File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import groq
2+ import os
3+ from dotenv import load_dotenv
4+
5+ load_dotenv (dotenv_path = ".env" )
6+ GROQ_API_KEY = os .getenv ("api_key" )
7+
8+ groq_client = groq .Client (api_key = GROQ_API_KEY )
9+
10+ def chat (query : str ):
11+ """
12+ API endpoint to handle user investment-related questions and return AI-generated insights.
13+ """
14+ if not query :
15+ return {"error" : "Query parameter is required" }
16+
17+ try :
18+ response = groq_client .chat .completions .create (
19+ model = "llama-3.3-70b-versatile" ,
20+ messages = [{"role" : "system" , "content" : "You are an AI investment assistant." },
21+ {"role" : "user" , "content" : query }]
22+ )
23+
24+ answer = response .choices [0 ].message .content
25+ return {"question" : query , "answer" : answer }
26+
27+ except Exception as e :
28+ return {"error" : str (e )}
You can’t perform that action at this time.
0 commit comments