Trim SDK.
Project description
🧠 Trim LangChain SDK
Trim LangChain is a lightweight, OpenAI-compatible SDK designed for smart routing and efficient interaction with LLMs. It integrates seamlessly with LangChain agents, chat models, and OpenAI-style APIs.
📦 Installation
Install the SDK via pip:
pip install trim-langchain
🚀 Quick Start
🔐 Environment Variables
To use the SDK, you need to set the following environment variables in a .env file or your system environment:
TRIM_API_KEY=your_trim_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
TRIM_API_KEY: Your API key for authenticating with the Trim backend.OPENAI_API_KEY: Your OpenAI API key used internally by Trim to route to OpenAI models.
Make sure to load these using Python's dotenv:
from dotenv import load_dotenv
load_dotenv()
🔗 LangChain ReAct Agent
from dotenv import load_dotenv
from langgraph.prebuilt import create_react_agent
from examples.utils import print_agent_response
from sdk.trim_chatmodel import TrimChatModel
load_dotenv()
def calculator(expression: str) -> str:
"""Evaluates a basic math expression."""
try:
return str(eval(expression))
except Exception as e:
return f"Error: {e}"
llm = TrimChatModel()
agent = create_react_agent(model=llm, tools=[calculator])
response = agent.invoke({"messages": "What is (12 * 3) + 5?"})
print_agent_response(response['messages'])
💬 LangChain ChatModel
from sdk.trim_chatmodel import TrimChatModel
from dotenv import load_dotenv
load_dotenv()
llm = TrimChatModel()
response = llm.invoke([
{"role": "user", "content": "Tell me about Elon Musk in 20 words"}
])
print(response.content)
🧩 OpenAI-Compatible API
from sdk.trim_client import TrimLLMClient
from dotenv import load_dotenv
load_dotenv()
client = TrimLLMClient()
# Way 1: Simple completion
completion = client.responses.create(
model="gpt-4.1",
input="Write a one-sentence bedtime story about a unicorn."
)
print(completion.output_text)
# Way 2: Chat completion
completion = client.chat.completions.create(
model="gpt-4.1",
messages=[{"role": "user", "content": "Write a one-sentence bedtime story about bears"}]
)
print(completion.choices[0].message.content)
🧠 LangChain LLM Wrapper
from sdk.trim_llm import TrimLLM
from dotenv import load_dotenv
load_dotenv()
llm = TrimLLM()
prompt = "Explain quantum computing in less than 20 words."
result = llm.invoke(prompt)
print(result)
📚 Documentation
Coming soon. For now, explore the examples/ directory for use cases and integration patterns.
🤝 Contributing
Contributions are welcome! Please open issues or submit pull requests.
🛡️ License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trim_sdk-0.1.0.tar.gz.
File metadata
- Download URL: trim_sdk-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56580151e9bdcc8a1bc6cf94c1e1fbd06b63668a62910da2aa41e95e32708f0b
|
|
| MD5 |
320488019a300f10a83c494c1b3a057d
|
|
| BLAKE2b-256 |
0b5aec111f3d9249d7f5b95d27abdc3bfc3d27c7c638b80258c79b7abf706824
|
File details
Details for the file trim_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trim_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93ac438838d678be50f7d388bee1e16790fa73898f0f747c3decf1ca15fc3a82
|
|
| MD5 |
306d04fc02cb7db57f4e5ca7f0758af7
|
|
| BLAKE2b-256 |
44a883f9eff9ef3c9c3860c667acb394b4807f0a6572497ba3f9046cc5366845
|