subashpoudel commited on
Commit
8039e4b
·
1 Parent(s): af36f40

Included streaming in the responses

Browse files
api/__pycache__/stored_data.cpython-312.pyc CHANGED
Binary files a/api/__pycache__/stored_data.cpython-312.pyc and b/api/__pycache__/stored_data.cpython-312.pyc differ
 
api/routers/__pycache__/brainstorm.cpython-312.pyc CHANGED
Binary files a/api/routers/__pycache__/brainstorm.cpython-312.pyc and b/api/routers/__pycache__/brainstorm.cpython-312.pyc differ
 
api/routers/__pycache__/context_analysis.cpython-312.pyc CHANGED
Binary files a/api/routers/__pycache__/context_analysis.cpython-312.pyc and b/api/routers/__pycache__/context_analysis.cpython-312.pyc differ
 
api/routers/__pycache__/generate_final_story.cpython-312.pyc CHANGED
Binary files a/api/routers/__pycache__/generate_final_story.cpython-312.pyc and b/api/routers/__pycache__/generate_final_story.cpython-312.pyc differ
 
api/routers/__pycache__/ideation.cpython-312.pyc CHANGED
Binary files a/api/routers/__pycache__/ideation.cpython-312.pyc and b/api/routers/__pycache__/ideation.cpython-312.pyc differ
 
api/routers/__pycache__/orchestration.cpython-312.pyc CHANGED
Binary files a/api/routers/__pycache__/orchestration.cpython-312.pyc and b/api/routers/__pycache__/orchestration.cpython-312.pyc differ
 
api/routers/brainstorm.py CHANGED
@@ -1,8 +1,12 @@
 
 
1
  from fastapi import APIRouter
 
2
  from api.stored_data import stored_data
3
  from pydantic import BaseModel
4
  from typing import Optional
5
  from src.genai.brainstroming_agent.agent import brainstroming_graph
 
6
 
7
  router=APIRouter()
8
  brainstrom_graph = brainstroming_graph()
@@ -13,28 +17,31 @@ class BrainstormRequest(BaseModel):
13
  image_base64_list: Optional[list] = []
14
  thread_id: Optional[str]="default-session"
15
 
 
16
  @router.post("/brainstorm")
17
- def brainstroming_endpoint(
18
- request: BrainstormRequest, # 🔥 Full JSON body here
19
- ):
20
  idea = (
21
- [stored_data['refined_ideation']]
22
- if stored_data.get('refined_ideation')
23
- else [str(stored_data['final_ideation'])]
24
- if stored_data.get('final_ideation')
25
- else ['''I don't have any idea right now. Create your own **very creative** and **out of the box** video idea and generate the story for now.'''])
26
-
27
- result = brainstrom_graph.invoke({
28
- 'idea': idea,
29
- 'images': request.image_base64_list,
30
- 'latest_preferred_topics': request.preferred_topics,
31
- 'business_details': stored_data['business_details']
32
- },
33
- config={"configurable": {"thread_id": request.thread_id}})
34
-
35
- stored_data['brainstroming_response'] = result
36
-
37
- return {'response':{
38
- "story": result['stories'][-1],
39
- "brainstorming_topics": result['brainstroming_topics'][-1]
40
- }}
 
 
 
 
 
1
+
2
+ import json
3
  from fastapi import APIRouter
4
+ from fastapi.responses import StreamingResponse
5
  from api.stored_data import stored_data
6
  from pydantic import BaseModel
7
  from typing import Optional
8
  from src.genai.brainstroming_agent.agent import brainstroming_graph
9
+ from langgraph.pregel.io import AddableValuesDict
10
 
11
  router=APIRouter()
12
  brainstrom_graph = brainstroming_graph()
 
17
  image_base64_list: Optional[list] = []
18
  thread_id: Optional[str]="default-session"
19
 
20
+
21
  @router.post("/brainstorm")
22
+ def brainstorming_endpoint(request: BrainstormRequest):
 
 
23
  idea = (
24
+ [stored_data['refined_ideation']]
25
+ if stored_data.get('refined_ideation')
26
+ else [str(stored_data['final_ideation'])]
27
+ if stored_data.get('final_ideation')
28
+ else [
29
+ "I don't have any idea right now. Create your own **very creative** and **out of the box** video idea and generate the story for now."
30
+ ]
31
+ )
32
+
33
+ def event_stream():
34
+
35
+ for stream_mode, chunk in brainstrom_graph.stream(
36
+ {
37
+ "idea": idea,
38
+ "images": request.image_base64_list,
39
+ "latest_preferred_topics": request.preferred_topics,
40
+ "business_details": stored_data["business_details"],
41
+ },
42
+ config={"configurable": {"thread_id": request.thread_id}},
43
+ stream_mode=['messages','values']
44
+ ):
45
+ stored_data['brainstorming_response'] = chunk if isinstance(chunk, AddableValuesDict) else stored_data.get('brainstorming_response')
46
+ if isinstance(chunk, tuple): yield chunk[0].content
47
+ return StreamingResponse(event_stream(), media_type="text/event-stream")
api/routers/context_analysis.py CHANGED
@@ -1,5 +1,7 @@
1
  import ast
 
