MatteoFalcioni commited on
Commit ·
2bd0bca
1
Parent(s): a26c2f1
changing tools
Browse files- __pycache__/tools.cpython-310.pyc +0 -0
- requirements.txt +2 -2
- tools.py +44 -14
__pycache__/tools.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/tools.cpython-310.pyc and b/__pycache__/tools.cpython-310.pyc differ
|
|
|
requirements.txt
CHANGED
|
@@ -3,5 +3,5 @@ requests
|
|
| 3 |
langgraph
|
| 4 |
langchain_openai
|
| 5 |
langchain-tavily
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 3 |
langgraph
|
| 4 |
langchain_openai
|
| 5 |
langchain-tavily
|
| 6 |
+
markdownify
|
| 7 |
+
re
|
tools.py
CHANGED
|
@@ -1,28 +1,57 @@
|
|
| 1 |
from langchain_core.tools import tool
|
| 2 |
-
import math
|
| 3 |
import pandas as pd
|
| 4 |
import requests
|
| 5 |
import io
|
| 6 |
from langchain_tavily import TavilySearch
|
| 7 |
from langchain.tools import tool
|
| 8 |
-
import yt_dlp
|
| 9 |
-
import whisper
|
| 10 |
import os
|
| 11 |
-
import
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
@tool
|
| 15 |
-
def
|
| 16 |
-
"""
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
"""
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
except Exception as e:
|
| 25 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
@tool
|
|
@@ -60,9 +89,10 @@ tavily_search_tool = TavilySearch(
|
|
| 60 |
|
| 61 |
# Export the tools in a list
|
| 62 |
TOOLS = [
|
| 63 |
-
compute_expression,
|
| 64 |
describe_table_from_url,
|
| 65 |
-
tavily_search_tool
|
|
|
|
|
|
|
| 66 |
]
|
| 67 |
|
| 68 |
|
|
|
|
| 1 |
from langchain_core.tools import tool
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
import io
|
| 5 |
from langchain_tavily import TavilySearch
|
| 6 |
from langchain.tools import tool
|
|
|
|
|
|
|
| 7 |
import os
|
| 8 |
+
from markdownify import markdownify
|
| 9 |
+
from requests.exceptions import RequestException
|
| 10 |
+
import re
|
| 11 |
+
from langchain_community.document_loaders import YoutubeLoader
|
| 12 |
|
| 13 |
|
| 14 |
@tool
|
| 15 |
+
def visit_webpage(url: str) -> str:
|
| 16 |
+
"""Visits a webpage at the given URL and returns its content as a markdown string.
|
| 17 |
+
Args:
|
| 18 |
+
url: The URL of the webpage to visit.
|
| 19 |
+
Returns:
|
| 20 |
+
The content of the webpage converted to Markdown, or an error message if the request fails.
|
| 21 |
"""
|
| 22 |
try:
|
| 23 |
+
# Send a GET request to the URL
|
| 24 |
+
response = requests.get(url)
|
| 25 |
+
response.raise_for_status() # Raise an exception for bad status codes
|
| 26 |
+
|
| 27 |
+
# Convert the HTML content to Markdown
|
| 28 |
+
markdown_content = markdownify(response.text).strip()
|
| 29 |
+
|
| 30 |
+
# Remove multiple line breaks
|
| 31 |
+
markdown_content = re.sub(r"\n{3,}", "\n\n", markdown_content)
|
| 32 |
+
|
| 33 |
+
return markdown_content
|
| 34 |
+
|
| 35 |
+
except RequestException as e:
|
| 36 |
+
return f"Error fetching the webpage: {str(e)}"
|
| 37 |
except Exception as e:
|
| 38 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
@tool
|
| 42 |
+
def youtube_transcription_tool(url: str) -> str:
|
| 43 |
+
"""
|
| 44 |
+
This tool returns transcript of the youtube video.
|
| 45 |
+
Args:
|
| 46 |
+
url: youtube video url
|
| 47 |
+
"""
|
| 48 |
+
# Example list of catering services and their ratings
|
| 49 |
+
loader = YoutubeLoader.from_youtube_url(
|
| 50 |
+
url, add_video_info=False
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
return loader.load()[0].page_content
|
| 55 |
|
| 56 |
|
| 57 |
@tool
|
|
|
|
| 89 |
|
| 90 |
# Export the tools in a list
|
| 91 |
TOOLS = [
|
|
|
|
| 92 |
describe_table_from_url,
|
| 93 |
+
tavily_search_tool,
|
| 94 |
+
visit_webpage,
|
| 95 |
+
youtube_transcription_tool
|
| 96 |
]
|
| 97 |
|
| 98 |
|