安装
环境
要使用 Together AI,您需要找到 API 密钥(位置:api.together.ai/settings/api-keys)。该密钥可通过初始化参数together_api_key 或设置环境变量 TOGETHER_API_KEY 传入。
示例
官方原文:src/oss/python/integrations/providers/together.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
使用 LangChain Python 集成 Together AI。
pip install -U langchain-together
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
stream = chat.stream_events("Tell me fun things to do in NYC", version="v3")
for token in stream.text:
print(token, 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")
# 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(): "))
官方原文:src/oss/python/integrations/providers/together.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。