2
  from fastapi import APIRouter, Depends
 
3
  from pydantic import BaseModel
4
  from api.stored_data import stored_data
5
  from src.genai.context_analysis_agent.agent import IntroductionChatbot
@@ -10,19 +12,46 @@ class UserMessage(BaseModel):
10
  message: str
11
  context_analysis_graph = IntroductionChatbot()
12
 
 
 
 
13
  @router.post("/context-analysis")
14
  def context_analysis(msg: UserMessage):
15
- response = context_analysis_graph.chat(msg.message)
16
- if context_analysis_graph.is_complete(response):
17
- details = context_analysis_graph.extract_details()
18
- if type(details) != dict:
19
- details = details.model_dump()
20
- print('Business_details:',details)
21
- if isinstance(details, str):
22
- details= ast.literal_eval(details)
23
- print('Details Type:',type(details))
24
- # save_to_db(details)
25
- stored_data['business_details'] = details
26
- context_analysis_graph.reset()
27
- return {"response": response, "business_details": details, "complete": True}
28
- return {"response": response, "complete": False}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import ast
2
+ import json
3
  from fastapi import APIRouter, Depends
4
+ from fastapi.responses import StreamingResponse
5
  from pydantic import BaseModel
6
  from api.stored_data import stored_data
7
  from src.genai.context_analysis_agent.agent import IntroductionChatbot
 
12
  message: str
13
  context_analysis_graph = IntroductionChatbot()
14
 
15
+
16
+ ## ---------------------- Passing in json ------------------------
17
+
18
  @router.post("/context-analysis")
19
  def context_analysis(msg: UserMessage):
20
+ def event_generator():
21
+ accumulated_response = ""
22
+
23
+ # Stream tokens or partial chunks from your chat generator
24
+ for chunk in context_analysis_graph.chat(msg.message):
25
+ accumulated_response += chunk
26
+ payload = {
27
+ "streamed_response": chunk,
28
+ }
29
+ yield json.dumps(payload) + "\n" # JSON per line
30
+
31
+ # After streaming finished, get completion info
32
+ last_response = context_analysis_graph.messages[-1]["content"]
33
+
34
+ if context_analysis_graph.is_complete(last_response):
35
+ details = context_analysis_graph.extract_details()
36
+ if type(details) != dict:
37
+ details = details.model_dump()
38
+ if isinstance(details, str):
39
+ details = ast.literal_eval(details)
40
+
41
+ stored_data["business_details"] = details
42
+ context_analysis_graph.reset()
43
+
44
+ final_payload = {
45
+ "response": accumulated_response,
46
+ "complete": True,
47
+ "business_details": details
48
+ }
49
+ else:
50
+ final_payload = {
51
+ "response": accumulated_response,
52
+ "complete": False
53
+ }
54
+
55
+ yield json.dumps(final_payload) + "\n"
56
+
57
+ return StreamingResponse(event_generator(), media_type="event-stream")
api/routers/generate_final_story.py CHANGED
@@ -1,4 +1,5 @@
1
  from fastapi import APIRouter
 
2
  from api.stored_data import stored_data
3
  from src.genai.brainstroming_agent.utils.utils import generate_final_story
4
 
@@ -6,10 +7,8 @@ router= APIRouter()
6
 
7
  @router.post("/generate-final-story")
8
  def generate_final_story_endpoint():
9
- final_story = generate_final_story(
10
- stored_data.get("brainstroming_response") or stored_data.get("business_details")
11
- )
12
- stored_data['final_story']=final_story
13
- return {
14
- 'response': final_story
15
- }
 
1
  from fastapi import APIRouter
2
+ from fastapi.responses import StreamingResponse
3
  from api.stored_data import stored_data
4
  from src.genai.brainstroming_agent.utils.utils import generate_final_story
5
 
 
7
 
8
  @router.post("/generate-final-story")
9
  def generate_final_story_endpoint():
10
+ def event_stream():
11
+ for chunk in generate_final_story(stored_data.get('brainstorming_response') or stored_data.get('business_details')):
12
+ yield chunk
13
+
14
+ return StreamingResponse(event_stream(), media_type="text/event-stream")
 
 
api/routers/ideation.py CHANGED
@@ -1,5 +1,6 @@
1
  import ast
2
  from fastapi import APIRouter
 
3
  from api.stored_data import stored_data
4
  from src.genai.ideation_agent.agent import ideation_graph
5
  from langgraph.errors import GraphRecursionError
@@ -25,4 +26,5 @@ def ideation_endpoint():
25
  return {'response':ast.literal_eval(result['improver_response'][-1])}
26
  except GraphRecursionError:
27
  result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
28
- return {'response': result[0]}
 
 
1
  import ast
2
  from fastapi import APIRouter
3
+ from fastapi.responses import StreamingResponse
4
  from api.stored_data import stored_data
5
  from src.genai.ideation_agent.agent import ideation_graph
6
  from langgraph.errors import GraphRecursionError
 
