@@ -323,26 +323,66 @@ async def _generate_llm_response(self, query: str, data: Dict[str, Any]) -> str:
323323 print (f"🤖 LLM Prompt length: { len (prompt )} characters" )
324324 print (f"🤖 LLM Prompt preview: { prompt [:200 ]} ..." )
325325
326- # Call the LLM
326+ # Get LLM configuration from environment
327+ llm_provider = os .getenv ("LLM_PROVIDER" , "ollama" )
328+ llm_api_key = os .getenv ("LLM_API_KEY" , "" )
329+ llm_model = os .getenv ("LLM_MODEL" , "llama3.2:latest" )
330+
331+ # Call the LLM based on provider
327332 async with httpx .AsyncClient () as client :
328- response = await client .post (
329- LLM_URL ,
330- json = {
331- "model" : "llama3.2:latest" , # Use the model you have installed
333+ if llm_provider == "digitalocean" :
334+ # DigitalOcean AI Agent format
335+ headers = {
336+ "Content-Type" : "application/json" ,
337+ "Authorization" : f"Bearer { llm_api_key } "
338+ }
339+ payload = {
340+ "messages" : [
341+ {
342+ "role" : "user" ,
343+ "content" : prompt
344+ }
345+ ],
346+ "stream" : False ,
347+ "include_functions_info" : False ,
348+ "include_retrieval_info" : False ,
349+ "include_guardrails_info" : False
350+ }
351+ else :
352+ # Ollama format (default)
353+ headers = {"Content-Type" : "application/json" }
354+ payload = {
355+ "model" : llm_model ,
332356 "prompt" : prompt ,
333357 "stream" : False ,
334358 "options" : {
335359 "temperature" : 0.7 ,
336360 "top_p" : 0.9 ,
337- "max_tokens" : 1000 # Increased from 500
361+ "max_tokens" : 1000
338362 }
339- },
363+ }
364+
365+ response = await client .post (
366+ LLM_URL ,
367+ json = payload ,
368+ headers = headers ,
340369 timeout = 30
341370 )
342371
343372 if response .status_code == 200 :
344373 result = response .json ()
345- llm_response = result .get ("response" , "" ).strip ()
374+
375+ # Parse response based on provider
376+ if llm_provider == "digitalocean" :
377+ # DigitalOcean format: response is in choices[0].message.content
378+ if "choices" in result and len (result ["choices" ]) > 0 :
379+ llm_response = result ["choices" ][0 ]["message" ]["content" ].strip ()
380+ else :
381+ llm_response = result .get ("response" , "" ).strip ()
382+ else :
383+ # Ollama format
384+ llm_response = result .get ("response" , "" ).strip ()
385+
346386 print (f"🤖 LLM Response length: { len (llm_response )} characters" )
347387 print (f"🤖 LLM Response preview: { llm_response [:200 ]} ..." )
348388
0 commit comments