Scott Cogan commited on
Commit
5f1fcc8
·
1 Parent(s): 281911e

requirements update for llm compat

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -5,7 +5,7 @@ import inspect
5
  import pandas as pd
6
  import asyncio
7
  from langchain_google_genai import ChatGoogleGenerativeAI
8
- from typing import IO, Dict, TypedDict, Annotated, Sequence
9
  from io import BytesIO
10
  from langchain_core.messages import HumanMessage, SystemMessage, BaseMessage, AIMessage
11
  from langgraph.graph import StateGraph, END
@@ -13,7 +13,6 @@ import base64
13
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
14
  import google.generativeai as genai
15
  import operator
16
- from langgraph.prebuilt.tool_node import ToolNode
17
  from langchain_core.tools import tool
18
  from utilities import get_file
19
  import time
@@ -36,6 +35,13 @@ class AgentState(TypedDict):
36
  messages: Annotated[Sequence[BaseMessage], operator.add]
37
  next: str
38
 
 
 
 
 
 
 
 
39
  # Convert existing functions to tools
40
  @tool
41
  def analyse_excel(task_id: str) -> Dict[str, float]:
@@ -221,11 +227,16 @@ class BasicAgent:
221
  )
222
 
223
  # Create tool executor
224
- self.tools = [
225
- get_file, analyse_excel, add_numbers, transcribe_audio,
226
- python_code, open_image, open_youtube_video, google_search
227
- ]
228
- self.tool_node = ToolNode(self.tools)
 
 
 
 
 
229
 
230
  # System message
231
  self.sys_msg = SystemMessage('''You are a general AI assistant. I will ask you a question. Follow these steps:
@@ -435,7 +446,7 @@ class BasicAgent:
435
  logger.info(f"Executing tool: {tool_name}")
436
  logger.info(f"Tool arguments: {json.dumps(tool_args, indent=2)}")
437
 
438
- result = self.tool_node.invoke({"name": tool_name, "args": tool_args})
439
  logger.info(f"Tool result: {result}")
440
 
441
  messages.append(AIMessage(content=f"Tool result: {result}"))
 
5
  import pandas as pd
6
  import asyncio
7
  from langchain_google_genai import ChatGoogleGenerativeAI
8
+ from typing import IO, Dict, TypedDict, Annotated, Sequence, Any, Callable
9
  from io import BytesIO
10
  from langchain_core.messages import HumanMessage, SystemMessage, BaseMessage, AIMessage
11
  from langgraph.graph import StateGraph, END
 
13
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
14
  import google.generativeai as genai
15
  import operator
 
16
  from langchain_core.tools import tool
17
  from utilities import get_file
18
  import time
 
35
  messages: Annotated[Sequence[BaseMessage], operator.add]
36
  next: str
37
 
38
+ # Tool execution function
39
+ def execute_tool(tool_name: str, tool_args: Dict[str, Any], tools: Dict[str, Callable]) -> Any:
40
+ """Execute a tool with the given arguments."""
41
+ if tool_name not in tools:
42
+ raise ValueError(f"Tool {tool_name} not found")
43
+ return tools[tool_name](**tool_args)
44
+
45
  # Convert existing functions to tools
46
  @tool
47
  def analyse_excel(task_id: str) -> Dict[str, float]:
 
227
  )
228
 
229
  # Create tool executor
230
+ self.tools = {
231
+ "get_file": get_file,
232
+ "analyse_excel": analyse_excel,
233
+ "add_numbers": add_numbers,
234
+ "transcribe_audio": transcribe_audio,
235
+ "python_code": python_code,
236
+ "open_image": open_image,
237
+ "open_youtube_video": open_youtube_video,
238
+ "google_search": google_search
239
+ }
240
 
241
  # System message
242
  self.sys_msg = SystemMessage('''You are a general AI assistant. I will ask you a question. Follow these steps:
 
446
  logger.info(f"Executing tool: {tool_name}")
447
  logger.info(f"Tool arguments: {json.dumps(tool_args, indent=2)}")
448
 
449
+ result = execute_tool(tool_name, tool_args, self.tools)
450
  logger.info(f"Tool result: {result}")
451
 
452
  messages.append(AIMessage(content=f"Tool result: {result}"))