26
  return {'response':ast.literal_eval(result['improver_response'][-1])}
27
  except GraphRecursionError:
28
  result = idea_graph.get_state({"configurable": {"thread_id": "ideation_thread123"}})
29
+ return {'response': result[0]}
30
+
api/routers/orchestration.py CHANGED
@@ -1,4 +1,7 @@
 
 
1
  from fastapi import APIRouter, Depends
 
2
  from pydantic import BaseModel
3
  from api.stored_data import stored_data
4
  from src.genai.orchestration_agent.agent import orchestration_chat
@@ -14,17 +17,17 @@ router= APIRouter()
14
  def orchestration_endpoint(request:OrchestrationRequest):
15
  print('Image:',request.image_base64)
16
  result = orchestration_chat(request.message , request.image_base64)
17
- if result.image_caption != '':
18
- stored_data['image_caption']=result.image_caption
19
- if result.video_idea !='' or result.video_idea != 'null':
20
- stored_data['refined_ideation']= result.video_idea
21
- if result.video_story!='' or result.video_story!='null':
22
- stored_data['final_story']= result.video_story
23
  print('Idea:',stored_data['refined_ideation'])
24
  print('Story:', stored_data['final_story'])
25
 
26
  return {'tool_response': result.tool ,
27
- 'message_response': result.query_response,
28
- 'image_caption':result.image_caption,
29
- 'video_idea': result.video_idea,
30
- 'video_story': result.video_story}
 
 
 
1
+
2
+ import json
3
  from fastapi import APIRouter, Depends
4
+ from fastapi.responses import StreamingResponse
5
  from pydantic import BaseModel
6
  from api.stored_data import stored_data
7
  from src.genai.orchestration_agent.agent import orchestration_chat
 
17
  def orchestration_endpoint(request:OrchestrationRequest):
18
  print('Image:',request.image_base64)
19
  result = orchestration_chat(request.message , request.image_base64)
20
+ if result.image_caption != '': stored_data['image_caption']=result.image_caption
21
+ if result.video_idea !='' or result.video_idea != 'null': stored_data['refined_ideation']= result.video_idea
22
+ if result.video_story!='' or result.video_story!='null': stored_data['final_story']= result.video_story
23
+
 
 
24
  print('Idea:',stored_data['refined_ideation'])
25
  print('Story:', stored_data['final_story'])
26
 
27
  return {'tool_response': result.tool ,
28
+ 'message_response': result.query_response,
29
+ 'image_caption':result.image_caption,
30
+ 'video_idea': result.video_idea,
31
+ 'video_story': result.video_story}
32
+
33
+
api/stored_data.py CHANGED
@@ -7,4 +7,5 @@ stored_data['business_details'] = {
7
  "offerings": "personal training, group fitness classes, modern workout equipment, nutrition guidance, and wellness programs",
8
  "Challenges_faced": "attracting loyal members, standing out in a competitive market, and promoting consistent engagement"
9
  }
10
- stored_data['human_ideation_interactions'] = []
 
 
7
  "offerings": "personal training, group fitness classes, modern workout equipment, nutrition guidance, and wellness programs",
8
  "Challenges_faced": "attracting loyal members, standing out in a competitive market, and promoting consistent engagement"
9
  }
10
+ stored_data['human_ideation_interactions'] = []
11
+ stored_data['brainstorming_response']={}
logs/access.log CHANGED
@@ -22,3 +22,164 @@
22
  2025-08-07 22:21:00,552 | INFO | access_logger | Response status: 200
23
  2025-08-07 22:30:28,130 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/ideation
24
  2025-08-07 22:31:21,403 | INFO | access_logger | Response status: 200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  2025-08-07 22:21:00,552 | INFO | access_logger | Response status: 200
23
  2025-08-07 22:30:28,130 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/ideation
24
  2025-08-07 22:31:21,403 | INFO | access_logger | Response status: 200
