跳到主要內容

Together AI

注意

您目前所在的頁面記錄了將 Together AI 模型用作文字完成模型的使用方式。許多熱門的 Together AI 模型都是聊天完成模型

您可能正在尋找這個頁面

Together AI 提供 API,只需幾行程式碼即可查詢 50 多個領先的開放原始碼模型

此範例說明如何使用 LangChain 與 Together AI 模型互動。

安裝

%pip install --upgrade langchain-together

環境

若要使用 Together AI,您需要一個 API 金鑰,您可以在這裡找到:https://api.together.ai/settings/api-keys。這可以作為 init 參數 together_api_key 傳入,或設定為環境變數 TOGETHER_API_KEY

範例

# Querying chat models with Together AI

from langchain_together import ChatTogether

# choose from our 50+ models here: https://docs.together.ai/docs/inference-models
chat = ChatTogether(
# together_api_key="YOUR_API_KEY",
model="meta-llama/Llama-3-70b-chat-hf",
)

# stream the response back from the model
for m in chat.stream("Tell me fun things to do in NYC"):
print(m.content, end="", flush=True)

# if you don't want to do streaming, you can use the invoke method
# chat.invoke("Tell me fun things to do in NYC")
API 參考:ChatTogether
# Querying code and language models with Together AI

from langchain_together import Together

llm = Together(
model="codellama/CodeLlama-70b-Python-hf",
# together_api_key="..."
)

print(llm.invoke("def bubble_sort(): "))
API 參考:Together

此頁面是否對您有幫助?