Turbiling commited on
Commit
5752ed1
·
verified ·
1 Parent(s): 444f8e6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import chainlit as cl
4
+ import os
5
+ from groq import Groq
6
+
7
+ # Initialize Groq client using Hugging Face secret
8
+ groq_client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
9
+
10
+ @cl.on_chat_start
11
+ async def start_chat():
12
+ await cl.Message(content="👋 Hello! I am your Chainlit + Groq AI Assistant. Ask me anything!").send()
13
+
14
+ @cl.on_message
15
+ async def handle_message(message: cl.Message):
16
+ # Call Groq API using LLaMA3 model
17
+ response = groq_client.chat.completions.create(
18
+ model="llama3-8b-8192",
19
+ messages=[
20
+ {"role": "system", "content": "You are a helpful assistant."},
21
+ {"role": "user", "content": message.content}
22
+ ]
23
+ )
24
+ reply = response.choices[0].message.content
25
+ await cl.Message(content=reply).send()