25
+ 2025-08-08 12:34:17,614 | INFO | access_logger | Request: GET http://127.0.0.1:8000/docs
26
+ 2025-08-08 12:34:17,700 | INFO | access_logger | Response status: 200
27
+ 2025-08-08 12:34:18,307 | INFO | access_logger | Request: GET http://127.0.0.1:8000/openapi.json
28
+ 2025-08-08 12:34:18,694 | INFO | access_logger | Response status: 200
29
+ 2025-08-08 12:34:33,118 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
30
+ 2025-08-08 12:34:33,196 | INFO | access_logger | Response status: 200
31
+ 2025-08-08 12:35:43,964 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
32
+ 2025-08-08 12:35:43,966 | INFO | access_logger | Response status: 200
33
+ 2025-08-08 12:38:28,583 | INFO | access_logger | Request: POST http://localhost:8000/context-analysis
34
+ 2025-08-08 12:38:28,584 | INFO | access_logger | Response status: 404
35
+ 2025-08-08 12:38:42,076 | INFO | access_logger | Request: POST http://localhost:8000/context-analysis
36
+ 2025-08-08 12:38:42,077 | INFO | access_logger | Response status: 404
37
+ 2025-08-08 12:39:22,455 | INFO | access_logger | Request: POST http://localhost:8000/context-analysis
38
+ 2025-08-08 12:39:22,456 | INFO | access_logger | Response status: 404
39
+ 2025-08-08 12:40:55,457 | INFO | access_logger | Request: POST http://localhost:8000/api/context-analysis
40
+ 2025-08-08 12:40:55,459 | INFO | access_logger | Response status: 200
41
+ 2025-08-08 12:41:02,606 | INFO | access_logger | Request: POST http://localhost:8000/api/context-analysis
42
+ 2025-08-08 12:41:02,607 | INFO | access_logger | Response status: 200
43
+ 2025-08-08 12:41:19,683 | INFO | access_logger | Request: POST http://localhost:8000/api/context-analysis
44
+ 2025-08-08 12:41:19,684 | INFO | access_logger | Response status: 200
45
+ 2025-08-08 12:49:35,934 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
46
+ 2025-08-08 12:49:36,037 | INFO | access_logger | Response status: 200
47
+ 2025-08-08 13:01:42,998 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
48
+ 2025-08-08 13:01:43,000 | INFO | access_logger | Response status: 200
49
+ 2025-08-08 13:08:44,153 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
50
+ 2025-08-08 13:08:44,178 | INFO | access_logger | Response status: 200
51
+ 2025-08-08 13:09:51,201 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
52
+ 2025-08-08 13:09:51,219 | INFO | access_logger | Response status: 200
53
+ 2025-08-08 13:14:54,051 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
54
+ 2025-08-08 13:14:54,053 | INFO | access_logger | Response status: 200
55
+ 2025-08-08 13:19:48,617 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
56
+ 2025-08-08 13:19:48,663 | INFO | access_logger | Response status: 200
57
+ 2025-08-08 13:20:56,481 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
58
+ 2025-08-08 13:20:56,511 | INFO | access_logger | Response status: 200
59
+ 2025-08-08 13:59:38,690 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/context-analysis
60
+ 2025-08-08 13:59:38,719 | INFO | access_logger | Response status: 200
61
+ 2025-08-08 15:00:50,518 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
62
+ 2025-08-08 15:00:50,530 | INFO | access_logger | Response status: 200
63
+ 2025-08-08 15:02:13,449 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
64
+ 2025-08-08 15:02:13,524 | INFO | access_logger | Response status: 200
65
+ 2025-08-08 15:05:18,827 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
66
+ 2025-08-08 15:05:18,931 | INFO | access_logger | Response status: 200
67
+ 2025-08-08 15:06:31,333 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
68
+ 2025-08-08 15:06:31,399 | INFO | access_logger | Response status: 200
69
+ 2025-08-08 15:08:55,531 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
70
+ 2025-08-08 15:08:55,551 | INFO | access_logger | Response status: 200
71
+ 2025-08-08 15:10:07,358 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
72
+ 2025-08-08 15:10:07,379 | INFO | access_logger | Response status: 200
73
+ 2025-08-08 15:12:35,001 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
74
+ 2025-08-08 15:12:35,020 | INFO | access_logger | Response status: 200
75
+ 2025-08-08 15:17:00,191 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
76
+ 2025-08-08 15:17:05,312 | INFO | access_logger | Response status: 200
77
+ 2025-08-08 15:28:53,275 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/ideation
78
+ 2025-08-08 15:28:53,297 | INFO | access_logger | Response status: 200
79
+ 2025-08-08 15:33:57,376 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/ideation
80
+ 2025-08-08 15:34:48,822 | INFO | access_logger | Response status: 200
81
+ 2025-08-08 15:50:01,547 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
82
+ 2025-08-08 15:50:01,581 | INFO | access_logger | Response status: 200
83
+ 2025-08-08 15:58:58,448 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
84
+ 2025-08-08 15:58:58,458 | INFO | access_logger | Response status: 200
85
+ 2025-08-08 16:08:07,260 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
86
+ 2025-08-08 16:08:07,290 | INFO | access_logger | Response status: 200
87
+ 2025-08-08 16:08:32,836 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
88
+ 2025-08-08 16:08:32,837 | INFO | access_logger | Response status: 200
89
+ 2025-08-08 16:09:50,716 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
90
+ 2025-08-08 16:09:50,727 | INFO | access_logger | Response status: 200
91
+ 2025-08-08 16:10:16,510 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
92
+ 2025-08-08 16:10:16,512 | INFO | access_logger | Response status: 200
93
+ 2025-08-08 16:11:30,356 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
94
+ 2025-08-08 16:11:30,380 | INFO | access_logger | Response status: 200
95
+ 2025-08-08 16:12:24,813 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
96
+ 2025-08-08 16:12:24,862 | INFO | access_logger | Response status: 200
97
+ 2025-08-08 16:14:46,454 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
98
+ 2025-08-08 16:14:46,672 | INFO | access_logger | Response status: 200
99
+ 2025-08-08 16:20:24,481 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
100
+ 2025-08-08 16:20:24,517 | INFO | access_logger | Response status: 200
101
+ 2025-08-10 11:48:42,113 | INFO | access_logger | Request: GET http://127.0.0.1:8000/docs
102
+ 2025-08-10 11:48:42,183 | INFO | access_logger | Response status: 200
103
+ 2025-08-10 11:48:42,594 | INFO | access_logger | Request: GET http://127.0.0.1:8000/openapi.json
104
+ 2025-08-10 11:48:43,146 | INFO | access_logger | Response status: 200
105
+ 2025-08-10 11:48:50,843 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
106
+ 2025-08-10 11:48:50,847 | INFO | access_logger | Response status: 200
107
+ 2025-08-10 11:49:39,792 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
108
+ 2025-08-10 11:49:39,794 | INFO | access_logger | Response status: 200
109
+ 2025-08-10 11:51:58,227 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
110
+ 2025-08-10 11:51:58,257 | INFO | access_logger | Response status: 200
111
+ 2025-08-10 11:59:32,675 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
112
+ 2025-08-10 11:59:32,709 | INFO | access_logger | Response status: 200
113
+ 2025-08-10 12:00:42,289 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
114
+ 2025-08-10 12:00:42,318 | INFO | access_logger | Response status: 200
115
+ 2025-08-10 12:12:39,146 | INFO | access_logger | Request: POST http://localhost:8000/brainstorm
116
+ 2025-08-10 12:12:39,164 | INFO | access_logger | Response status: 404
117
+ 2025-08-10 12:12:49,589 | INFO | access_logger | Request: POST http://localhost:8000/brainstorm
118
+ 2025-08-10 12:12:49,590 | INFO | access_logger | Response status: 404
119
+ 2025-08-10 12:13:34,759 | INFO | access_logger | Request: POST http://localhost:8000/brainstorm
120
+ 2025-08-10 12:13:34,759 | INFO | access_logger | Response status: 404
121
+ 2025-08-10 12:14:42,887 | INFO | access_logger | Request: POST http://localhost:8000/brainstorm
122
+ 2025-08-10 12:14:42,888 | INFO | access_logger | Response status: 404
123
+ 2025-08-10 12:17:03,648 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
124
+ 2025-08-10 12:17:03,651 | INFO | access_logger | Response status: 200
125
+ 2025-08-10 12:21:31,107 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
126
+ 2025-08-10 12:21:31,119 | INFO | access_logger | Response status: 200
127
+ 2025-08-10 12:29:51,748 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
128
+ 2025-08-10 12:29:51,787 | INFO | access_logger | Response status: 200
129
+ 2025-08-10 12:30:01,049 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
130
+ 2025-08-10 12:30:01,051 | INFO | access_logger | Response status: 200
131
+ 2025-08-10 12:31:49,109 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
132
+ 2025-08-10 12:31:49,125 | INFO | access_logger | Response status: 200
133
+ 2025-08-10 12:34:16,979 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
134
+ 2025-08-10 12:34:17,008 | INFO | access_logger | Response status: 200
135
+ 2025-08-10 12:35:39,262 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
136
+ 2025-08-10 12:35:39,266 | INFO | access_logger | Response status: 200
137
+ 2025-08-10 12:39:44,154 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
138
+ 2025-08-10 12:39:44,174 | INFO | access_logger | Response status: 200
139
+ 2025-08-10 12:41:35,931 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
140
+ 2025-08-10 12:41:35,950 | INFO | access_logger | Response status: 200
141
+ 2025-08-10 12:45:15,852 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
142
+ 2025-08-10 12:45:15,892 | INFO | access_logger | Response status: 200
143
+ 2025-08-10 12:49:15,614 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
144
+ 2025-08-10 12:49:15,670 | INFO | access_logger | Response status: 200
145
+ 2025-08-10 12:54:52,731 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
146
+ 2025-08-10 12:54:52,801 | INFO | access_logger | Response status: 200
147
+ 2025-08-10 13:04:02,325 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
148
+ 2025-08-10 13:04:02,356 | INFO | access_logger | Response status: 200
149
+ 2025-08-10 13:05:44,152 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
150
+ 2025-08-10 13:05:44,165 | INFO | access_logger | Response status: 200
151
+ 2025-08-10 13:08:14,035 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
152
+ 2025-08-10 13:08:14,106 | INFO | access_logger | Response status: 200
153
+ 2025-08-10 13:09:37,550 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
154
+ 2025-08-10 13:09:37,555 | INFO | access_logger | Response status: 200
155
+ 2025-08-10 13:14:10,482 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
156
+ 2025-08-10 13:14:10,518 | INFO | access_logger | Response status: 200
157
+ 2025-08-10 13:32:25,085 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
158
+ 2025-08-10 13:33:46,468 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
159
+ 2025-08-10 13:33:46,502 | INFO | access_logger | Response status: 200
160
+ 2025-08-10 13:43:49,545 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
161
+ 2025-08-10 13:43:49,592 | INFO | access_logger | Response status: 200
162
+ 2025-08-10 14:12:04,506 | INFO | access_logger | Request: GET http://127.0.0.1:8000/openapi.json
163
+ 2025-08-10 14:12:04,539 | INFO | access_logger | Response status: 200
164
+ 2025-08-10 14:12:56,394 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/generate-final-story
165
+ 2025-08-10 14:12:56,452 | INFO | access_logger | Response status: 200
166
+ 2025-08-10 14:15:18,251 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/generate-final-story
167
+ 2025-08-10 14:15:18,265 | INFO | access_logger | Response status: 200
168
+ 2025-08-10 14:16:26,524 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/orchestration
169
+ 2025-08-10 14:16:32,000 | INFO | access_logger | Response status: 200
170
+ 2025-08-10 14:21:01,210 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
171
+ 2025-08-10 14:21:01,219 | INFO | access_logger | Response status: 200
172
+ 2025-08-10 14:21:40,018 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/generate-final-story
173
+ 2025-08-10 14:21:40,020 | INFO | access_logger | Response status: 200
174
+ 2025-08-10 14:22:22,513 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
175
+ 2025-08-10 14:22:22,515 | INFO | access_logger | Response status: 422
176
+ 2025-08-10 14:22:37,843 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/brainstorm
177
+ 2025-08-10 14:22:37,844 | INFO | access_logger | Response status: 422
178
+ 2025-08-10 14:23:36,931 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
179
+ 2025-08-10 14:23:36,933 | INFO | access_logger | Response status: 422
180
+ 2025-08-10 14:25:26,279 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
181
+ 2025-08-10 14:25:26,280 | INFO | access_logger | Response status: 422
182
+ 2025-08-10 14:26:05,319 | INFO | access_logger | Request: POST http://localhost:8000/api/brainstorm
183
+ 2025-08-10 14:26:05,321 | INFO | access_logger | Response status: 200
184
+ 2025-08-10 14:27:01,144 | INFO | access_logger | Request: POST http://127.0.0.1:8000/api/generate-final-story
185
+ 2025-08-10 14:27:01,146 | INFO | access_logger | Response status: 200
src/genai/brainstroming_agent/__pycache__/agent.cpython-312.pyc CHANGED
Binary files a/src/genai/brainstroming_agent/__pycache__/agent.cpython-312.pyc and b/src/genai/brainstroming_agent/__pycache__/agent.cpython-312.pyc differ
 
