跳到主要內容
Open In ColabOpen on GitHub

ChatPipeshift

這將幫助您開始使用 Pipeshift 聊天模型。如需所有 ChatPipeshift 功能和配置的詳細文件,請前往 API 參考

概觀

整合詳細資訊

類別套件本地可序列化JS 支援套件下載套件最新版本
ChatPipeshiftlangchain-pipeshift-PyPI - DownloadsPyPI - Version

模型功能

工具呼叫結構化輸出JSON 模式圖像輸入音訊輸入視訊輸入Token 層級串流原生非同步Token 使用量Logprobs
-

設定

若要存取 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.

實例化

現在我們可以實例化我們的模型物件並產生聊天完成

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.

串鏈

我們可以像這樣使用提示範本串鏈我們的模型

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


此頁面是否對您有幫助?