-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
32 lines (24 loc) · 736 Bytes
/
Copy pathchatbot.py
File metadata and controls
32 lines (24 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("GROQ_API_KEY")
if not API_KEY:
print("Error: GROQ_API_KEY not found in .env file")
exit(1)
client = Groq(api_key=API_KEY)
messages = []
while True:
user_input = input("\nYou: ").strip()
if not user_input:
continue
if user_input.lower() in ["exit", "quit"]:
break
messages.append({"role": "user", "content": user_input})
chat_completion = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=messages
)
reply = chat_completion.choices[0].message.content
print(f"Bot: {reply}")
messages.append({"role": "assistant", "content": reply})