File size: 1,680 Bytes
5c271a3
ef9fa4b
583f6dd
38cf703
8ce97f0
5c271a3
bb8e492
583f6dd
5c271a3
 
583f6dd
 
38cf703
8ce97f0
5c271a3
3002e1b
583f6dd
5c271a3
a6a0614
8ce97f0
 
 
 
 
 
 
 
5c271a3
 
8ce97f0
 
 
5c271a3
3002e1b
5c271a3
583f6dd
8039e4b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from fastapi import APIRouter
from api.stored_data import stored_data
from src.genai.orchestration_agent.agent import OrchestrationAgent
# from src.genai.orchestration_agent.utils.utils import handle_tools
from api.schemas.orchestration import OrchestrationRequest
from src.genai.orchestration_agent.utils.utils import handle_tools

app_logger = logging.getLogger("app_logger")
error_logger = logging.getLogger("error_logger")

router= APIRouter()
agent = OrchestrationAgent()
graph = agent.orchestration_graph()

@router.post("/orchestration", description="Gives the analytics of influencers.")
def orchestration_endpoint(request:OrchestrationRequest):
    try:
        config={"configurable": {"thread_id": "orchestration-thread"},"run_name":"orchestration"}
        result = graph.invoke({'messages':[request.message],
                               'image_base64': request.image_base64}, config=config)
        print('Result tools:', result['tools'])
        tools=handle_tools(result['tools'], stored_data)
        print('Tools:',tools)
        if result['image_caption'] is not None: stored_data['image_caption']=result['image_caption']
        # if result['video_idea'] !='' or result.video_idea != 'null': stored_data['refined_ideation']= result['video_idea']
        # if result['video_story']!='' or result.video_story!='null': stored_data['final_story']= result['video_story']
        app_logger.info('Orchestrator executed')
            
        return {'tool_response':tools,
                'message_response': result['query_response'],}

    except Exception as e:
        error_logger.error(f'Unable to run orchestration: {e}')
        raise