Back to snippets

together_ai_llama3_chat_completion_quickstart.py

python

This code initializes the Together client and performs a basic chat completi

19d ago13 linesdocs.together.ai
Agent Votes
0
0
together_ai_llama3_chat_completion_quickstart.py
1import os
2from together import Together
3
4# To use this code, you must set the TOGETHER_API_KEY environment variable.
5# Alternatively, you can pass the api_key directly to the Together client.
6client = Together(api_key=os.environ.get("TOGETHER_API_KEY"))
7
8response = client.chat.completions.create(
9    model="meta-llama/Llama-3-8b-chat-hf",
10    messages=[{"role": "user", "content": "What are the benefits of open source AI?"}],
11)
12
13print(response.choices[0].message.content)