src/genai/brainstroming_agent/agent.py CHANGED
@@ -17,15 +17,7 @@ def brainstroming_graph():
17
  # Normal edges
18
  builder.add_edge(START, "caption_image")
19
  builder.add_edge("caption_image", "retrieve")
20
-
21
- # builder.add_edge(START, "retrieve")
22
  builder.add_edge("retrieve", "generate_story")
23
-
24
- # builder.add_edge("retrieve", "generate_story")
25
  builder.add_edge("generate_story", "generate_brainstroming")
26
-
27
- # Conditional edge
28
  builder.add_edge("generate_brainstroming", END)
29
- # builder.add_edge("generate_final_story",END)
30
-
31
  return builder.compile(checkpointer=memory)
 
17
  # Normal edges
18
  builder.add_edge(START, "caption_image")
19
  builder.add_edge("caption_image", "retrieve")
 
 
20
  builder.add_edge("retrieve", "generate_story")
 
 
21
  builder.add_edge("generate_story", "generate_brainstroming")
 
 
22
  builder.add_edge("generate_brainstroming", END)
 
 
23
  return builder.compile(checkpointer=memory)
src/genai/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc CHANGED
Binary files a/src/genai/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc and b/src/genai/brainstroming_agent/utils/__pycache__/nodes.cpython-312.pyc differ
 
