{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "64b2c237", "metadata": {}, "outputs": [], "source": [ "import os\n", "from langchain_openai import ChatOpenAI\n", "from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace\n", "\n", "import sys\n", "\n", "sys.path.append(os.path.abspath(\"../src\"))\n", "\n", "from agent import SmartAgent" ] }, { "cell_type": "code", "execution_count": 2, "id": "8a1ece26", "metadata": {}, "outputs": [], "source": [ "HUGGINGFACEHUB_API_TOKEN = os.getenv(\"HUGGINGFACEHUB_API_TOKEN\")\n", "OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n", "TAVILY_API_KEY = os.getenv(\"TAVILY_API_KEY\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "1d5bd941", "metadata": {}, "outputs": [], "source": [ "MODEL_ID = \"gpt-4o\"\n", "PROVIDER_TYPE = \"openai\" # \"openai\" or \"huggingface\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "711e347b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent initialized.\n", "Telemetry initialized.\n" ] } ], "source": [ "# Instantiate Agent\n", "try:\n", " if PROVIDER_TYPE == \"huggingface\":\n", " llm = HuggingFaceEndpoint(\n", " repo_id=MODEL_ID,\n", " huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,\n", " )\n", " chat = ChatHuggingFace(llm=llm, verbose=True)\n", " elif PROVIDER_TYPE == \"openai\":\n", " chat = ChatOpenAI(model=MODEL_ID, temperature=0.2)\n", " else:\n", " print(f\"Provider {PROVIDER_TYPE} not supported.\")\n", "\n", " agent = SmartAgent(chat)\n", "\n", "except Exception as e:\n", " print(f\"Error instantiating agent: {e}\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "57656b10", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent received question: The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places..\n", "Provided file: ../data/sales.xlsx.\n", "Agent returning answer: 29623.00\n" ] } ], "source": [ "# Run Agent\n", "\n", "question = \"The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places.\"\n", "filename = \"../data/sales.xlsx\"\n", "answer = agent(question, filename)" ] }, { "cell_type": "code", "execution_count": 6, "id": "0f82fc20", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent received question: Here is a scanned invoice. Please extract the vendor name, invoice number, and total amount..\n", "Provided file: ../data/invoice.png.\n", "Agent returning answer: Adeline Palmerston, 01234, 440\n" ] } ], "source": [ "# Run Agent\n", "\n", "question = \"Here is a scanned invoice. Please extract the vendor name, invoice number, and total amount.\"\n", "filename = \"../data/invoice.png\"\n", "answer = agent(question, filename)" ] }, { "cell_type": "code", "execution_count": 11, "id": "833cb42b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent received question: Explain in detail what the conclusion of the paper Attention is all you need.\n", "Agent returning answer: The conclusion of the paper \"Attention is All You Need\" is that the Transformer model, which relies entirely on attention mechanisms and does not use recurrence or convolution, achieves state-of-the-art results on translation tasks and is highly efficient in terms of parallelization, making it suitable for training on large datasets. The paper demonstrates that attention mechanisms alone are sufficient for achieving high performance in sequence transduction tasks.\n" ] } ], "source": [ "# Run Agent\n", "\n", "question = (\n", " \"Explain in detail what the conclusion of the paper Attention is all you need\"\n", ")\n", "answer = agent(question)" ] }, { "cell_type": "code", "execution_count": 8, "id": "9077c2b0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Agent received question: Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal say in response to the question Isn't that hot?.\n", " \r" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/giulia/Progetti/Agent_Course_Final_Assignment/.venv/lib/python3.10/site-packages/whisper/transcribe.py:126: UserWarning: FP16 is not supported on CPU; using FP32 instead\n", " warnings.warn(\"FP16 is not supported on CPU; using FP32 instead\")\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Agent returning answer: Extremely\n" ] } ], "source": [ "# Run Agent\n", "\n", "question = \"Examine the video at https://www.youtube.com/watch?v=1htKBjuUWec. What does Teal say in response to the question Isn't that hot?\"\n", "answer = agent(question)" ] }, { "cell_type": "code", "execution_count": null, "id": "7ee42f12", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }