Spaces:
Sleeping

Turbiling commited on
Commit
4492680
·
verified ·
1 Parent(s): 87e1f93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -1,26 +1,21 @@
1
- ---
2
- title: "Chainlit Groq Chatbot"
3
- emoji: "🤖"
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
- # 🤖 Chainlit Chatbot with Groq API
13
 
14
- This is a simple AI chatbot powered by Chainlit and the Groq API (LLaMA 3). Deployed on Hugging Face Spaces.
 
 
15
 
16
- ## How to Use
17
-
18
- Just open the Space and start chatting! 🎉
19
-
20
- ## Setup Instructions (for contributors)
21
-
22
- 1. Create a secret key named `GROQ_API_KEY` in the Hugging Face Space settings.
23
- 2. Upload the following files:
24
- - `app.py`
25
- - `requirements.txt`
26
- - `README.md`
 
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()