src/genai/brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc CHANGED
Binary files a/src/genai/brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc and b/src/genai/brainstroming_agent/utils/__pycache__/utils.cpython-312.pyc differ
 
src/genai/brainstroming_agent/utils/nodes.py CHANGED
@@ -2,8 +2,8 @@ import pandas as pd
2
  import ast
3
  from .state import State
4
  from .tools import retrieve_tool
5
- from langchain_core.messages import SystemMessage ,HumanMessage, ToolMessage
6
- from src.genai.utils.models_loader import llm , ST
7
  from src.genai.utils.data_loader import load_influencer_data
8
  from groq import Groq
9
  import os
@@ -74,7 +74,7 @@ def retrieve(state: State) -> State:
74
 
75
  def generate_story(state:State)-> State:
76
  react_agent=create_react_agent(
77
- model=llm,
78
  tools=[]
79
 
80
  )
@@ -83,13 +83,12 @@ def generate_story(state:State)-> State:
83
  else:
84
  template = refined_story_prompt(state)
85
 
86
- # and {state.image_captions[-1]}
87
 
88
  messages = [SystemMessage(content=template),
89
  HumanMessage(content=f'''The idea of the video is:\n{state.idea}\n'''),
90
- ToolMessage(content=f'''The business details is:\n{state.business_details}\n
91
  The retrieved data of influencers is:\n{state.retrievals[-1]}\n
92
- The information from the image is:\n{state.image_captions[-1]} ''', tool_call_id='generate_story_tool')]
93
 
94
  print('Messages:',messages)
