naman1102 commited on
Commit
6e59961
·
1 Parent(s): 45c7739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from typing import Dict, Any, List, TypedDict, Annotated
7
  from langgraph.graph import Graph, StateGraph
8
  from langgraph.prebuilt import ToolNode
9
  from pydantic import BaseModel, Field
@@ -15,6 +15,9 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  MODEL_API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct"
16
  HF_TOKEN = os.getenv("HF_TOKEN") # Make sure to set this environment variable
17
 
 
 
 
18
  class AgentState(BaseModel):
19
  """Schema for the agent's state."""
20
  question: str = Field(..., description="The original question")
@@ -150,13 +153,17 @@ class BasicAgent:
150
 
151
  def _create_workflow(self) -> Graph:
152
  """Create the agent workflow using LangGraph."""
153
- workflow = StateGraph(AgentState)
 
 
 
 
154
 
155
- # Add nodes
156
- workflow.add_node("analyze", self._analyze_question)
157
- workflow.add_node("calculator", self._use_calculator)
158
- workflow.add_node("search", self._use_search)
159
- workflow.add_node("final_answer", self._generate_final_answer)
160
 
161
  # Define edges
162
  workflow.add_edge("analyze", "calculator")
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from typing import Dict, Any, List, TypedDict, Annotated, TypeVar, cast
7
  from langgraph.graph import Graph, StateGraph
8
  from langgraph.prebuilt import ToolNode
9
  from pydantic import BaseModel, Field
 
15
  MODEL_API_URL = "https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct"
16
  HF_TOKEN = os.getenv("HF_TOKEN") # Make sure to set this environment variable
17
 
18
+ # Define the state type
19
+ StateType = TypeVar("StateType", bound=BaseModel)
20
+
21
  class AgentState(BaseModel):
22
  """Schema for the agent's state."""
23
  question: str = Field(..., description="The original question")
 
153
 
154
  def _create_workflow(self) -> Graph:
155
  """Create the agent workflow using LangGraph."""
156
+ # Create the workflow with explicit input and output types
157
+ workflow = StateGraph(
158
+ input_type=AgentState,
159
+ output_type=AgentState
160
+ )
161
 
162
+ # Add nodes with explicit type casting
163
+ workflow.add_node("analyze", cast(Any, self._analyze_question))
164
+ workflow.add_node("calculator", cast(Any, self._use_calculator))
165
+ workflow.add_node("search", cast(Any, self._use_search))
166
+ workflow.add_node("final_answer", cast(Any, self._generate_final_answer))
167
 
168
  # Define edges
169
  workflow.add_edge("analyze", "calculator")