Commit ·
df6c855
1
Parent(s): 10c9801
Fix tools bugs
Browse filesFiles changed (3)
- requirements.txt+11
- tools.py+56-3
- utils.py+1-4
123456789101112131415164 unmodified lines2122232425263 unmodified lines3031323334353637383940414243444515 unmodified lines616263646566aiofiles==24.1.0 ; python_version >= '3.8'annotated-types==0.7.0 ; python_version >= '3.8'anyio==4.9.0 ; python_version >= '3.9'boto3==1.38.23botocore==1.38.23 ; python_version >= '3.9'certifi==2025.4.26 ; python_version >= '3.6'charset-normalizer==3.4.2 ; python_version >= '3.7'click==8.2.1 ; python_version >= '3.10'et-xmlfile==2.0.0 ; python_version >= '3.8'fastapi==0.115.12 ; python_version >= '3.8'ffmpy==0.5.0 ; python_version >= '3.8' and python_version < '4.0'filelock==3.18.0 ; python_version >= '3.9'fsspec==2025.5.1 ; python_version >= '3.9'gradio==5.31.0gradio-client==1.10.1 ; python_version >= '3.10'groovy==0.1.2 ; python_version >= '3.10'4 unmodified lineshuggingface-hub==0.32.1 ; python_full_version >= '3.8.0'idna==3.10 ; python_version >= '3.6'jinja2==3.1.6 ; python_version >= '3.7'jmespath==1.0.1 ; python_version >= '3.7'jsonpatch==1.33 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'jsonpointer==3.0.0 ; python_version >= '3.7'3 unmodified lineslanggraph-prebuilt==0.2.1 ; python_version >= '3.9'langgraph-sdk==0.1.70 ; python_version >= '3.9'langsmith==0.3.42 ; python_version >= '3.9'markdown-it-py==3.0.0 ; python_version >= '3.8'markupsafe==3.0.2 ; python_version >= '3.9'mdurl==0.1.2 ; python_version >= '3.7'numpy==2.2.6 ; python_version >= '3.10'openpyxl==3.1.5orjson==3.10.18 ; python_version >= '3.9'ormsgpack==1.10.0 ; python_version >= '3.9'packaging==24.2 ; python_version >= '3.8'pandas==2.2.3 ; python_version >= '3.9'pillow==11.2.1 ; python_version >= '3.9'pydantic==2.11.5 ; python_version >= '3.9'pydantic-core==2.33.2 ; python_version >= '3.9'pydub==0.25.115 unmodified linessix==1.17.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'smolagents==1.16.1sniffio==1.3.1 ; python_version >= '3.7'starlette==0.46.2 ; sys_platform != 'emscripten'tenacity==9.1.2 ; python_version >= '3.9'tomlkit==0.13.2 ; python_version >= '3.8'1234567891011121314151617181920214 unmodified lines262728293031323 unmodified lines363738394041424344454647484950515253545515 unmodified lines71727374757677-i https://pypi.org/simpleaiofiles==24.1.0 ; python_version >= '3.8'annotated-types==0.7.0 ; python_version >= '3.8'anyio==4.9.0 ; python_version >= '3.9'beautifulsoup4==4.13.4 ; python_full_version >= '3.7.0'boto3==1.38.23botocore==1.38.23 ; python_version >= '3.9'certifi==2025.4.26 ; python_version >= '3.6'charset-normalizer==3.4.2 ; python_version >= '3.7'click==8.2.1 ; python_version >= '3.10'distro==1.9.0 ; python_version >= '3.6'duckduckgo-search==8.0.2et-xmlfile==2.0.0 ; python_version >= '3.8'fastapi==0.115.12 ; python_version >= '3.8'ffmpy==0.5.0 ; python_version >= '3.8' and python_version < '4.0'filelock==3.18.0 ; python_version >= '3.9'fsspec==2025.5.1 ; python_version >= '3.9'googlesearch-python==1.3.0gradio==5.31.0gradio-client==1.10.1 ; python_version >= '3.10'groovy==0.1.2 ; python_version >= '3.10'4 unmodified lineshuggingface-hub==0.32.1 ; python_full_version >= '3.8.0'idna==3.10 ; python_version >= '3.6'jinja2==3.1.6 ; python_version >= '3.7'jiter==0.10.0 ; python_version >= '3.9'jmespath==1.0.1 ; python_version >= '3.7'jsonpatch==1.33 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'jsonpointer==3.0.0 ; python_version >= '3.7'3 unmodified lineslanggraph-prebuilt==0.2.1 ; python_version >= '3.9'langgraph-sdk==0.1.70 ; python_version >= '3.9'langsmith==0.3.42 ; python_version >= '3.9'lxml==5.4.0 ; python_version >= '3.6'markdown-it-py==3.0.0 ; python_version >= '3.8'markdownify==1.1.0markupsafe==3.0.2 ; python_version >= '3.9'mdurl==0.1.2 ; python_version >= '3.7'numpy==2.2.6 ; python_version >= '3.10'openai==1.82.0openpyxl==3.1.5orjson==3.10.18 ; python_version >= '3.9'ormsgpack==1.10.0 ; python_version >= '3.9'packaging==24.2 ; python_version >= '3.8'pandas==2.2.3 ; python_version >= '3.9'pillow==11.2.1 ; python_version >= '3.9'primp==0.15.0 ; python_version >= '3.8'pydantic==2.11.5 ; python_version >= '3.9'pydantic-core==2.33.2 ; python_version >= '3.9'pydub==0.25.115 unmodified linessix==1.17.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'smolagents==1.16.1sniffio==1.3.1 ; python_version >= '3.7'soupsieve==2.7 ; python_version >= '3.8'starlette==0.46.2 ; sys_platform != 'emscripten'tenacity==9.1.2 ; python_version >= '3.9'tomlkit==0.13.2 ; python_version >= '3.8'
7 unmodified lines8910111213141529 unmodified lines4546474849508 unmodified lines59606162636426 unmodified lines91929394959654 unmodified lines15115215315415515615718 unmodified lines1761771781791801811827 unmodified linesimport boto3import fitzfrom pandas import read_excelfrom smolagents import tool, Toolfrom definitions import TranscriptionJobfrom utils import get_file, s3_upload_file, s3_download_file, bedrock_runtime, BEDROCK_MODEL_ID29 unmodified linesreturn f"Error reading Excel file {file_name}: {e}"def txt_reader(task_id: str, file_name: str) -> str:"""Reads a text file and returns its content as a string.8 unmodified linesreturn f"Error reading file {file_name}: {e}"def pdf_reader(task_id: str, file_name: str) -> str:"""Reads a PDF file and returns its content as a string.26 unmodified lines"description": "The name of the audio file to transcribe.",},}def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)54 unmodified lines"""try:file_content = get_file(task_id)base64_image = base64.b64encode(file_content).decode("utf-8")response = bedrock_runtime.invoke_model(modelId=BEDROCK_MODEL_ID,body=json.dumps(18 unmodified lines],}),).read()return json.loads(response)["message"]["content"][0]["text"]except Exception as e:return f"Error processing image file {file_name}: {e}"7 unmodified lines89101112131415161718192029 unmodified lines505152535455568 unmodified lines6566676869707126 unmodified lines989910010110210310454 unmodified lines15916016116216316416518 unmodified lines1841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342357 unmodified linesimport boto3import fitzimport requestsfrom bs4 import BeautifulSoupfrom googlesearch import searchfrom pandas import read_excelfrom smolagents import tool, Toolfrom requests.exceptions import HTTPErrorfrom urllib3.exceptions import ReadTimeoutErrorfrom definitions import TranscriptionJobfrom utils import get_file, s3_upload_file, s3_download_file, bedrock_runtime, BEDROCK_MODEL_ID29 unmodified linesreturn f"Error reading Excel file {file_name}: {e}"@tooldef txt_reader(task_id: str, file_name: str) -> str:"""Reads a text file and returns its content as a string.8 unmodified linesreturn f"Error reading file {file_name}: {e}"@tooldef pdf_reader(task_id: str, file_name: str) -> str:"""Reads a PDF file and returns its content as a string.26 unmodified lines"description": "The name of the audio file to transcribe.",},}output_type = "string"def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)54 unmodified lines"""try:file_content = get_file(task_id)base64_image = base64.b64encode(file_content.getvalue()).decode("utf-8")response = bedrock_runtime.invoke_model(modelId=BEDROCK_MODEL_ID,body=json.dumps(18 unmodified lines],}),)["body"].read()return json.loads(response)["content"][0]["text"]except Exception as e:return f"Error processing image file {file_name}: {e}"def _get_content(url: str, timeout: int = 5) -> bytes:resp = requests.get(url=url, timeout=timeout)resp.raise_for_status()return resp.contentdef _js_disable_message(text: str) -> bool:return "JavaScript is disabled in this browser" in text@tooldef search_engine(search_term: str) -> str:"""Search for the provided search term in Google SearchArgs:search_term (str): The term to search for on the web."""results = search(search_term, num_results=5)for idx, url in enumerate(results, 1):error_ocurred = Falsetry:html_content = BeautifulSoup(_get_content(url), "html.parser")# Remove headers and footersfor tag in html_content.find_all(["header", "footer", "nav", "aside"]):tag.decompose()except (ReadTimeoutError, HTTPError) as ex:print("Got HTTP error when requesting %s. Error %s", url, ex)error_ocurred = Truehtml_text = html_content.textif _js_disable_message(html_text):error_ocurred = Trueif error_ocurred:# if the last URL is not successfully requested, return a direct response as if it was the final answerif len(results) == idx:return "Sorry, got an HTTP error when requesting the internet"# if there are more URLs to request, continuecontinuereturn html_text.replace("\n", "")return "Could not retrieve any content from the search results."
2 unmodified lines345678910111213142 unmodified linesimport boto3import requestsfrom dotenv import load_dotenvDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"BEDROCK_MODEL_ID = "anthropic.claude-3-5-sonnet-20241022-v2:0"load_dotenv()bedrock_runtime = boto3.client("bedrock-runtime", region_name=os.getenv("AWS_REGION"))2 unmodified lines345678910112 unmodified linesimport boto3import requestsDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"BEDROCK_MODEL_ID = "anthropic.claude-3-5-sonnet-20240620-v1:0"bedrock_runtime = boto3.client("bedrock-runtime", region_name=os.getenv("AWS_REGION"))
requirements.txt+11
tools.py+56-3
utils.py+1-4