File size: 1,409 Bytes
5c271a3
583f6dd
 
 
ef9fa4b
5c271a3
583f6dd
 
5c271a3
 
583f6dd
8ce97f0
 
5c271a3
8ce97f0
5c271a3
 
 
 
 
8ce97f0
5c271a3
 
 
 
 
 
 
3002e1b
5c271a3
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
import logging
from fastapi import APIRouter
from api.stored_data import stored_data
from src.genai.human_refined_ideation.agent import human_refined_idea
from api.schemas.human_idea_refining import RefineIdeationRequest

router= APIRouter()
human_refine_graph = human_refined_idea()
app_logger = logging.getLogger("app_logger")
error_logger = logging.getLogger("error_logger")

@router.get("/human-idea-refining")
def human_idea_refine_endpoint(query:str):
    try:
        stored_data['human_ideation_interactions'].append({"role": "user", "content": query})
        response = human_refine_graph.invoke(
            {
            'query': stored_data['human_ideation_interactions'],
            'business_details': stored_data["business_details"],
            'final_ideation': stored_data.get('final_ideation',["","","",""]),
            },config={"configurable": {"thread_id": "human-idea-refine-thread"}}
        )
        stored_data['human_ideation_interactions'].append({"role": "assistant", "content": response['result']})
        stored_data['refined_ideation'] = stored_data['human_ideation_interactions'][-1]['content']
        app_logger.info('Executed human ideation refining.')
        return {'response' : stored_data['human_ideation_interactions'][-1]['content'] }
    
    except Exception as e:
        error_logger.error(f'Unable to execute human idea refining agent: {e}')
        raise