Metadata-Version: 2.5
Name: langchain-morse
Version: 0.1.0
Summary: An integration package connecting Morse and LangChain
Project-URL: Homepage, https://trymorse.ai/inference
Project-URL: Documentation, https://trymorse.ai/inference/docs/langchain
Project-URL: Models, https://trymorse.ai/inference/models
Project-URL: Repository, https://github.com/trymorse/langchain-morse
Author: Morse
License-Expression: MIT
License-File: LICENSE
Keywords: chat,langchain,llm,morse,openai-compatible,private-inference
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: <4.0,>=3.10
Requires-Dist: langchain-core<2.0.0,>=1.0.0
Requires-Dist: langchain-openai<2.0.0,>=1.0.0
Description-Content-Type: text/markdown

# langchain-morse

This package connects [Morse](https://trymorse.ai/inference) and LangChain.

Morse is a private, OpenAI-compatible inference API for open-weight models (DeepSeek, GLM, Qwen, Kimi, Gemma, Llama, MiniMax, Mistral and others). Morse keeps no prompt and no response, and providers see Morse as the customer, not you. Some models also run in a trusted execution environment (TEE).

## Installation

```bash
pip install -U langchain-morse
```

Get an API key at [console.trymorse.ai](https://console.trymorse.ai) and set it:

```bash
export MORSE_API_KEY="your-api-key"
```

## Chat models

`ChatMorse` is a LangChain chat model for every chat model on Morse. Model ids are listed at [trymorse.ai/inference/models](https://trymorse.ai/inference/models), or as JSON at `https://inference.trymorse.ai/v1/models` (no key needed).

```python
from langchain_morse import ChatMorse

llm = ChatMorse(model="deepseek/deepseek-v4.1-flash")
llm.invoke("Sing a ballad of LangChain.")
```

### Streaming

```python
for chunk in llm.stream("Write one line about rain."):
    print(chunk.text, end="")
```

### Tool calling and structured output

```python
from langchain_core.tools import tool


@tool
def get_weather(city: str) -> str:
    """The weather now in a city."""
    return f"It's raining in {city}."


reply = llm.bind_tools([get_weather]).invoke("Is it raining in Lisbon?")
print(reply.tool_calls)
```

`with_structured_output` works the same way as with `ChatOpenAI`. On a model without JSON schema output, pass `method="function_calling"`.

### Reasoning

Reasoning models return their thinking in `additional_kwargs["reasoning_content"]`:

```python
llm = ChatMorse(model="z-ai/glm-5.3", reasoning_effort="high")
response = llm.invoke("What is 3^3?")
print(response.additional_kwargs.get("reasoning_content"))
```

### Morse request options

Send Morse's own parameters in `extra_body`, for example to keep a request on TEE hardware:

```python
llm = ChatMorse(
    model="z-ai/glm-5.3",
    extra_body={"provider": {"min_privacy": "tee"}},
)
```

### Agents

```python
from langchain.agents import create_agent

agent = create_agent(llm, tools=[get_weather])
```

## Configuration

| Argument | Environment variable | Default |
| --- | --- | --- |
| `api_key` | `MORSE_API_KEY` | required |
| `base_url` | `MORSE_API_BASE` | `https://inference.trymorse.ai/v1` |
| `model` | | `deepseek/deepseek-v4.1-flash` |

`OPENAI_API_KEY` is never read, so an OpenAI key is never sent to Morse.

## Docs

- [LangChain guide](https://trymorse.ai/inference/docs/langchain)
- [Morse inference docs](https://trymorse.ai/inference/docs)

## Development

```bash
uv sync --group test
uv run pytest --disable-socket --allow-unix-socket tests/unit_tests
MORSE_API_KEY=... uv run pytest tests/integration_tests
```
