Abhlash commited on
Commit
eecee13
1 Parent(s): c5329f9

updated chat

Browse files
Files changed (1) hide show
  1. bot/chat.py +26 -0
bot/chat.py CHANGED
@@ -15,6 +15,32 @@ logger = logging.getLogger(__name__)
15
 
16
  client = AsyncGroq(api_key=GROQ_API_KEY)
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  async def chat_with_groq(message, history):
19
  formatted_messages = [
20
  {
 
15
 
16
  client = AsyncGroq(api_key=GROQ_API_KEY)
17
 
18
+ async def chat_interface(message, history):
19
+ try:
20
+ # Prepare the conversation history
21
+ conversation = []
22
+ for h in history:
23
+ conversation.append({"role": "user", "content": h[0]})
24
+ conversation.append({"role": "assistant", "content": h[1]})
25
+ conversation.append({"role": "user", "content": message})
26
+
27
+ # Call the Groq API
28
+ chat_completion = await client.chat.completions.create(
29
+ messages=conversation,
30
+ model="mixtral-8x7b-32768",
31
+ temperature=0.7,
32
+ max_tokens=1000,
33
+ )
34
+
35
+ # Extract the response
36
+ response = chat_completion.choices[0].message.content
37
+
38
+ return response
39
+ except Exception as e:
40
+ logger.error(f"Error in chat_interface: {str(e)}")
41
+ return "Oops! Something went wrong. Please try again later."
42
+
43
+
44
  async def chat_with_groq(message, history):
45
  formatted_messages = [
46
  {