Spaces:
Sleeping
Sleeping
| from groq import Groq | |
| from scripts.llm.runner import run_groq | |
| from scripts.llm.services import save_history , load_history | |
| async def run_llm( | |
| product_details : dict , | |
| product_id : int , | |
| user_id : int , | |
| query : str , | |
| system_prompt : str , | |
| groq_client : Groq , | |
| redis_client = '' | |
| ) -> str : | |
| system_prompt += str(product_details) | |
| session_id : str= str(product_id) + str(user_id) | |
| history : list = await load_history(redis_client , session_id) | |
| if history == [] : history = [ | |
| { | |
| 'role' : 'system' , | |
| 'content' : system_prompt | |
| } | |
| ] | |
| history.append({ | |
| 'role' : 'user' , | |
| 'content' : query | |
| }) | |
| response : str = await run_groq(history , groq_client) | |
| history.append({ | |
| 'role' : 'assistant' , | |
| 'content' : response | |
| }) | |
| await save_history(redis_client , history , session_id) | |
| return response |