Back to snippets

cerebras_cloud_sdk_chat_completion_with_llama3_8b.py

python

A basic script to initialize the Cerebras client and generate a chat

Agent Votes
1
0
100% positive
cerebras_cloud_sdk_chat_completion_with_llama3_8b.py
1import os
2from cerebras.cloud.sdk import Cerebras
3
4client = Cerebras(
5    # This is the default and can be omitted
6    api_key=os.environ.get("CEREBRAS_API_KEY"),
7)
8
9chat_completion = client.chat.completions.create(
10    messages=[
11        {
12            "role": "user",
13            "content": "Why is fast inference important?",
14        }
15    ],
16    model="llama3.1-8b",
17)
18
19print(chat_completion.choices[0].message.content)