Added Transcription and Webpage Tools
Browse files- agent_tools.py +37 -0
agent_tools.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
|
|
| 1 |
from langchain_community.document_loaders import TextLoader, PyPDFLoader, Docx2txtLoader, CSVLoader
|
| 2 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 3 |
from langchain_community.retrievers import BM25Retriever
|
|
|
|
|
|
|
| 4 |
|
| 5 |
@tool
|
| 6 |
def addition_tool(a:float, b:float)->float:
|
|
@@ -110,3 +113,37 @@ class RagTool(Tool):
|
|
| 110 |
retriever = BM25Retriever.from_documents(docs)
|
| 111 |
results = retriever.get_relevant_documents(query)
|
| 112 |
return "\n\n".join([doc.page_content for doc in results[:3]]) if results else "No matching information found"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from bs4 import BeautifulSoup
|
| 2 |
from langchain_community.document_loaders import TextLoader, PyPDFLoader, Docx2txtLoader, CSVLoader
|
| 3 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 4 |
from langchain_community.retrievers import BM25Retriever
|
| 5 |
+
import requests
|
| 6 |
+
import whisper
|
| 7 |
|
| 8 |
@tool
|
| 9 |
def addition_tool(a:float, b:float)->float:
|
|
|
|
| 113 |
retriever = BM25Retriever.from_documents(docs)
|
| 114 |
results = retriever.get_relevant_documents(query)
|
| 115 |
return "\n\n".join([doc.page_content for doc in results[:3]]) if results else "No matching information found"
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# WebPage Tool
|
| 119 |
+
@tool
|
| 120 |
+
def visit_webpage_tool(url:str)->str:
|
| 121 |
+
"""
|
| 122 |
+
Takes a url of webpage and returns its content.
|
| 123 |
+
Args:
|
| 124 |
+
url: The url of the webpage.
|
| 125 |
+
"""
|
| 126 |
+
try:
|
| 127 |
+
# Make a GET request to fetch the raw HTML content
|
| 128 |
+
html_content = requests.get(url).text
|
| 129 |
+
|
| 130 |
+
# Parse the html content
|
| 131 |
+
soup = BeautifulSoup(html_content, 'html')
|
| 132 |
+
return soup.text # print the parsed data of html
|
| 133 |
+
except:
|
| 134 |
+
return "Could not get information from webpage"
|
| 135 |
+
|
| 136 |
+
@tool
|
| 137 |
+
def transcriber_tool(file_path:str)->str:
|
| 138 |
+
"""
|
| 139 |
+
Takes the file path of an audio file and returns the transcribed text
|
| 140 |
+
Args:
|
| 141 |
+
file_path: File path of audio file
|
| 142 |
+
"""
|
| 143 |
+
model = whisper.load_model("base") # You can try "small" or "medium" for better accuracy
|
| 144 |
+
|
| 145 |
+
# Transcribe the audio
|
| 146 |
+
result = model.transcribe(file_path)["text"]
|
| 147 |
+
|
| 148 |
+
# Print the text
|
| 149 |
+
return f"The result of the transcription is: {result}"
|