anamjafar6 commited on
Commit
8018329
·
verified ·
1 Parent(s): 1c87d00

Create groq_handler.py

Browse files
Files changed (1) hide show
  1. groq_handler.py +18 -0
groq_handler.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # groq_handler.py
2
+ import os
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env
7
+ load_dotenv()
8
+
9
+ # Initialize Groq client
10
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
11
+
12
+ # Function to call Groq's chatbot
13
+ def ask_groq(prompt, model="llama3-70b-8192"):
14
+ chat_completion = client.chat.completions.create(
15
+ messages=[{"role": "user", "content": prompt}],
16
+ model=model,
17
+ )
18
+ return chat_completion.choices[0].message.content