from groq import Groq
 
client = Groq(api_key = 'Groq API Key')

completion = client.chat.completions.create(
    model = "llama-3.1-8b-instant",
    messages =[
      {
        "role": "user",
        "content": "請使用繁體中文和台灣用語來說明 Python 是如何使用 Groq API?"
      }
    ],
    temperature = 1,
    max_completion_tokens = 1024,
    top_p = 1,
    stream = True,
    stop = None
)

for chunk in completion:
    print(chunk.choices[0].delta.content or "", end = "")