95
 
@@ -107,13 +106,12 @@ def generate_brainstroming(state:State)-> State:
107
 
108
  messages = [SystemMessage(content=template),
109
  HumanMessage(content=f'''Here is the story to you for brainstorming:\n{state.stories[-1]}'''),
110
- ToolMessage(content=f'''The details of business is:\n{state.business_details}\n''', tool_call_id="brainstorm_tool")]
111
  print('Message for brainstorming:',messages)
112
- response = llm.with_structured_output(BrainstromTopicFormatter).invoke(messages)
113
  response = response.model_dump()
114
  state.brainstroming_topics.append(response)
115
  print('The brainstroming topics are:',state.brainstroming_topics)
116
- # return State(messages="Story generated",topic=state.topic,brainstroming_topics=state.brainstroming_topics)
117
  return state
118
 
119
 
@@ -123,4 +121,5 @@ def generate_brainstroming(state:State)-> State:
123
 
124
 
125
 
 
126
 
 
2
  import ast
3
  from .state import State
4
  from .tools import retrieve_tool
5
+ from langchain_core.messages import SystemMessage ,HumanMessage, ToolMessage, FunctionMessage
6
+ from src.genai.utils.models_loader import llm , llm_gpt
7
  from src.genai.utils.data_loader import load_influencer_data
8
  from groq import Groq
9
  import os
 
74
 
75
  def generate_story(state:State)-> State:
76
  react_agent=create_react_agent(
77
+ model=llm_gpt,
78
  tools=[]
79
 
80
  )
 
83
  else:
84
  template = refined_story_prompt(state)
85
 
 
86
 
87
  messages = [SystemMessage(content=template),
88
  HumanMessage(content=f'''The idea of the video is:\n{state.idea}\n'''),
89
+ FunctionMessage(name='generate_story_function',content=f'''The business details is:\n{state.business_details}\n
90
  The retrieved data of influencers is:\n{state.retrievals[-1]}\n
91
+ The information from the image is:\n{state.image_captions[-1]} ''')]
92
 
93
  print('Messages:',messages)
94
 
 
106
 
107
  messages = [SystemMessage(content=template),
108
  HumanMessage(content=f'''Here is the story to you for brainstorming:\n{state.stories[-1]}'''),
109
+ FunctionMessage(content=f'''The details of business is:\n{state.business_details}\n''', name="brainstorm_tool")]
110
  print('Message for brainstorming:',messages)
111
+ response = llm_gpt.with_structured_output(BrainstromTopicFormatter).invoke(messages)
112
  response = response.model_dump()
113
  state.brainstroming_topics.append(response)
114
  print('The brainstroming topics are:',state.brainstroming_topics)
 
115
  return state
116
 
117
 
 
121
 
122
 
123
 
124
+
125
 
src/genai/brainstroming_agent/utils/utils.py CHANGED
@@ -1,5 +1,5 @@
1
 
2
- from langchain_core.messages import SystemMessage, ToolMessage, HumanMessage
3
  from .tools import retrieve_tool
4
  import base64
5
  from PIL import Image
@@ -11,7 +11,9 @@ import os
11
  from langgraph.prebuilt import create_react_agent
12
  import pandas as pd
13
  from datasets import load_dataset
14
- from src.genai.utils.models_loader import llm
 
 
15
 
16
  def generate_final_story(final_state):
17
  if 'preferred_topics' in final_state:
@@ -19,30 +21,31 @@ def generate_final_story(final_state):
19
  template = final_story_prompt(final_state)
20
  messages = [SystemMessage(content=template),
21
  HumanMessage(content=f'''The idea of the video is:\n{final_state['idea']}\n '''),
22
- ToolMessage(content=f'''The business details is:\n{final_state['business_details']}\nThe data of influencers is:\n{final_state['retrievals'][-1]}''',tool_call_id='final_story_tool')]
23
  print('The message of final story:',messages)
24
 
25
  react_agent=create_react_agent(
26
- model=llm,
27
  tools=[])
28
 
29
- response = react_agent.invoke({'messages':messages})
30
- response = response['messages'][-1].content
31
- return response
32
-
33
  else:
34
- return final_state['stories'][-1]
 
35
  else:
36
  template = final_story_prompt(final_state)
37
  influencers_data = retrieve_tool(final_state)
38
  messages = [SystemMessage(content=template),
39
- ToolMessage(content=f'''The business details is:\n{str(final_state)}\nThe data of influencers is:\n{influencers_data}''',tool_call_id='final_story_tool')]
40
  react_agent=create_react_agent(
41
- model=llm,
42
  tools=[])
43
- response = react_agent.invoke({'messages':messages})
44
- response = response['messages'][-1].content
45
- return response
 
46
 
47
 
48
 
@@ -60,10 +63,10 @@ def generate_prompt(final_story,business_details,refined_ideation):
60
  print('************Entering prompt generator****************')
61
  messages = [SystemMessage(content=story_to_prompt()),
62
  HumanMessage(content=f'''The scene-by-scene video story is {final_story}'''),
63
- ToolMessage(content=f'''The business details is:\n{business_details}\nThe idea is{refined_ideation}''',tool_call_id='prompt_generation_id')
64
  ]
