-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroq-simple-Chatbot
44 lines (32 loc) · 1.19 KB
/
Groq-simple-Chatbot
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
from groq import Groq
# Initialize the Groq API
client= Groq(api_key="<key-here>")
# Initialize the conversation list
conversation = [
{"role": "system", "content": "You are a helpful assistant."},
]
# Function to interact with GPT-3
def chat_with_groq(prompt, conversation):
model_engine = "mixtral-8x7b-32768"
# Add the new user message to the conversation list
conversation.append({"role": "user", "content": prompt})
# Generate a message from the model
response = client.chat.completions.create(
model=model_engine,
messages=conversation
)
message_output = response.choices[0].message.content
# Add the model's message to the conversation list
conversation.append({"role": "assistant", "content": message_output})
return message_output
# Main chat loop
if __name__ == "__main__":
print("Chatbot initialized. Type 'quit' to exit.")
while True:
user_input = input("You: ")
if user_input.lower() == 'quit':
print("Chatbot: Goodbye!")
break
else:
bot_response = chat_with_groq(user_input, conversation)
print(f"Chatbot: {bot_response}")