本页面将帮助您开始使用 Crusoe AI 聊天模型。有关所有 ChatCrusoe 功能和配置的详细文档,请参阅 Crusoe 托管推理文档.
Crusoe AI 为以下模型提供高性能托管推理服务 领先的开源模型 通过 Crusoe Intelligence Foundry 提供,由专有的 MemoryAlloy™ 技术驱动,实现超低延迟和高吞吐量。
概览
集成详情
| 类 | 包 | 可序列化 | JS 支持 | 下载量 | 版本 |
|---|---|---|---|---|---|
| ChatCrusoe | langchain-crusoe | beta | ❌ | !PyPI - 下载量 | !PyPI - 版本 |
模型特性
| 工具调用 | 结构化输出 | 图像输入 | 音频输入 | 视频输入 | 令牌级流式处理 | 原生异步 | 令牌使用量 | 对数概率 |
|---|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |
设置
要访问 Crusoe 模型,您需要创建一个 Crusoe Cloud 账户,获取推理 API 密钥,并安装 langchain-crusoe 集成包。
凭证
前往 Crusoe Cloud 控制台 进行注册。然后导航到 **安全** 标签页并选择 **推理 API 密钥** 来生成您的密钥。完成此操作后,设置 CRUSOE_API_KEY 环境变量:
if "CRUSOE_API_KEY" not in os.environ:
os.environ["CRUSOE_API_KEY"] = getpass.getpass("Enter your Crusoe API key: ")
要启用模型调用的自动追踪,请设置您的 LangSmith API 密钥:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"
安装
LangChain Crusoe 集成包含在 langchain-crusoe package:
pip install -qU langchain-crusoe
uv add langchain-crusoe
实例化
现在我们可以实例化模型对象并生成聊天补全:
from langchain_crusoe import ChatCrusoe
llm = ChatCrusoe(
model="meta-llama/Llama-3.3-70B-Instruct",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
# api_key="...", # if not set via CRUSOE_API_KEY env var
# other params...
)
可用模型
Crusoe 通过 Intelligence Foundry 提供领先的开源模型服务。参见 完整模型列表 了解最新可用性。
| 模型 | 提供商 | 上下文长度 |
|---|---|---|
meta-llama/Llama-3.3-70B-Instruct | Meta | 128k |
openai/gpt-oss-120b | OpenAI | 128k |
deepseek-ai/DeepSeek-V3-0324 | DeepSeek | 160k |
deepseek-ai/DeepSeek-R1-0528 | DeepSeek | 160k |
deepseek-ai/DeepSeek-V3.1 | DeepSeek | 160k |
Qwen/Qwen3-235B-A22B | Qwen | 131k |
google/gemma-3-12b-it | 128k | |
moonshotai/Kimi-K2-Thinking | Moonshot AI | 131k |
调用
messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
AIMessage(content="J'adore la programmation.", response_metadata={'token_usage': {'completion_tokens': 9, 'prompt_tokens': 35, 'total_tokens': 44}, 'model_name': 'meta-llama/Llama-3.3-70B-Instruct', 'system_fingerprint': None, 'finish_reason': 'stop', 'logprobs': None}, id='run-...', usage_metadata={'input_tokens': 35, 'output_tokens': 9, 'total_tokens': 44})
print(ai_msg.content)
J'adore la programmation.
链式调用
我们可以 链式调用 将模型与提示模板链接,如下所示:
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
),
("human", "{input}"),
]
)
chain = prompt | llm
chain.invoke(
{
"input_language": "English",
"output_language": "German",
"input": "I love programming.",
}
)
AIMessage(content='Ich liebe Programmieren.', response_metadata={...}, id='run-...')
流式输出
stream = llm.stream_events(messages, version="v3")
for token in stream.text:
print(token, end="", flush=True)
工具调用
from pydantic import BaseModel, Field
class GetWeather(BaseModel):
"""Get the current weather in a given location."""
location: str = Field(description="City and state, e.g. San Francisco, CA")
llm_with_tools = llm.bind_tools([GetWeather])
ai_msg = llm_with_tools.invoke("What's the weather like in San Francisco?")
print(ai_msg.tool_calls)
结构化输出
from pydantic import BaseModel, Field
from typing import Optional
class Joke(BaseModel):
"""Joke to tell user."""
setup: str = Field(description="The setup of the joke")
punchline: str = Field(description="The punchline to the joke")
rating: Optional[int] = Field(description="How funny the joke is, from 1 to 10")
structured_llm = llm.with_structured_output(Joke)
structured_llm.invoke("Tell me a joke about cats")
Joke(setup='Why was the cat sitting on the computer?', punchline='To keep an eye on the mouse!', rating=7)
API参考
有关ChatCrusoe所有功能和配置的详细文档,请访问 Crusoe托管推理文档.