65
 
66
- prompt = llm.invoke(messages)
67
  print('The prompt is:',prompt)
68
  return prompt.content
69
 
 
1
 
2
+ from langchain_core.messages import SystemMessage, ToolMessage, HumanMessage, FunctionMessage
3
  from .tools import retrieve_tool
4
  import base64
5
  from PIL import Image
 
11
  from langgraph.prebuilt import create_react_agent
12
  import pandas as pd
13
  from datasets import load_dataset
14
+ from src.genai.utils.models_loader import llm_gpt
15
+
16
+
17
 
18
  def generate_final_story(final_state):
19
  if 'preferred_topics' in final_state:
 
21
  template = final_story_prompt(final_state)
22
  messages = [SystemMessage(content=template),
23
  HumanMessage(content=f'''The idea of the video is:\n{final_state['idea']}\n '''),
24
+ FunctionMessage(content=f'''The business details is:\n{final_state['business_details']}\nThe data of influencers is:\n{final_state['retrievals'][-1]}''',name='final_story_tool')]
25
  print('The message of final story:',messages)
26
 
27
  react_agent=create_react_agent(
28
+ model=llm_gpt,
29
  tools=[])
30
 
31
+ for message_chunk , metadata in react_agent.stream({'messages':messages},stream_mode='messages'):
32
+ yield message_chunk.content
33
+
 
34
  else:
35
+ for chunk in final_state['stories'][-1]:
36
+ yield chunk
37
  else:
38
  template = final_story_prompt(final_state)
39
  influencers_data = retrieve_tool(final_state)
40
  messages = [SystemMessage(content=template),
41
+ FunctionMessage(content=f'''The business details is:\n{str(final_state)}\nThe data of influencers is:\n{influencers_data}''',name='final_story_tool')]
42
  react_agent=create_react_agent(
43
+ model=llm_gpt,
44
  tools=[])
45
+
46
+ for message_chunk , metadata in react_agent.stream({'messages':messages},stream_mode='messages'):
47
+ yield message_chunk.content
48
+
49
 
50
 
51
 
 
63
  print('************Entering prompt generator****************')
64
  messages = [SystemMessage(content=story_to_prompt()),
65
  HumanMessage(content=f'''The scene-by-scene video story is {final_story}'''),
66
+ FunctionMessage(content=f'''The business details is:\n{business_details}\nThe idea is{refined_ideation}''',name='prompt_generation_id')
67
  ]
68
 
69
+ prompt = llm_gpt.invoke(messages)
70
  print('The prompt is:',prompt)
71
  return prompt.content
72
 
src/genai/context_analysis_agent/__pycache__/agent.cpython-312.pyc CHANGED
Binary files a/src/genai/context_analysis_agent/__pycache__/agent.cpython-312.pyc and b/src/genai/context_analysis_agent/__pycache__/agent.cpython-312.pyc differ
 
src/genai/context_analysis_agent/agent.py CHANGED
@@ -25,10 +25,13 @@ class IntroductionChatbot:
25
  def chat(self, user_input: str):
26
  self.messages.append({"role": "user", "content": user_input})
27
  config = {"configurable": {"thread_id": "1"}}
28
- response = self.interact_agent.invoke({"messages": [user_input]}, config)['messages'][-1].content
29
- self.messages.append({"role": "assistant", "content": response})
30
- business_state.interactions.append({'user': user_input, 'agent_response': response})
31
- return response
 
 
 
32
 
33
  def is_complete(self, latest_response: str) -> bool:
34
  return "Thanks for providing all your required business details" in latest_response
 
25
  def chat(self, user_input: str):
26
  self.messages.append({"role": "user", "content": user_input})
27
  config = {"configurable": {"thread_id": "1"}}
28
+ for message_chunk, metadata in self.interact_agent.stream(
29
+ {"messages": [user_input]},
30
+ config=config,
31
+ stream_mode="messages"
32
+ ):
33
+ yield message_chunk.content
34
+
35
 
36
  def is_complete(self, latest_response: str) -> bool:
37
  return "Thanks for providing all your required business details" in latest_response
src/genai/orchestration_agent/__pycache__/agent.cpython-312.pyc CHANGED
Binary files a/src/genai/orchestration_agent/__pycache__/agent.cpython-312.pyc and b/src/genai/orchestration_agent/__pycache__/agent.cpython-312.pyc differ
 
src/genai/orchestration_agent/agent.py CHANGED
@@ -23,6 +23,7 @@ def orchestration_graph():
23
 
24
  user_input_history = []
25
  def orchestration_chat(user_input: str, image_base64=[]):
 
26
  global user_input_history
27
  user_input_history.append({'role': 'human', 'content': user_input})
28
 
 
23
 
24
  user_input_history = []
25
  def orchestration_chat(user_input: str, image_base64=[]):
26
+ print('Message Chunk:')
27
  global user_input_history
28
  user_input_history.append({'role': 'human', 'content': user_input})
29