聊天管道
这将帮助您开始使用 Pipeshift 聊天模型。有关所有 ChatPipeshift 功能和配置的详细文档,请前往 API 参考。
概述
集成详细信息
| 类 | 包 | 本地化 | 序列 化 | JS 支持 | 软件包下载 | 最新包装 |
|---|---|---|---|---|---|---|
| ChatPipeshift | langchain-pipeshift | ❌ | - | ❌ |
模型特点
| 工具调用 | 结构化输出 | JSON 模式 | 图像输入 | 音频输入 | 视频输入 | 令牌级流式处理 | 本机异步 | Token 使用情况 | 日志 |
|---|---|---|---|---|---|---|---|---|---|
| ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | - |
设置
要访问 Pipeshift 模型,您需要在 Pipeshift 上创建一个帐户,获取 API 密钥,并安装langchain-pipeshift集成包。
凭据
前往 Pipeshift 注册 Pipeshift 并生成 API 密钥。完成此作后,设置 PIPESHIFT_API_KEY 环境变量:
import getpass
import os
if not os.getenv("PIPESHIFT_API_KEY"):
os.environ["PIPESHIFT_API_KEY"] = getpass.getpass("Enter your Pipeshift API key: ")
如果您想自动跟踪模型调用,您还可以通过取消下面的注释来设置您的 LangSmith API 密钥:
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
安装
LangChain Pipeshift 集成位于langchain-pipeshift包:
%pip install -qU langchain-pipeshift
Note: you may need to restart the kernel to use updated packages.
实例
现在我们可以实例化我们的 Model 对象并生成聊天补全:
from langchain_pipeshift import ChatPipeshift
llm = ChatPipeshift(
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
temperature=0,
max_tokens=512,
# other params...
)
调用
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='Here is the translation:\n\nJe suis amoureux du programme. \n\nHowever, a more common translation would be:\n\nJ\'aime programmer.\n\nNote that "Je suis amoureux" typically implies romantic love, whereas "J\'aime" is a more casual way to express affection or enjoyment for an activity, in this case, programming.', additional_kwargs={}, response_metadata={}, id='run-5cad8e5c-d089-44a8-8dcd-22736cde7d7b-0')
print(ai_msg.content)
Here is the translation:
Je suis amoureux du programme.
However, a more common translation would be:
J'aime programmer.
Note that "Je suis amoureux" typically implies romantic love, whereas "J'aime" is a more casual way to express affection or enjoyment for an activity, in this case, programming.
链接
我们可以用 prompt 模板链接我们的模型,如下所示:
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate(
[
(
"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.",
}
)
API 参考:ChatPromptTemplate
AIMessage(content="Das ist schön! Du liebst Programmieren! (That's great! You love programming!)\n\nWould you like to know the German translation of a specific programming-related term or phrase, or would you like me to help you with something else?", additional_kwargs={}, response_metadata={}, id='run-8a4b7d56-23d9-43a7-8fb2-e05f556d94bd-0')
API 参考
有关所有 ChatPipeshift 功能和配置的详细文档,请访问 API 参考:https://dashboard.pipeshift.com/docs