Spaces:
Sleeping
Sleeping
| import ast | |
| import logging | |
| from fastapi import APIRouter | |
| from api.stored_data import stored_data | |
| from src.genai.ideation_agent.agent import IdeationAgent | |
| from langgraph.errors import GraphRecursionError | |
| app_logger = logging.getLogger("app_logger") | |
| error_logger = logging.getLogger("error_logger") | |
| router = APIRouter() | |
| agent = IdeationAgent() | |
| idea_graph = agent.ideation_graph() | |
| def ideation_endpoint(): | |
| config={"recursion_limit":25, "configurable": {"thread_id": "ideation_thread123"}} | |
| try: | |
| result = idea_graph.invoke( | |
| { | |
| 'business_details': [stored_data['business_details']], | |
| 'image_caption': [stored_data['image_caption'] if 'image_caption' in stored_data else ""] | |
| }, | |
| config=config) | |
| stored_data['final_ideation'] = result['top_4_ideas'][-1] | |
| # stored_data['final_ideation']=ast.literal_eval(stored_data['final_ideation']) | |
| app_logger.info('Executed the ideation pipeline.') | |
| return {'response':result['top_4_ideas'][-1]} | |
| except GraphRecursionError: | |
| error_logger.error('Ideation loop ran more than specified.') | |
| result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}}) | |
| return {'response': result[0]} | |
| except Exception as e: | |
| error_logger.error('Unable to execute the ideation', e) | |
| raise | |