wishwakankanamg commited on
Commit
cdc62bb
·
1 Parent(s): 6a1ad3d

this thing damn works

Browse files
Files changed (4) hide show
  1. __pycache__/graph.cpython-310.pyc +0 -0
  2. app.log +128 -0
  3. app.py +2 -2
  4. graph.py +60 -45
__pycache__/graph.cpython-310.pyc CHANGED
Binary files a/__pycache__/graph.cpython-310.pyc and b/__pycache__/graph.cpython-310.pyc differ
 
app.log CHANGED
@@ -50301,3 +50301,131 @@ For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/er
50301
  2025-06-06 18:34:27:__main__:INFO: Starting the interface
50302
  2025-06-06 18:34:31:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50303
  2025-06-06 18:35:28:__main__:INFO: Prompt: You are a helpful assistant.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50301
  2025-06-06 18:34:27:__main__:INFO: Starting the interface
50302
  2025-06-06 18:34:31:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50303
  2025-06-06 18:35:28:__main__:INFO: Prompt: You are a helpful assistant.
50304
+ 2025-06-06 18:45:50:__main__:INFO: Prompt: You are a helpful assistant.
50305
+ 2025-06-06 18:52:40:__main__:INFO: Starting the interface
50306
+ 2025-06-06 18:52:45:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50307
+ 2025-06-06 18:52:48:__main__:INFO: Prompt: You are a helpful assistant.
50308
+ 2025-06-06 18:53:33:asyncio:ERROR: Task exception was never retrieved
50309
+ future: <Task finished name='Task-1197' coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("generator didn't stop after athrow()")>
50310
+ Traceback (most recent call last):
50311
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2663, in astream
50312
+ yield o
50313
+ GeneratorExit
50314
+
50315
+ During handling of the above exception, another exception occurred:
50316
+
50317
+ Traceback (most recent call last):
50318
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2596, in astream
50319
+ async with AsyncPregelLoop(
50320
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/loop.py", line 1393, in __aexit__
50321
+ return await exit_task
50322
+ File "/usr/local/lib/python3.10/contextlib.py", line 714, in __aexit__
50323
+ raise exc_details[1]
50324
+ File "/usr/local/lib/python3.10/contextlib.py", line 697, in __aexit__
50325
+ cb_suppress = await cb(*exc_details)
50326
+ File "/usr/local/lib/python3.10/contextlib.py", line 249, in __aexit__
50327
+ raise RuntimeError("generator didn't stop after athrow()")
50328
+ RuntimeError: generator didn't stop after athrow()
50329
+ 2025-06-06 18:56:39:__main__:INFO: Starting the interface
50330
+ 2025-06-06 18:56:43:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50331
+ 2025-06-06 18:58:35:__main__:INFO: Prompt: You are a helpful assistant.
50332
+ 2025-06-06 18:58:35:__main__:ERROR: Exception occurred
50333
+ Traceback (most recent call last):
50334
+ File "/home/user/app/app.py", line 97, in chat_fn
50335
+ async for stream_mode, chunk in graph.astream(
50336
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2655, in astream
50337
+ async for _ in runner.atick(
50338
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/runner.py", line 400, in atick
50339
+ _panic_or_proceed(
50340
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/runner.py", line 509, in _panic_or_proceed
50341
+ raise exc
50342
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/retry.py", line 136, in arun_with_retry
50343
+ return await task.proc.ainvoke(task.input, config)
50344
+ File "/usr/local/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 676, in ainvoke
50345
+ input = await step.ainvoke(input, config, **kwargs)
50346
+ File "/usr/local/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 440, in ainvoke
50347
+ ret = await self.afunc(*args, **kwargs)
50348
+ File "/home/user/app/graph.py", line 154, in guidance_node
50349
+ print(f"Tools Enabled: {state.tools_enabled}")
50350
+ File "/usr/local/lib/python3.10/site-packages/pydantic/main.py", line 891, in __getattr__
50351
+ raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
50352
+ AttributeError: 'GraphProcessingState' object has no attribute 'tools_enabled'
50353
+ 2025-06-06 19:03:03:__main__:INFO: Starting the interface
50354
+ 2025-06-06 19:03:07:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50355
+ 2025-06-06 19:03:17:__main__:INFO: Prompt: You are a helpful assistant.
50356
+ 2025-06-06 19:03:21:__main__:ERROR: Exception occurred
50357
+ Traceback (most recent call last):
50358
+ File "/home/user/app/app.py", line 97, in chat_fn
50359
+ async for stream_mode, chunk in graph.astream(
50360
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2655, in astream
50361
+ async for _ in runner.atick(
50362
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/runner.py", line 400, in atick
50363
+ _panic_or_proceed(
50364
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/runner.py", line 509, in _panic_or_proceed
50365
+ raise exc
50366
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/retry.py", line 136, in arun_with_retry
50367
+ return await task.proc.ainvoke(task.input, config)
50368
+ File "/usr/local/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 678, in ainvoke
50369
+ input = await step.ainvoke(input, config)
50370
+ File "/usr/local/lib/python3.10/site-packages/langgraph/utils/runnable.py", line 440, in ainvoke
50371
+ ret = await self.afunc(*args, **kwargs)
50372
+ File "/usr/local/lib/python3.10/site-packages/langgraph/graph/branch.py", line 185, in _aroute
50373
+ value = reader(config)
50374
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/read.py", line 110, in do_read
50375
+ return mapper(read(select, fresh))
50376
+ File "/usr/local/lib/python3.10/site-packages/langgraph/graph/state.py", line 1050, in _coerce_state
50377
+ return schema(**input)
50378
+ File "/usr/local/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
50379
+ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
50380
+ pydantic_core._pydantic_core.ValidationError: 1 validation error for GraphProcessingState
50381
+ next_stage
50382
+ Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
50383
+ For further information visit https://errors.pydantic.dev/2.10/v/string_type
50384
+ 2025-06-06 19:05:35:__main__:INFO: Starting the interface
50385
+ 2025-06-06 19:05:39:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50386
+ 2025-06-06 19:05:59:__main__:INFO: Prompt: You are a helpful assistant.
50387
+ 2025-06-06 19:06:36:asyncio:ERROR: Task exception was never retrieved
50388
+ future: <Task finished name='Task-1329' coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("generator didn't stop after athrow()")>
50389
+ Traceback (most recent call last):
50390
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2663, in astream
50391
+ yield o
50392
+ GeneratorExit
50393
+
50394
+ During handling of the above exception, another exception occurred:
50395
+
50396
+ Traceback (most recent call last):
50397
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2596, in astream
50398
+ async with AsyncPregelLoop(
50399
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/loop.py", line 1393, in __aexit__
50400
+ return await exit_task
50401
+ File "/usr/local/lib/python3.10/contextlib.py", line 714, in __aexit__
50402
+ raise exc_details[1]
50403
+ File "/usr/local/lib/python3.10/contextlib.py", line 697, in __aexit__
50404
+ cb_suppress = await cb(*exc_details)
50405
+ File "/usr/local/lib/python3.10/contextlib.py", line 249, in __aexit__
50406
+ raise RuntimeError("generator didn't stop after athrow()")
50407
+ RuntimeError: generator didn't stop after athrow()
50408
+ 2025-06-06 19:14:45:__main__:INFO: Starting the interface
50409
+ 2025-06-06 19:14:49:__main__:INFO: Greeting added for new user via handle_initial_greeting_load.
50410
+ 2025-06-06 19:14:55:__main__:INFO: Prompt: You are a helpful assistant.
50411
+ 2025-06-06 19:15:37:asyncio:ERROR: Task exception was never retrieved
50412
+ future: <Task finished name='Task-1216' coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("generator didn't stop after athrow()")>
50413
+ Traceback (most recent call last):
50414
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2663, in astream
50415
+ yield o
50416
+ GeneratorExit
50417
+
50418
+ During handling of the above exception, another exception occurred:
50419
+
50420
+ Traceback (most recent call last):
50421
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/__init__.py", line 2596, in astream
50422
+ async with AsyncPregelLoop(
50423
+ File "/usr/local/lib/python3.10/site-packages/langgraph/pregel/loop.py", line 1393, in __aexit__
50424
+ return await exit_task
50425
+ File "/usr/local/lib/python3.10/contextlib.py", line 714, in __aexit__
50426
+ raise exc_details[1]
50427
+ File "/usr/local/lib/python3.10/contextlib.py", line 697, in __aexit__
50428
+ cb_suppress = await cb(*exc_details)
50429
+ File "/usr/local/lib/python3.10/contextlib.py", line 249, in __aexit__
50430
+ raise RuntimeError("generator didn't stop after athrow()")
50431
+ RuntimeError: generator didn't stop after athrow()
app.py CHANGED
@@ -125,8 +125,8 @@ async def chat_fn(user_input: str, history: dict, input_graph_state: dict, uuid:
125
  input_graph_state["awaiting_human_input"] = True
126
  input_graph_state["human_assistance_tool_id"] = msg_tool_call["id"]
127
 
128
- # Show input textbox to user and pause graph execution
129
- yield "\n".join(waiting_output_seq), gr.Textbox(visible=True, label="Your input"), gr.skip()
130
  return # Pause execution, resume in next call
131
 
132
  else:
 
125
  input_graph_state["awaiting_human_input"] = True
126
  input_graph_state["human_assistance_tool_id"] = msg_tool_call["id"]
127
 
128
+ # Indicate that human input is needed
129
+ yield "\n".join(waiting_output_seq), input_graph_state, gr.skip(), True
130
  return # Pause execution, resume in next call
131
 
132
  else:
graph.py CHANGED
@@ -128,19 +128,14 @@ class GraphProcessingState(BaseModel):
128
 
129
 
130
  async def guidance_node(state: GraphProcessingState, config=None):
131
- # Use logger.debug() for verbose debugging information
132
- # This allows you to control its visibility via logging configuration
133
- print("\n--- Guidance Node (Debug via print) ---") # Added a newline for clarity
134
-
135
 
136
  print(f"Prompt: {state.prompt}")
137
  for message in state.messages:
138
  if isinstance(message, HumanMessage):
139
  print(f"Human: {message.content}")
140
  elif isinstance(message, AIMessage):
141
- # Check if content is non-empty
142
  if message.content:
143
- # If content is a list (e.g., list of dicts), extract text
144
  if isinstance(message.content, list):
145
  texts = [item.get('text', '') for item in message.content if isinstance(item, dict) and 'text' in item]
146
  if texts:
@@ -156,21 +151,17 @@ async def guidance_node(state: GraphProcessingState, config=None):
156
  print(f"Search Enabled: {state.search_enabled}")
157
  print(f"Next Stage: {state.next_stage}")
158
 
159
-
160
- # Log boolean completion flags
161
  print(f"Idea Complete: {state.idea_complete}")
162
  print(f"Brainstorming Complete: {state.brainstorming_complete}")
163
  print(f"Planning Complete: {state.planning_complete}")
164
  print(f"Drawing Complete: {state.drawing_complete}")
165
  print(f"Product Searching Complete: {state.product_searching_complete}")
166
  print(f"Purchasing Complete: {state.purchasing_complete}")
167
-
168
-
169
  guidance_node.count = getattr(guidance_node, 'count', 0) + 1
170
  print('\nGuidance Node called count', guidance_node.count)
171
- print("\n--- End Guidance Node Debug ---") # Added for clarity
172
 
173
- # Prepare context: stage completion statuses
174
  stage_order = ["brainstorming", "planning", "drawing", "product_searching", "purchasing"]
175
  completed = [stage for stage in stage_order if getattr(state, f"{stage}_complete", False)]
176
  incomplete = [stage for stage in stage_order if not getattr(state, f"{stage}_complete", False)]
@@ -180,17 +171,15 @@ async def guidance_node(state: GraphProcessingState, config=None):
180
  guidance_prompt = (
181
  "You are the guiding assistant. Based on the user's input and the current project status, "
182
  "help decide the next stage in the DIY process. Ask the user which stage to continue next if needed.\n\n"
183
- f"CURRENT STATUS:\n{status_summary}\n\n" # <-- The information was moved here
184
  "Available stages: brainstorming, planning, drawing, product_searching, purchasing."
185
  )
186
 
187
- # Build final prompt with base and current prompt
188
  if state.prompt:
189
  final_prompt = "\n".join([guidance_prompt, state.prompt, ASSISTANT_SYSTEM_PROMPT_BASE])
190
  else:
191
  final_prompt = "\n".join([guidance_prompt, ASSISTANT_SYSTEM_PROMPT_BASE])
192
 
193
- # Create prompt template
194
  prompt = ChatPromptTemplate.from_messages(
195
  [
196
  ("system", final_prompt),
@@ -198,45 +187,72 @@ async def guidance_node(state: GraphProcessingState, config=None):
198
  ]
199
  )
200
 
201
- # Bind tools if needed (minimal here, mostly guidance)
202
- assistant_model = model.bind_tools([])
203
 
204
- # Create the chain
205
  chain = prompt | assistant_model
206
 
207
-
208
-
209
- # Get response from assistant
210
- response = await chain.ainvoke({"messages": state.messages}, config=config)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
- for msg in response:
213
- if isinstance(msg, HumanMessage):
214
- print("Human:", msg.content)
215
- elif isinstance(msg, AIMessage):
216
- if isinstance(msg.content, list):
217
- ai_texts = [part.get("text", "") for part in msg.content if isinstance(part, dict)]
218
- print("AI:", " ".join(ai_texts))
219
- else:
220
- print("AI:", msg.content)
221
 
222
- return {
223
- "messages": response,
224
- "next_stage": incomplete[0] if incomplete else None
225
- }
226
 
227
- async def brainstorming_node(state: GraphProcessingState, config=None):
228
- print("\n--- brainstorming_node (Debug via print) ---")
229
  print(f"Prompt: {state.prompt}")
230
-
231
- # Log the content of each message
232
  for message in state.messages:
233
- if isinstance(message, (HumanMessage, AIMessage, SystemMessage, ToolMessage)):
234
- print(f"Message Content: {message.content}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
- print(f"Tools called: {state.tool_call_required}")
237
  print(f"Search Enabled: {state.search_enabled}")
238
  print(f"Next Stage: {state.next_stage}")
239
 
 
240
  # Log boolean completion flags
241
  print(f"Idea Complete: {state.idea_complete}")
242
  print(f"Brainstorming Complete: {state.brainstorming_complete}")
@@ -244,7 +260,6 @@ async def brainstorming_node(state: GraphProcessingState, config=None):
244
  print(f"Drawing Complete: {state.drawing_complete}")
245
  print(f"Product Searching Complete: {state.product_searching_complete}")
246
  print(f"Purchasing Complete: {state.purchasing_complete}")
247
- print("--- End Guidance Node Debug ---")
248
 
249
  # Check if model is available
250
  if not model:
@@ -452,10 +467,10 @@ def define_workflow() -> CompiledStateGraph:
452
  # workflow.add_edge("tools", "brainstorming_node")
453
 
454
  workflow.add_conditional_edges(
455
- "brainstorming_node",
456
  tools_condition,
457
  )
458
- workflow.add_conditional_edges("guidance_node", guidance_routing)
459
  # workflow.add_conditional_edges("brainstorming_node", brainstorming_routing)
460
 
461
  # # Set end nodes
 
128
 
129
 
130
  async def guidance_node(state: GraphProcessingState, config=None):
131
+ print("\n--- Guidance Node (Debug via print) ---")
 
 
 
132
 
133
  print(f"Prompt: {state.prompt}")
134
  for message in state.messages:
135
  if isinstance(message, HumanMessage):
136
  print(f"Human: {message.content}")
137
  elif isinstance(message, AIMessage):
 
138
  if message.content:
 
139
  if isinstance(message.content, list):
140
  texts = [item.get('text', '') for item in message.content if isinstance(item, dict) and 'text' in item]
141
  if texts:
 
151
  print(f"Search Enabled: {state.search_enabled}")
152
  print(f"Next Stage: {state.next_stage}")
153
 
 
 
154
  print(f"Idea Complete: {state.idea_complete}")
155
  print(f"Brainstorming Complete: {state.brainstorming_complete}")
156
  print(f"Planning Complete: {state.planning_complete}")
157
  print(f"Drawing Complete: {state.drawing_complete}")
158
  print(f"Product Searching Complete: {state.product_searching_complete}")
159
  print(f"Purchasing Complete: {state.purchasing_complete}")
160
+
 
161
  guidance_node.count = getattr(guidance_node, 'count', 0) + 1
162
  print('\nGuidance Node called count', guidance_node.count)
163
+ print("\n--- End Guidance Node Debug ---")
164
 
 
165
  stage_order = ["brainstorming", "planning", "drawing", "product_searching", "purchasing"]
166
  completed = [stage for stage in stage_order if getattr(state, f"{stage}_complete", False)]
167
  incomplete = [stage for stage in stage_order if not getattr(state, f"{stage}_complete", False)]
 
171
  guidance_prompt = (
172
  "You are the guiding assistant. Based on the user's input and the current project status, "
173
  "help decide the next stage in the DIY process. Ask the user which stage to continue next if needed.\n\n"
174
+ f"CURRENT STATUS:\n{status_summary}\n\n"
175
  "Available stages: brainstorming, planning, drawing, product_searching, purchasing."
176
  )
177
 
 
178
  if state.prompt:
179
  final_prompt = "\n".join([guidance_prompt, state.prompt, ASSISTANT_SYSTEM_PROMPT_BASE])
180
  else:
181
  final_prompt = "\n".join([guidance_prompt, ASSISTANT_SYSTEM_PROMPT_BASE])
182
 
 
183
  prompt = ChatPromptTemplate.from_messages(
184
  [
185
  ("system", final_prompt),
 
187
  ]
188
  )
189
 
190
+ assistant_model = model.bind_tools([human_assistance])
 
191
 
 
192
  chain = prompt | assistant_model
193
 
194
+ try:
195
+ response = await chain.ainvoke({"messages": state.messages}, config=config)
196
+
197
+ for msg in response:
198
+ if isinstance(msg, HumanMessage):
199
+ print("Human:", msg.content)
200
+ elif isinstance(msg, AIMessage):
201
+ if isinstance(msg.content, list):
202
+ ai_texts = [part.get("text", "") for part in msg.content if isinstance(part, dict)]
203
+ print("AI:", " ".join(ai_texts))
204
+ else:
205
+ print("AI:", msg.content)
206
+
207
+ # Check for tool calls in the response
208
+ if hasattr(response, "tool_calls"):
209
+ for tool_call in response.tool_calls:
210
+ tool_name = tool_call['name']
211
+ if tool_name == "human_assistance":
212
+ query = tool_call['args']['query']
213
+ print(f"Human input needed: {query}")
214
+ # Handle human assistance tool call
215
+ # You can pause execution and wait for user input here
216
+
217
+ return {
218
+ "messages": [response],
219
+ "next_stage": incomplete[0] if incomplete else "brainstorming"
220
+ }
221
+ except Exception as e:
222
+ print(f"Error in guidance node: {e}")
223
+ return {
224
+ "messages": [AIMessage(content="Error in guidance node.")],
225
+ "next_stage": "brainstorming"
226
+ }
227
 
228
+ async def brainstorming_node(state: GraphProcessingState, config=None):
229
+ print("\n--- Guidance Node (Debug via print) ---") # Added a newline for clarity
 
 
 
 
 
 
 
230
 
 
 
 
 
231
 
 
 
232
  print(f"Prompt: {state.prompt}")
 
 
233
  for message in state.messages:
234
+ if isinstance(message, HumanMessage):
235
+ print(f"Human: {message.content}")
236
+ elif isinstance(message, AIMessage):
237
+ # Check if content is non-empty
238
+ if message.content:
239
+ # If content is a list (e.g., list of dicts), extract text
240
+ if isinstance(message.content, list):
241
+ texts = [item.get('text', '') for item in message.content if isinstance(item, dict) and 'text' in item]
242
+ if texts:
243
+ print(f"AI: {' '.join(texts)}")
244
+ elif isinstance(message.content, str):
245
+ print(f"AI: {message.content}")
246
+ elif isinstance(message, SystemMessage):
247
+ print(f"System: {message.content}")
248
+ elif isinstance(message, ToolMessage):
249
+ print(f"Tool: {message.content}")
250
 
251
+ print(f"Tools Enabled: {state.tools_enabled}")
252
  print(f"Search Enabled: {state.search_enabled}")
253
  print(f"Next Stage: {state.next_stage}")
254
 
255
+
256
  # Log boolean completion flags
257
  print(f"Idea Complete: {state.idea_complete}")
258
  print(f"Brainstorming Complete: {state.brainstorming_complete}")
 
260
  print(f"Drawing Complete: {state.drawing_complete}")
261
  print(f"Product Searching Complete: {state.product_searching_complete}")
262
  print(f"Purchasing Complete: {state.purchasing_complete}")
 
263
 
264
  # Check if model is available
265
  if not model:
 
467
  # workflow.add_edge("tools", "brainstorming_node")
468
 
469
  workflow.add_conditional_edges(
470
+ "guidance_node",
471
  tools_condition,
472
  )
473
+ # workflow.add_conditional_edges("guidance_node", guidance_routing)
474
  # workflow.add_conditional_edges("brainstorming_node", brainstorming_routing)
475
 
476
  # # Set end nodes