Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
colorFrom: "blue"
|
| 5 |
-
colorTo: "green"
|
| 6 |
-
sdk: "chainlit"
|
| 7 |
-
sdk_version: "0.7.600" # Optional: You can omit or update this version
|
| 8 |
-
app_file: "app.py"
|
| 9 |
-
pinned: false
|
| 10 |
-
---
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 1 |
+
import chainlit as cl
|
| 2 |
+
import os
|
| 3 |
+
from groq import Groq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
groq_client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 6 |
|
| 7 |
+
@cl.on_chat_start
|
| 8 |
+
async def start_chat():
|
| 9 |
+
await cl.Message(content="👋 Hello! I am your Groq-powered chatbot.").send()
|
| 10 |
|
| 11 |
+
@cl.on_message
|
| 12 |
+
async def handle_message(message: cl.Message):
|
| 13 |
+
response = groq_client.chat.completions.create(
|
| 14 |
+
model="llama3-8b-8192",
|
| 15 |
+
messages=[
|
| 16 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 17 |
+
{"role": "user", "content": message.content}
|
| 18 |
+
]
|
| 19 |
+
)
|
| 20 |
+
reply = response.choices[0].message.content
|
| 21 |
+
await cl.Message(content=reply).send()
|