Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
使用 LangChain 的 ChatOpenAI 接入 PipeLLM 的 OpenAI 兼容路由
pip install langchain-openai
import os from langchain_openai import ChatOpenAI llm = ChatOpenAI( model='gpt-4.1', api_key=os.getenv('PIPELLM_API_KEY'), base_url='https://api.pipellm.ai/v1' ) response = llm.invoke([ ('user', 'Why is the sky blue?') ]) print(response.content)
import { ChatOpenAI } from '@langchain/openai'; const llm = new ChatOpenAI({ model: 'gpt-4.1', apiKey: process.env.PIPELLM_API_KEY, configuration: { baseURL: 'https://api.pipellm.ai/v1' } }); const response = await llm.invoke([ { role: 'user', content: 'Why is the sky blue?' } ]); console.log(response.content);
import os from langchain_openai import ChatOpenAI llm = ChatOpenAI( model='gpt-4.1', api_key=os.getenv('PIPELLM_API_KEY'), base_url='https://api.pipellm.ai/v1', streaming=True ) for chunk in llm.stream('Tell me a story'): print(chunk.content, end='', flush=True)
import os from langchain_openai import ChatOpenAI from langchain_core.tools import tool @tool def get_weather(location: str) -> str: """获取指定地点的天气""" return f"{location} 的天气:22°C,晴天" llm = ChatOpenAI( model='gpt-4.1', api_key=os.getenv('PIPELLM_API_KEY'), base_url='https://api.pipellm.ai/v1' ) llm_with_tools = llm.bind_tools([get_weather]) response = llm_with_tools.invoke("东京现在天气怎么样?") print(response.tool_calls)
POST /v1/chat/completions
此页面对您有帮助吗?