Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import osimport gradio as grfrom groq import Groq# 安裝 groq 套件os.system('pip install groq')# 從環境變數中獲取API Keygroq_key = os.getenv('groq_key')# 設定API Keyclient = Groq(api_key=groq_key)def chat_with_groq(message):completion = client.chat.completions.create(model="llama-3.1-70b-versatile",messages=[{"role": "system","content": "You have a humorous temperament, always discuss serious matters with a sense of humor. \nYou should always use Traditional Chinese (zh-tw)."},{"role": "user","content": message}],temperature=1,max_tokens=1024,top_p=1,stream=False,stop=None,)response = ""for chunk in completion:response += chunk.choices[0].delta.content or ""return responsewith gr.Blocks() as demo:chatbot = gr.Chatbot()message = gr.Textbox(placeholder="Type your message here...")def respond(message, chat_history):bot_response = chat_with_groq(message)chat_history.append((message, bot_response))return "", chat_historymessage.submit(respond, [message, chatbot], [message, chatbot])demo.launch()
app.py+49