File tree Expand file tree Collapse file tree 2 files changed +7
-16
lines changed
Expand file tree Collapse file tree 2 files changed +7
-16
lines changed Original file line number Diff line number Diff line change 1717
1818# Custom imports
1919from topStocks import get_top_stocks
20+ from ask import groq_chat
2021from agents import multi_ai
2122from agno .agent import RunResponse
2223
@@ -53,7 +54,8 @@ async def lifespan(_: FastAPI):
5354 print (f"❌ Error while closing Redis: { e } " )
5455
5556
56- app = FastAPI ()
57+ app = FastAPI (lifespan = lifespan ) # Pass the lifespan context manager to FastAPI
58+
5759app .add_middleware (
5860 CORSMiddleware ,
5961 allow_origins = ["*" ],
@@ -115,18 +117,10 @@ def chat(query: str):
115117 """
116118 API endpoint to handle user investment-related questions and return AI-generated insights.
117119 """
118- if not query :
119- return {"error" : "Query parameter is required" }
120120
121121 try :
122- response = groq_client .chat .completions .create (
123- model = "llama-3.3-70b-versatile" ,
124- messages = [{"role" : "system" , "content" : "You are an AI investment assistant." },
125- {"role" : "user" , "content" : query }]
126- )
127-
128- answer = response .choices [0 ].message .content
129- return {"question" : query , "answer" : answer }
122+ answer = groq_chat (query )
123+ return answer
130124
131125 except Exception as e :
132126 return {"error" : str (e )}
Original file line number Diff line number Diff line change 77GROQ_API_KEY = os .getenv ("GROQ_API_KEY" )
88groq_client = groq .Client (api_key = GROQ_API_KEY )
99
10- def chat (query : str ):
11- """
12- API endpoint to handle user investment-related questions and return AI-generated insights.
13- """
10+ def groq_chat (query : str ):
1411 if not query :
1512 return {"error" : "Query parameter is required" }
1613
1714 try :
1815 response = groq_client .chat .completions .create (
1916 model = "llama-3.3-70b-versatile" ,
20- messages = [{"role" : "system" , "content" : "You are an AI investment assistant." },
17+ messages = [{"role" : "system" , "content" : "You are an AI investment assistant. You are here to help users with investment-related questions. " },
2118 {"role" : "user" , "content" : query }]
2219 )
2320
You can’t perform that action at this time.
0 commit comments