EtienneB commited on
Commit
0a05d57
·
1 Parent(s): 9a75fd8

updated tools and requirements

Browse files
Files changed (3) hide show
  1. agent.py +8 -14
  2. requirements.txt +1 -0
  3. tools.py +8 -13
agent.py CHANGED
@@ -8,10 +8,10 @@ from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
8
  from langgraph.graph import START, MessagesState, StateGraph
9
  from langgraph.prebuilt import ToolNode, tools_condition
10
 
11
- from tools import (absolute, add, analyze_csv_file, # extract_text_from_image,
12
- analyze_excel_file, arxiv_search, audio_transcription,
13
- compound_interest, convert_temperature, divide,
14
- download_file, exponential, factorial, floor_divide,
15
  get_current_time_in_timezone, greatest_common_divisor,
16
  is_prime, least_common_multiple, logarithm, modulus,
17
  multiply, percentage_calculator, power, python_code_parser,
@@ -32,7 +32,7 @@ tools = [
32
  is_prime, least_common_multiple, percentage_calculator,
33
  wikipedia_search, analyze_excel_file, arxiv_search,
34
  audio_transcription, python_code_parser, analyze_csv_file,
35
- # extract_text_from_image,
36
  reverse_sentence, web_content_extract,
37
  download_file,
38
  ]
@@ -73,13 +73,7 @@ You are an advanced AI agent equipped with multiple tools to solve complex, mult
73
  - **Plan multi-tool sequences** - many questions require 2-5 tools in various combinations
74
  - **Consider tool order flexibility** - tools can be used in any sequence that makes logical sense
75
  - **Validate tool choice** - ensure the selected tool is the optimal match for your needs
76
- - Examples of multi-tool workflows:
77
- - reserve_sentence -> read the reversed question and answer it.
78
- - download_file -> analyze_csv_file -> add -> percentage_calculator
79
- - reverse_sentence -> python_code_parser -> web_search -> extract_text_from_image
80
- - arvix_search -> web_content_extract -> factorial -> roman_calculator_converter
81
- - audio_transcription -> wikipedia_search -> compound_interest -> convert_temperature
82
-
83
  4. **Multi-Step Problem Solving**: For complex questions:
84
  - Break down the problem into logical steps
85
  - Execute each step systematically, including any text transformations
@@ -113,7 +107,7 @@ You are an advanced AI agent equipped with multiple tools to solve complex, mult
113
  - **download_file**: Download files from URLs or attachments
114
  - **analyze_csv_file**: Analyze CSV file data
115
  - **analyze_excel_file**: Analyze Excel file data
116
- - **extract_text_from_image**: Extract text from image files
117
  - **audio_transcription**: Transcribe audio files to text
118
 
119
  ### Text Processing
@@ -137,7 +131,7 @@ You are an advanced AI agent equipped with multiple tools to solve complex, mult
137
  - **Sequential Processing**: Use outputs from one tool as inputs for another when necessary
138
  - **File Processing Priority**: Always download and process files before attempting to answer questions about them
139
  - **Mathematical Chains**: Combine mathematical operations as needed (e.g., add -> multiply -> percentage_calculator)
140
- - **Information + Processing**: Combine search tools with processing tools (e.g., web_search -> extract_text_from_image -> analyze_csv_file)
141
  - **Text Transformations**: Use text processing tools before analysis (e.g., reverse_sentence -> python_code_parser). In other words, first reverse the text when needed and then re-read the adjusted question.
142
  - **Pattern Recognition**: Look for hidden patterns, instructions, or transformations within questions
143
 
 
8
  from langgraph.graph import START, MessagesState, StateGraph
9
  from langgraph.prebuilt import ToolNode, tools_condition
10
 
11
+ from tools import (absolute, add, analyze_csv_file, analyze_excel_file,
12
+ arxiv_search, audio_transcription, compound_interest,
13
+ convert_temperature, divide, download_file, exponential,
14
+ extract_text, factorial, floor_divide,
15
  get_current_time_in_timezone, greatest_common_divisor,
16
  is_prime, least_common_multiple, logarithm, modulus,
17
  multiply, percentage_calculator, power, python_code_parser,
 
32
  is_prime, least_common_multiple, percentage_calculator,
33
  wikipedia_search, analyze_excel_file, arxiv_search,
34
  audio_transcription, python_code_parser, analyze_csv_file,
35
+ extract_text,
36
  reverse_sentence, web_content_extract,
37
  download_file,
38
  ]
 
73
  - **Plan multi-tool sequences** - many questions require 2-5 tools in various combinations
74
  - **Consider tool order flexibility** - tools can be used in any sequence that makes logical sense
75
  - **Validate tool choice** - ensure the selected tool is the optimal match for your needs
76
+
 
 
 
 
 
 
77
  4. **Multi-Step Problem Solving**: For complex questions:
78
  - Break down the problem into logical steps
79
  - Execute each step systematically, including any text transformations
 
107
  - **download_file**: Download files from URLs or attachments
108
  - **analyze_csv_file**: Analyze CSV file data
109
  - **analyze_excel_file**: Analyze Excel file data
110
+ - **extract_text**: Extract text from image files
111
  - **audio_transcription**: Transcribe audio files to text
112
 
113
  ### Text Processing
 
131
  - **Sequential Processing**: Use outputs from one tool as inputs for another when necessary
132
  - **File Processing Priority**: Always download and process files before attempting to answer questions about them
133
  - **Mathematical Chains**: Combine mathematical operations as needed (e.g., add -> multiply -> percentage_calculator)
134
+ - **Information + Processing**: Combine search tools with processing tools (e.g., web_search -> extract_text -> analyze_csv_file)
135
  - **Text Transformations**: Use text processing tools before analysis (e.g., reverse_sentence -> python_code_parser). In other words, first reverse the text when needed and then re-read the adjusted question.
136
  - **Pattern Recognition**: Look for hidden patterns, instructions, or transformations within questions
137
 
requirements.txt CHANGED
@@ -14,6 +14,7 @@ langchain-huggingface
14
  langfuse
15
  langchain-google-genai
16
  langchain-tavily
 
17
 
18
  # Hugging Face integration
19
  huggingface_hub
 
14
  langfuse
15
  langchain-google-genai
16
  langchain-tavily
17
+ langchain-openai
18
 
19
  # Hugging Face integration
20
  huggingface_hub
tools.py CHANGED
@@ -19,6 +19,7 @@ from langchain_core.messages import HumanMessage
19
  # from langchain_community.tools import DuckDuckGoSearchRun
20
  from langchain_core.tools import tool
21
  from langchain_google_genai import ChatGoogleGenerativeAI
 
22
  from langchain_tavily import TavilySearch
23
 
24
 
@@ -744,24 +745,18 @@ def analyze_csv_file(file_path: str, query: str) -> str:
744
  except Exception as e:
745
  return f"Error analyzing CSV file: {str(e)}"
746
 
747
- '''
748
- # Extract Text Tool
749
- vision_llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",temperature=0)
750
 
751
  @tool
752
- def extract_text_from_image(img_path: str) -> str:
753
  """
754
  Extract text from an image file using a multimodal model.
755
-
756
- Args:
757
- img_path: A local image file path (strings).
758
-
759
- Returns:
760
- A single string containing the concatenated text extracted from each image.
761
  """
762
  all_text = ""
763
  try:
764
-
765
  # Read image and encode as base64
766
  with open(img_path, "rb") as image_file:
767
  image_bytes = image_file.read()
@@ -797,11 +792,11 @@ def extract_text_from_image(img_path: str) -> str:
797
 
798
  return all_text.strip()
799
  except Exception as e:
800
- # You can choose whether to raise or just return an empty string / error message
801
  error_msg = f"Error extracting text: {str(e)}"
802
  print(error_msg)
803
  return ""
804
- '''
805
 
806
  @tool
807
  def reverse_sentence(text: str) -> str:
 
19
  # from langchain_community.tools import DuckDuckGoSearchRun
20
  from langchain_core.tools import tool
21
  from langchain_google_genai import ChatGoogleGenerativeAI
22
+ from langchain_openai import ChatOpenAI
23
  from langchain_tavily import TavilySearch
24
 
25
 
 
745
  except Exception as e:
746
  return f"Error analyzing CSV file: {str(e)}"
747
 
748
+
749
+ vision_llm = ChatOpenAI(model="gpt-4o")
 
750
 
751
  @tool
752
+ def extract_text(img_path: str) -> str:
753
  """
754
  Extract text from an image file using a multimodal model.
755
+
756
+ This allows me to properly analyze the contents.
 
 
 
 
757
  """
758
  all_text = ""
759
  try:
 
760
  # Read image and encode as base64
761
  with open(img_path, "rb") as image_file:
762
  image_bytes = image_file.read()
 
792
 
793
  return all_text.strip()
794
  except Exception as e:
795
+ # A butler should handle errors gracefully
796
  error_msg = f"Error extracting text: {str(e)}"
797
  print(error_msg)
798
  return ""
799
+
800
 
801
  @tool
802
  def reverse_sentence(text: str) -> str: