Spaces:
Sleeping
Sleeping
EtienneB
commited on
Commit
·
8ca5d55
1
Parent(s):
9a1c353
updated tools and agent
Browse files- __pycache__/tools.cpython-313.pyc +0 -0
- agent.py +5 -3
- tools.py +86 -1
__pycache__/tools.cpython-313.pyc
CHANGED
Binary files a/__pycache__/tools.cpython-313.pyc and b/__pycache__/tools.cpython-313.pyc differ
|
|
agent.py
CHANGED
@@ -7,13 +7,14 @@ from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
|
|
7 |
from langgraph.graph import START, MessagesState, StateGraph
|
8 |
from langgraph.prebuilt import ToolNode, tools_condition
|
9 |
|
10 |
-
from tools import (absolute, add,
|
|
|
11 |
divide, exponential, factorial, floor_divide,
|
12 |
get_current_time_in_timezone, greatest_common_divisor,
|
13 |
is_prime, least_common_multiple, logarithm, modulus,
|
14 |
multiply, percentage_calculator, power,
|
15 |
roman_calculator_converter, square_root, subtract,
|
16 |
-
web_search)
|
17 |
|
18 |
# Load Constants
|
19 |
load_dotenv()
|
@@ -26,7 +27,8 @@ tools = [
|
|
26 |
exponential, web_search, roman_calculator_converter,
|
27 |
get_current_time_in_timezone, compound_interest,
|
28 |
convert_temperature, factorial, greatest_common_divisor,
|
29 |
-
is_prime, least_common_multiple, percentage_calculator
|
|
|
30 |
]
|
31 |
|
32 |
def build_graph():
|
|
|
7 |
from langgraph.graph import START, MessagesState, StateGraph
|
8 |
from langgraph.prebuilt import ToolNode, tools_condition
|
9 |
|
10 |
+
from tools import (absolute, add, analyze_excel_file, arvix_search,
|
11 |
+
audio_transcription, compound_interest, convert_temperature,
|
12 |
divide, exponential, factorial, floor_divide,
|
13 |
get_current_time_in_timezone, greatest_common_divisor,
|
14 |
is_prime, least_common_multiple, logarithm, modulus,
|
15 |
multiply, percentage_calculator, power,
|
16 |
roman_calculator_converter, square_root, subtract,
|
17 |
+
web_search, wiki_search)
|
18 |
|
19 |
# Load Constants
|
20 |
load_dotenv()
|
|
|
27 |
exponential, web_search, roman_calculator_converter,
|
28 |
get_current_time_in_timezone, compound_interest,
|
29 |
convert_temperature, factorial, greatest_common_divisor,
|
30 |
+
is_prime, least_common_multiple, percentage_calculator,
|
31 |
+
wiki_search, analyze_excel_file, arvix_search, audio_transcription
|
32 |
]
|
33 |
|
34 |
def build_graph():
|
tools.py
CHANGED
@@ -1,9 +1,14 @@
|
|
1 |
import datetime
|
2 |
import math
|
|
|
3 |
from typing import Union
|
4 |
|
|
|
5 |
import pytz
|
6 |
-
from langchain_community.document_loaders import
|
|
|
|
|
|
|
7 |
from langchain_community.tools import DuckDuckGoSearchRun
|
8 |
from langchain_core.tools import tool
|
9 |
|
@@ -581,3 +586,83 @@ def arvix_search(query: str) -> str:
|
|
581 |
for doc in search_docs
|
582 |
])
|
583 |
return {"arvix_results": formatted_search_docs}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import datetime
|
2 |
import math
|
3 |
+
import os
|
4 |
from typing import Union
|
5 |
|
6 |
+
import pandas
|
7 |
import pytz
|
8 |
+
from langchain_community.document_loaders import (
|
9 |
+
ArxivLoader, AssemblyAIAudioTranscriptLoader, WikipediaLoader)
|
10 |
+
from langchain_community.document_loaders.generic import GenericLoader
|
11 |
+
from langchain_community.document_loaders.parsers import LanguageParser
|
12 |
from langchain_community.tools import DuckDuckGoSearchRun
|
13 |
from langchain_core.tools import tool
|
14 |
|
|
|
586 |
for doc in search_docs
|
587 |
])
|
588 |
return {"arvix_results": formatted_search_docs}
|
589 |
+
|
590 |
+
|
591 |
+
@tool
|
592 |
+
def analyze_excel_file(file_path: str, query: str) -> str:
|
593 |
+
"""
|
594 |
+
Analyze an Excel file using pandas and answer a question about it.
|
595 |
+
Args:
|
596 |
+
file_path (str): the path to the Excel file.
|
597 |
+
query (str): Question about the data
|
598 |
+
"""
|
599 |
+
try:
|
600 |
+
file = pandas.read_excel(file_path)
|
601 |
+
|
602 |
+
result = (
|
603 |
+
f"Excel file loaded with {len(file)} rows and {len(file.columns)} columns.\n"
|
604 |
+
)
|
605 |
+
result += f"Columns: {', '.join(file.columns)}\n\n"
|
606 |
+
|
607 |
+
result += "Summary statistics:\n"
|
608 |
+
result += str(file.describe())
|
609 |
+
|
610 |
+
return result
|
611 |
+
|
612 |
+
except Exception as e:
|
613 |
+
return f"Error analyzing Excel file: {str(e)}"
|
614 |
+
|
615 |
+
|
616 |
+
@tool
|
617 |
+
def python_code_parser(file_path: str) -> str:
|
618 |
+
"""
|
619 |
+
Parse Python code to extract function names and their docstrings.
|
620 |
+
|
621 |
+
Args:
|
622 |
+
file_path: The path to the Python file to parse.
|
623 |
+
|
624 |
+
Returns:
|
625 |
+
Interpreted Python code as a string.
|
626 |
+
"""
|
627 |
+
if not os.path.exists(file_path):
|
628 |
+
return "0"
|
629 |
+
|
630 |
+
|
631 |
+
loader = GenericLoader.from_filesystem(
|
632 |
+
file_path,
|
633 |
+
glob="**/*",
|
634 |
+
suffixes=[".py"],
|
635 |
+
parser=LanguageParser()
|
636 |
+
)
|
637 |
+
search_docs = loader.load()
|
638 |
+
|
639 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
640 |
+
[
|
641 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
642 |
+
for doc in search_docs
|
643 |
+
])
|
644 |
+
|
645 |
+
return {"audio_results": formatted_search_docs}
|
646 |
+
|
647 |
+
|
648 |
+
@tool
|
649 |
+
def audio_transcription(file_path: str) -> str:
|
650 |
+
"""
|
651 |
+
Transcribe an audio file to text using AssemblyAI.
|
652 |
+
|
653 |
+
Args:
|
654 |
+
file_path: The path to the audio file.
|
655 |
+
|
656 |
+
Returns:
|
657 |
+
The transcribed text from the audio file.
|
658 |
+
"""
|
659 |
+
search_docs = AssemblyAIAudioTranscriptLoader(file_path=file_path).load()
|
660 |
+
|
661 |
+
formatted_search_docs = "\n\n---\n\n".join(
|
662 |
+
[
|
663 |
+
f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
|
664 |
+
for doc in search_docs
|
665 |
+
])
|
666 |
+
|
667 |
+
return {"audio_results": formatted_search_docs}
|
668 |
+
|