-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatBot.py
More file actions
44 lines (28 loc) · 1.06 KB
/
ChatBot.py
File metadata and controls
44 lines (28 loc) · 1.06 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
import requests
import json
API_URL= "https://api.groq.com/openai/v1/chat/completions"
API_KEY="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"
reminder=[{"role":"system", "content":"You are a helpful math and coding assistant."}]
print("Type 'quit' to exit the ChatBot")
while True:
user_input=input("You: ")
if user_input.lower()=="quit":
break
reminder.append({"role":"user", "content":user_input})
headers={"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
}
payload = {
"model": "llama-3.3-70b-versatile",
"messages": reminder,
"temperature": 0.7
}
try:
response= requests.post(API_URL, headers=headers, json=payload)
response.raise_for_status()
response_data=response.json()
bot_reply=response_data['choices'][0]['message']['content']
print(f"AI: {bot_reply}")
reminder.append({"role": "assistant", "content": bot_reply})
except requests.exceptions.RequestException as e:
print(f"Error: {e}")