> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixroute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> LangChainフレームワーク連携ガイド

## はじめに

LangChainは、言語モデルアプリケーションを開発するための強力なフレームワークです。[**MixRoute**](https://api.mixroute.ai/)\*\* API\*\*を使用すると、LangChainでさまざまなAIモデルを柔軟に利用できます。

## クイックスタート

### 1. 依存関係のインストール

```bash theme={null}
pip install langchain langchain-openai
```

### 2. 基本設定

```python theme={null}
import os
from langchain_openai import ChatOpenAI

os.environ["OPENAI_API_KEY"] = "YOUR_MIXROUTE_API_KEY"
os.environ["OPENAI_BASE_URL"] = "https://api.mixroute.ai/v1"

llm = ChatOpenAI(
    model="gpt-5.5",
    temperature=0.7
)
```

## 主な機能

### 基本的なチャット

```python theme={null}
from langchain.schema import HumanMessage, SystemMessage

messages = [
    SystemMessage(content="You are a helpful assistant"),
    HumanMessage(content="Explain Python's main features")
]

response = llm.invoke(messages)
print(response.content)
```

### 会話チェーン（メモリ付き）

```python theme={null}
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain

memory = ConversationBufferMemory()
conversation = ConversationChain(llm=llm, memory=memory)

conversation.predict(input="I want to learn machine learning")
conversation.predict(input="Recommend some resources")
```

### ストリーミング出力

```python theme={null}
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

streaming_llm = ChatOpenAI(
    model="gpt-5.5",
    streaming=True,
    callbacks=[StreamingStdOutCallbackHandler()]
)

streaming_llm.invoke("Write a poem about spring")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.