Metadata-Version: 2.4
Name: trim-sdk
Version: 0.2.2
Summary: Trim SDK.
Author: Elad Ben-Zaken
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: openai==1.93.0
Requires-Dist: python-dotenv==1.1.1
Requires-Dist: langchain-core==0.3.67
Requires-Dist: langchain-openai==0.3.27
Requires-Dist: requests>=2.31.0
Requires-Dist: pydantic>=2.0.0
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# 🧠 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:

```bash
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:

```env
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`:

```python
from dotenv import load_dotenv
load_dotenv()
```

### 🔗 LangChain ReAct Agent

```python
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`

```python
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

```python
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

```python
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
