Skip to main content

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-sdk

🚀 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 trim 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 trim 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 trim import TrimClient
from dotenv import load_dotenv

load_dotenv()

client = TrimClient()

# 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 trim 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trim_sdk-0.2.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trim_sdk-0.2.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file trim_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: trim_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for trim_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cb3c0938ee0d819d19e245b9112d9b6ebe4961491f70dbcbd7d8eccd54da5de6
MD5 70e148440d46ad306a00b0692378148f
BLAKE2b-256 d711ecf1b9372344dbe332c1ee1595cbf202b336c8d25353ca6addc9f33886ac

See more details on using hashes here.

File details

Details for the file trim_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: trim_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for trim_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ffb30fa4414eda82acf3b73ad81fdcee116c3abe16752f5b67694ed58059d3e
MD5 5df7d326f6e661d3451d8d847138295f
BLAKE2b-256 88864fe23c25ea5f2e4277d766ae0faf37f484a61475be454d1e06a19fad53b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page