From 718979e89a8069c0ac372bf29e48f2d8f532eecb Mon Sep 17 00:00:00 2001 From: Aymeric Date: Thu, 26 Sep 2024 11:37:25 +0200 Subject: [PATCH] Adapt agent notebooks to new transformers release --- notebooks/en/agent_change_llm.ipynb | 12 +- notebooks/en/agent_rag.ipynb | 350 ++----------- notebooks/en/agent_text_to_sql.ipynb | 429 +++++++++++++--- notebooks/en/agents.ipynb | 345 ++++--------- notebooks/en/multiagent_web_assistant.ipynb | 524 ++++---------------- 5 files changed, 587 insertions(+), 1073 deletions(-) diff --git a/notebooks/en/agent_change_llm.ipynb b/notebooks/en/agent_change_llm.ipynb index 0516bb3a..ecd75e64 100644 --- a/notebooks/en/agent_change_llm.ipynb +++ b/notebooks/en/agent_change_llm.ipynb @@ -29,7 +29,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -q openai anthropic" + "!pip install openai anthropic \"transformers[agents]\" --upgrade -q" ] }, { @@ -104,12 +104,12 @@ } ], "source": [ - "from transformers.agents import HfEngine, ReactCodeAgent\n", + "from transformers.agents import HfApiEngine, ReactCodeAgent\n", "\n", - "repo_id = \"meta-llama/Meta-Llama-3-8B-Instruct\"\n", + "repo_id = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"\n", "endpoint_url = \"your_endpoint_url\"\n", "\n", - "llm_engine = HfEngine(model=repo_id) # you could use model=endpoint_url here\n", + "llm_engine = HfApiEngine(model=repo_id) # you could use model=endpoint_url here\n", "\n", "agent = ReactCodeAgent(tools=[], llm_engine=llm_engine)\n", "\n", @@ -147,8 +147,8 @@ "}\n", "\n", "\n", - "class HfEngine:\n", - " def __init__(self, model: str = \"meta-llama/Meta-Llama-3-8B-Instruct\"):\n", + "class HfApiEngine:\n", + " def __init__(self, model: str = \"meta-llama/Meta-Llama-3.1-8B-Instruct\"):\n", " self.model = model\n", " self.client = InferenceClient(model=self.model, timeout=120)\n", "\n", diff --git a/notebooks/en/agent_rag.ipynb b/notebooks/en/agent_rag.ipynb index 4d827cfb..5f6c98fc 100644 --- a/notebooks/en/agent_rag.ipynb +++ b/notebooks/en/agent_rag.ipynb @@ -34,7 +34,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install pandas langchain langchain-community sentence-transformers faiss-cpu \"transformers[agents]\"" + "!pip install pandas langchain langchain-community sentence-transformers faiss-cpu \"transformers[agents]\" --upgrade -q" ] }, { @@ -48,16 +48,7 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/aymeric/Documents/Code/cookbook/.venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "import datasets\n", "\n", @@ -76,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -90,9 +81,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|██████████| 2647/2647 [00:34<00:00, 76.04it/s] \n", - "/Users/aymeric/Documents/Code/cookbook/.venv/lib/python3.12/site-packages/langchain_core/_api/deprecation.py:139: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 0.3.0. An updated version of the class exists in the langchain-huggingface package and should be used instead. To use it run `pip install -U langchain-huggingface` and import as `from langchain_huggingface import HuggingFaceEmbeddings`.\n", - " warn_deprecated(\n" + "100%|██████████| 2647/2647 [00:35<00:00, 74.10it/s] \n", + "/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/ipykernel_19946/2464760906.py:37: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.\n", + " embedding_model = HuggingFaceEmbeddings(model_name=\"thenlper/gte-small\")\n" ] }, { @@ -104,13 +95,13 @@ } ], "source": [ + "from tqdm import tqdm\n", "from transformers import AutoTokenizer\n", "from langchain.docstore.document import Document\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", "from langchain.vectorstores import FAISS\n", "from langchain_community.embeddings import HuggingFaceEmbeddings\n", "from langchain_community.vectorstores.utils import DistanceStrategy\n", - "from tqdm import tqdm\n", "\n", "source_docs = [\n", " Document(page_content=doc[\"text\"], metadata={\"source\": doc[\"source\"].split(\"/\")[1]})\n", @@ -154,12 +145,14 @@ "source": [ "Now the database is ready: let’s build our agentic RAG system!\n", "\n", - "👉 We only need a `RetrieverTool` that our agent can leverage to retrieve information from the knowledge base." + "👉 We only need a `RetrieverTool` that our agent can leverage to retrieve information from the knowledge base.\n", + "\n", + "Since we need to add a vectordb as an attribute of the tool, we cannot simply use the [simple tool constructor](https://huggingface.co/docs/transformers/main/en/agents#create-a-new-tool) with a `@tool` decorator: so we will follow the advanced setup highlighted in the [advanced agents documentation](https://huggingface.co/docs/transformers/main/en/agents_advanced#directly-define-a-tool-by-subclassing-tool-and-share-it-to-the-hub)." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -172,11 +165,11 @@ " description = \"Using semantic similarity, retrieves some documents from the knowledge base that have the closest embeddings to the input query.\"\n", " inputs = {\n", " \"query\": {\n", - " \"type\": \"text\",\n", + " \"type\": \"string\",\n", " \"description\": \"The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question.\",\n", " }\n", " }\n", - " output_type = \"text\"\n", + " output_type = \"string\"\n", "\n", " def __init__(self, vectordb: VectorStore, **kwargs):\n", " super().__init__(**kwargs)\n", @@ -217,13 +210,13 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ - "from transformers.agents import HfEngine, ReactJsonAgent\n", + "from transformers.agents import HfApiEngine, ReactJsonAgent\n", "\n", - "llm_engine = HfEngine(\"CohereForAI/c4ai-command-r-plus\")\n", + "llm_engine = HfApiEngine(\"meta-llama/Llama-3.1-70B-Instruct\")\n", "\n", "retriever_tool = RetrieverTool(vectordb)\n", "agent = ReactJsonAgent(\n", @@ -242,297 +235,15 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 14, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mHow can I push a model to the Hub?\u001b[0m\n", - "\u001b[38;20mSystem prompt is as follows:\u001b[0m\n", - "\u001b[38;20mYou are an expert assistant who can solve any task using JSON tool calls. You will be given a task to solve as best you can.\n", - "To do so, you have been given access to the following tools: 'retriever', 'final_answer'\n", - "The way you use the tools is by specifying a json blob, ending with ''.\n", - "Specifically, this json should have an `action` key (name of the tool to use) and an `action_input` key (input to the tool).\n", - "\n", - "The $ACTION_JSON_BLOB should only contain a SINGLE action, do NOT return a list of multiple actions. It should be formatted in json. Do not try to escape special characters. Here is the template of a valid $ACTION_JSON_BLOB:\n", - "{\n", - " \"action\": $TOOL_NAME,\n", - " \"action_input\": $INPUT\n", - "}\n", - "\n", - "Make sure to have the $INPUT as a dictionary in the right format for the tool you are using, and do not put variable names as input if you can find the right values.\n", - "\n", - "You should ALWAYS use the following format:\n", - "\n", - "Thought: you should always think about one action to take. Then use the action as follows:\n", - "Action:\n", - "$ACTION_JSON_BLOB\n", - "Observation: the result of the action\n", - "... (this Thought/Action/Observation can repeat N times, you should take several steps when needed. The $ACTION_JSON_BLOB must only use a SINGLE action at a time.)\n", - "\n", - "You can use the result of the previous action as input for the next action.\n", - "The observation will always be a string: it can represent a file, like \"image_1.jpg\".\n", - "Then you can use it as input for the next action. You can do it for instance as follows:\n", - "\n", - "Observation: \"image_1.jpg\"\n", - "\n", - "Thought: I need to transform the image that I received in the previous observation to make it green.\n", - "Action:\n", - "{\n", - " \"action\": \"image_transformer\",\n", - " \"action_input\": {\"image\": \"image_1.jpg\"}\n", - "}\n", - "\n", - "To provide the final answer to the task, use an action blob with \"action\": \"final_answer\" tool. It is the only way to complete the task, else you will be stuck on a loop. So your final output should look like this:\n", - "Action:\n", - "{\n", - " \"action\": \"final_answer\",\n", - " \"action_input\": {\"answer\": \"insert your final answer here\"}\n", - "}\n", - "\n", - "\n", - "Here are a few examples using notional tools:\n", - "---\n", - "Task: \"Generate an image of the oldest person in this document.\"\n", - "\n", - "Thought: I will proceed step by step and use the following tools: `document_qa` to find the oldest person in the document, then `image_generator` to generate an image according to the answer.\n", - "Action:\n", - "{\n", - " \"action\": \"document_qa\",\n", - " \"action_input\": {\"document\": \"document.pdf\", \"question\": \"Who is the oldest person mentioned?\"}\n", - "}\n", - "Observation: \"The oldest person in the document is John Doe, a 55 year old lumberjack living in Newfoundland.\"\n", - "\n", - "\n", - "Thought: I will now generate an image showcasing the oldest person.\n", - "Action:\n", - "{\n", - " \"action\": \"image_generator\",\n", - " \"action_input\": {\"text\": \"\"A portrait of John Doe, a 55-year-old man living in Canada.\"\"}\n", - "}\n", - "Observation: \"image.png\"\n", - "\n", - "Thought: I will now return the generated image.\n", - "Action:\n", - "{\n", - " \"action\": \"final_answer\",\n", - " \"action_input\": \"image.png\"\n", - "}\n", - "\n", - "---\n", - "Task: \"What is the result of the following operation: 5 + 3 + 1294.678?\"\n", - "\n", - "Thought: I will use python code evaluator to compute the result of the operation and then return the final answer using the `final_answer` tool\n", - "Action:\n", - "{\n", - " \"action\": \"python_interpreter\",\n", - " \"action_input\": {\"code\": \"5 + 3 + 1294.678\"}\n", - "}\n", - "Observation: 1302.678\n", - "\n", - "Thought: Now that I know the result, I will now return it.\n", - "Action:\n", - "{\n", - " \"action\": \"final_answer\",\n", - " \"action_input\": \"1302.678\"\n", - "}\n", - "\n", - "---\n", - "Task: \"Which city has the highest population , Guangzhou or Shanghai?\"\n", - "\n", - "Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities.\n", - "Action:\n", - "{\n", - " \"action\": \"search\",\n", - " \"action_input\": \"Population Guangzhou\"\n", - "}\n", - "Observation: ['Guangzhou has a population of 15 million inhabitants as of 2021.']\n", - "\n", - "\n", - "Thought: Now let's get the population of Shanghai using the tool 'search'.\n", - "Action:\n", - "{\n", - " \"action\": \"search\",\n", - " \"action_input\": \"Population Shanghai\"\n", - "}\n", - "Observation: '26 million (2019)'\n", - "\n", - "Thought: Now I know that Shanghai has a larger population. Let's return the result.\n", - "Action:\n", - "{\n", - " \"action\": \"final_answer\",\n", - " \"action_input\": \"Shanghai\"\n", - "}\n", - "\n", - "\n", - "Above example were using notional tools that might not exist for you. You only have access to those tools:\n", - "\n", - "- retriever: Using semantic similarity, retrieves some documents from the knowledge base that have the closest embeddings to the input query.\n", - " Takes inputs: {'query': {'type': 'text', 'description': 'The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question.'}}\n", - "\n", - "- final_answer: Provides a final answer to the given problem\n", - " Takes inputs: {'answer': {'type': 'text', 'description': 'The final answer to the problem'}}\n", - "\n", - "Here are the rules you should always follow to solve your task:\n", - "1. ALWAYS provide a 'Thought:' sequence, and an 'Action:' sequence that ends with , else you will fail.\n", - "2. Always use the right arguments for the tools. Never use variable names in the 'action_input' field, use the value instead.\n", - "3. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.\n", - "4. Never re-do a tool call that you previously did with the exact same parameters.\n", - "\n", - "Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.\n", - "\u001b[0m\n", - "\u001b[38;20m===== New step =====\u001b[0m\n", - "===== Calling LLM with this last message: =====\n", - "{'role': , 'content': 'Task: How can I push a model to the Hub?'}\n", - "\u001b[38;20m===== Output message of the LLM: =====\u001b[0m\n", - "\u001b[38;20mThought: I can use the \"retriever\" tool to find documents relevant to the question, \"How can I push a model to the Hub?\" I will then read through the retrieved documents to find the relevant information and provide an answer to the question.\n", - "\n", - "Action: ```json\n", - "{\n", - " \"action\": \"retriever\",\n", - " \"action_input\": {\n", - " \"query\": \"How can I push a model to the Hub?\"\n", - " }\n", - "}\u001b[0m\n", - "\u001b[38;20m===== Extracting action =====\u001b[0m\n", - "\u001b[33;1mCalling tool: 'retriever' with arguments: {'query': 'How can I push a model to the Hub?'}\u001b[0m\n", - "Retrieved documents:\n", - "===== Document 0 =====\n", - "# Step 7. Push everything to the Hub\n", - " api.upload_folder(\n", - " repo_id=repo_id,\n", - " folder_path=repo_local_path,\n", - " path_in_repo=\".\",\n", - " )\n", - "\n", - " print(\"Your model is pushed to the Hub. You can view your model here: \", repo_url)\n", - "```\n", - "\n", - "### .\n", - "\n", - "By using `push_to_hub` **you evaluate, record a replay, generate a model card of your agent and push it to the Hub**.===== Document 1 =====\n", - "```py\n", - ">>> trainer.push_to_hub()\n", - "```\n", - "\n", - "\n", - "Share a model to the Hub with [`PushToHubCallback`]. In the [`PushToHubCallback`] function, add:\n", - "\n", - "- An output directory for your model.\n", - "- A tokenizer.\n", - "- The `hub_model_id`, which is your Hub username and model name.\n", - "\n", - "```py\n", - ">>> from transformers import PushToHubCallback\n", - "\n", - ">>> push_to_hub_callback = PushToHubCallback(\n", - "... output_dir=\"./your_model_save_path\", tokenizer=tokenizer, hub_model_id=\"your-username/my-awesome-model\"\n", - "... )\n", - "```===== Document 2 =====\n", - "Let's pretend we've now fine-tuned the model. The next step would be to push it to the Hub! We can do this with the `timm.models.hub.push_to_hf_hub` function.\n", - "\n", - "```py\n", - ">>> model_cfg = dict(labels=['a', 'b', 'c', 'd'])\n", - ">>> timm.models.hub.push_to_hf_hub(model, 'resnet18-random', model_config=model_cfg)\n", - "```\n", - "\n", - "Running the above would push the model to `/resnet18-random` on the Hub. You can now share this model with your friends, or use it in your own code!\n", - "\n", - "## Loading a Model===== Document 3 =====\n", - "processor.push_to_hub(hub_model_id)\n", - "trainer.push_to_hub(**kwargs)\n", - "```\n", - "\n", - "# 4. Inference\n", - "\n", - "Now comes the exciting part, using our fine-tuned model! In this section, we'll show how you can load your model from the hub and use it for inference.===== Document 4 =====\n", - "--push_to_hub\n", - "```===== Document 5 =====\n", - ". The second way to upload a model, though, is to call model.push_to_hub(). So this is more of a once-off method - it's not called regularly during training. You can just call this manually whenever you want to upload a model to the hub. So we recommend running this after the end of training, just to make sure that you have a commit message just to guarantee that this was the final version of the model at the end of training. And it just makes sure that you're working with the definitive end-of-training model and not accidentally using a model that's from a checkpoint somewhere along the way===== Document 6 =====\n", - "Finally, if you want, you can push your model up to the hub. Here, we'll push it up if you specified `push_to_hub=True` in the training configuration. Note that in order to push to hub, you'll have to have git-lfs installed and be logged into your Hugging Face account (which can be done via `huggingface-cli login`).\n", - "\n", - "```python\n", - "kwargs = {\n", - " \"finetuned_from\": model.config._name_or_path,\n", - " \"tasks\": \"image-classification\",\n", - " \"dataset\": 'beans',\n", - " \"tags\": ['image-classification'],\n", - "}\n", - "\u001b[38;20m===== New step =====\u001b[0m\n", - "===== Calling LLM with this last message: =====\n", - "{'role': , 'content': 'Observation: Retrieved documents:\\n===== Document 0 =====\\n# Step 7. Push everything to the Hub\\n api.upload_folder(\\n repo_id=repo_id,\\n folder_path=repo_local_path,\\n path_in_repo=\".\",\\n )\\n\\n print(\"Your model is pushed to the Hub. You can view your model here: \", repo_url)\\n```\\n\\n### .\\n\\nBy using `push_to_hub` **you evaluate, record a replay, generate a model card of your agent and push it to the Hub**.===== Document 1 =====\\n```py\\n>>> trainer.push_to_hub()\\n```\\n\\n\\nShare a model to the Hub with [`PushToHubCallback`]. In the [`PushToHubCallback`] function, add:\\n\\n- An output directory for your model.\\n- A tokenizer.\\n- The `hub_model_id`, which is your Hub username and model name.\\n\\n```py\\n>>> from transformers import PushToHubCallback\\n\\n>>> push_to_hub_callback = PushToHubCallback(\\n... output_dir=\"./your_model_save_path\", tokenizer=tokenizer, hub_model_id=\"your-username/my-awesome-model\"\\n... )\\n```===== Document 2 =====\\nLet\\'s pretend we\\'ve now fine-tuned the model. The next step would be to push it to the Hub! We can do this with the `timm.models.hub.push_to_hf_hub` function.\\n\\n```py\\n>>> model_cfg = dict(labels=[\\'a\\', \\'b\\', \\'c\\', \\'d\\'])\\n>>> timm.models.hub.push_to_hf_hub(model, \\'resnet18-random\\', model_config=model_cfg)\\n```\\n\\nRunning the above would push the model to `/resnet18-random` on the Hub. You can now share this model with your friends, or use it in your own code!\\n\\n## Loading a Model===== Document 3 =====\\nprocessor.push_to_hub(hub_model_id)\\ntrainer.push_to_hub(**kwargs)\\n```\\n\\n# 4. Inference\\n\\nNow comes the exciting part, using our fine-tuned model! In this section, we\\'ll show how you can load your model from the hub and use it for inference.===== Document 4 =====\\n--push_to_hub\\n```===== Document 5 =====\\n. The second way to upload a model, though, is to call model.push_to_hub(). So this is more of a once-off method - it\\'s not called regularly during training. You can just call this manually whenever you want to upload a model to the hub. So we recommend running this after the end of training, just to make sure that you have a commit message just to guarantee that this was the final version of the model at the end of training. And it just makes sure that you\\'re working with the definitive end-of-training model and not accidentally using a model that\\'s from a checkpoint somewhere along the way===== Document 6 =====\\nFinally, if you want, you can push your model up to the hub. Here, we\\'ll push it up if you specified `push_to_hub=True` in the training configuration. Note that in order to push to hub, you\\'ll have to have git-lfs installed and be logged into your Hugging Face account (which can be done via `huggingface-cli login`).\\n\\n```python\\nkwargs = {\\n \"finetuned_from\": model.config._name_or_path,\\n \"tasks\": \"image-classification\",\\n \"dataset\": \\'beans\\',\\n \"tags\": [\\'image-classification\\'],\\n}'}\n", - "\u001b[38;20m===== Output message of the LLM: =====\u001b[0m\n", - "\u001b[38;20mThought: I have found multiple ways to push a model to the Hub. In order to answer comprehensively, I will provide each code snippet that describes how to push a model to the Hub.\n", - "\n", - "Action: ```json\n", - "{\n", - " \"action\": \"final_answer\",\n", - " \"action_input\": {\n", - " \"answer\": \"There are multiple ways to push a model to the Hub. Here are a few examples using different libraries and functions:\\n\\nUsing the `api`:\\n```python\\napi.upload_folder(\\n repo_id=repo_id,\\n folder_path=repo_local_path,\\n path_in_repo=\\\".\\\",\\n)\\n\\nprint(\\\"Your model is pushed to the Hub. You can view your model here:\\\", repo_url)\\n```\\n\\nWith Transformers:\\n```python\\nfrom transformers import PushToHubCallback\\n\\n# Initialize the callback with the output directory,\\ntokenizer, and your Hub username and model name\\npush_to_hub_callback = PushToHubCallback(\\n output_dir=\\\"./your_model_save_path\\\",\\n tokenizer=tokenizer,\\n hub_model_id=\\\"your-username/my-awesome-model\\\"\\n)\\n\\n# Assuming `trainer` is your Trainer object\\ntrainer.add_callback(push_to_hub_callback)\\n```\\n\\nUsing `timm`:\\n```python\\nfrom timm.models.hub import push_to_hf_hub\\n\\n# Assuming `model` is your fine-tuned model\\nmodel_cfg = {\\\"labels\\\": [\\\"a\\\", \\\"b\\\", \\\"c\\\", \\\"d\\\"]}\\npush_to_hf_hub(model, 'resnet18-random', model_config=model_cfg)\\n```\\n\\nFor computer vision models, you can also use `push_to_hub`:\\n```python\\nprocessor.push_to_hub(hub_model_id)\\ntrainer.push_to_hub(**kwargs)\\n```\\n\\nYou can also manually push a model with `model.push_to_hub()`:\\n```python\\nmodel.push_to_hub()\\n```\\n\\nAdditionally, you can opt to push your model to the Hub at the end of training by specifying `push_to_hub=True` in the training configuration. Don't forget to have git-lfs installed and be logged into your Hugging Face account.\"\n", - " }\n", - "}\u001b[0m\n", - "\u001b[38;20m===== Extracting action =====\u001b[0m\n", - "\u001b[33;1mCalling tool: 'final_answer' with arguments: {'answer': \"There are multiple ways to push a model to the Hub. Here are a few examples using different libraries and functions:\\n\\nUsing the `api`:\\npython\\napi.upload_folder(\\n repo_id=repo_id,\\n folder_path=repo_local_path,\\n path_in_repo='.',\\n)\\n\\nprint('Your model is pushed to the Hub. You can view your model here:', repo_url)\\n\\n\\nWith Transformers:\\npython\\nfrom transformers import PushToHubCallback\\n\\n# Initialize the callback with the output directory,\\ntokenizer, and your Hub username and model name\\npush_to_hub_callback = PushToHubCallback(\\n output_dir='./your_model_save_path',\\n tokenizer=tokenizer,\\n hub_model_id='your-username/my-awesome-model'\\n)\\n\\n# Assuming `trainer` is your Trainer object\\ntrainer.add_callback(push_to_hub_callback)\\n\\n\\nUsing `timm`:\\npython\\nfrom timm.models.hub import push_to_hf_hub\\n\\n# Assuming `model` is your fine-tuned model\\nmodel_cfg = {'labels': ['a', 'b', 'c', 'd']}\\npush_to_hf_hub(model, 'resnet18-random', model_config=model_cfg)\\n\\n\\nFor computer vision models, you can also use `push_to_hub`:\\npython\\nprocessor.push_to_hub(hub_model_id)\\ntrainer.push_to_hub(**kwargs)\\n\\n\\nYou can also manually push a model with `model.push_to_hub()`:\\npython\\nmodel.push_to_hub()\\n\\n\\nAdditionally, you can opt to push your model to the Hub at the end of training by specifying `push_to_hub=True` in the training configuration. Don't forget to have git-lfs installed and be logged into your Hugging Face account.\"}\u001b[0m\n" - ] - }, { "name": "stdout", "output_type": "stream", "text": [ "Final output:\n", - "There are multiple ways to push a model to the Hub. Here are a few examples using different libraries and functions:\n", - "\n", - "Using the `api`:\n", - "python\n", - "api.upload_folder(\n", - " repo_id=repo_id,\n", - " folder_path=repo_local_path,\n", - " path_in_repo='.',\n", - ")\n", - "\n", - "print('Your model is pushed to the Hub. You can view your model here:', repo_url)\n", - "\n", - "\n", - "With Transformers:\n", - "python\n", - "from transformers import PushToHubCallback\n", - "\n", - "# Initialize the callback with the output directory,\n", - "tokenizer, and your Hub username and model name\n", - "push_to_hub_callback = PushToHubCallback(\n", - " output_dir='./your_model_save_path',\n", - " tokenizer=tokenizer,\n", - " hub_model_id='your-username/my-awesome-model'\n", - ")\n", - "\n", - "# Assuming `trainer` is your Trainer object\n", - "trainer.add_callback(push_to_hub_callback)\n", - "\n", - "\n", - "Using `timm`:\n", - "python\n", - "from timm.models.hub import push_to_hf_hub\n", - "\n", - "# Assuming `model` is your fine-tuned model\n", - "model_cfg = {'labels': ['a', 'b', 'c', 'd']}\n", - "push_to_hf_hub(model, 'resnet18-random', model_config=model_cfg)\n", - "\n", - "\n", - "For computer vision models, you can also use `push_to_hub`:\n", - "python\n", - "processor.push_to_hub(hub_model_id)\n", - "trainer.push_to_hub(**kwargs)\n", - "\n", - "\n", - "You can also manually push a model with `model.push_to_hub()`:\n", - "python\n", - "model.push_to_hub()\n", - "\n", - "\n", - "Additionally, you can opt to push your model to the Hub at the end of training by specifying `push_to_hub=True` in the training configuration. Don't forget to have git-lfs installed and be logged into your Hugging Face account.\n" + "To push a model to the Hub, use `model.push_to_hub()`.\n" ] } ], @@ -556,9 +267,24 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b02d635c7a5948f0839cf1016f817fb8", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "README.md: 0%| | 0.00/893 [00:00 str:\n", + " \"\"\"\n", + " Allows you to perform SQL queries on the table. Returns a string representation of the result.\n", + " The table is named 'receipts'. Its description is as follows:\n", + " Columns:\n", + " - receipt_id: INTEGER\n", + " - customer_name: VARCHAR(16)\n", + " - price: FLOAT\n", + " - tip: FLOAT\n", "\n", - " def forward(self, query: str) -> str:\n", - " output = \"\"\n", - " with engine.connect() as con:\n", - " rows = con.execute(text(query))\n", - " for row in rows:\n", - " output += \"\\n\" + str(row)\n", - " return output" + " Args:\n", + " query: The query to perform. This should be correct SQL.\n", + " \"\"\"\n", + " output = \"\"\n", + " with engine.connect() as con:\n", + " rows = con.execute(text(query))\n", + " for row in rows:\n", + " output += \"\\n\" + str(row)\n", + " return output" ] }, { @@ -201,53 +199,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ - "from transformers.agents import ReactCodeAgent, HfEngine\n", + "from transformers.agents import ReactCodeAgent, HfApiEngine\n", "\n", "agent = ReactCodeAgent(\n", - " tools=[SQLExecutorTool()],\n", - " llm_engine=HfEngine(\"meta-llama/Meta-Llama-3-70B-Instruct\"),\n", + " tools=[sql_engine],\n", + " llm_engine=HfApiEngine(\"meta-llama/Meta-Llama-3-8B-Instruct\"),\n", ")" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33;1m======== New task ========\u001b[0m\n", + "\u001b[32;20;1m======== New task ========\u001b[0m\n", "\u001b[37;1mCan you give me the name of the client who got the most expensive receipt?\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msql_engine\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mSELECT customer_name, price FROM receipts ORDER BY price DESC LIMIT 1\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: I will use the tool sql_engine to query the table'receipts' and retrieve the client who got the most expensive receipt. I will sort the results in descending order based on the 'price' column and then return the client name.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mreceipts_result\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msql_engine\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mSELECT customer_name, MAX(price) FROM receipts\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mreceipts_result\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", "\u001b[32;20m\n", "('Woodrow Wilson', 53.43)\n", "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mWoodrow Wilson\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: From the output of the previous step, I can see that Woodrow Wilson got the most expensive receipt with a price of 53.43. Now, I want to verify the client name with the receipt data. I will use the tool sql_engine again to query the table'receipts' and retrieve the receipt information for Woodrow Wilson.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mreceipt_info\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msql_engine\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mSELECT * FROM receipts WHERE customer_name=\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;144mWoodrow Wilson\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mreceipt_info\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m====\u001b[0m\n", + "\u001b[33;1mPrint outputs:\u001b[0m\n", + "\u001b[32;20m\n", + "(3, 'Woodrow Wilson', 53.43, 5.43)\n", + "\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: From the output of the previous step, I can see that the receipt for Woodrow Wilson has the receipt_id 3, the customer_name 'Woodrow Wilson', the price 53.43, and the tip 5.43. Now, I want to give the final answer of the task using the tool final_answer.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mThe client who got the most expensive receipt is Woodrow Wilson.\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", "\u001b[32;20m\u001b[0m\n", - "\u001b[33;1m>>> Final answer:\u001b[0m\n", - "\u001b[32;20mWoodrow Wilson\u001b[0m\n" + "\u001b[33;1mLast output from code snippet:\u001b[0m\n", + "\u001b[32;20mThe client who got the most expensive receipt is Woodrow Wilson.\u001b[0m\n", + "\u001b[32;20;1mFinal answer:\u001b[0m\n", + "\u001b[32;20mThe client who got the most expensive receipt is Woodrow Wilson.\u001b[0m\n" ] }, { "data": { "text/plain": [ - "'Woodrow Wilson'" + "'The client who got the most expensive receipt is Woodrow Wilson.'" ] }, - "execution_count": 7, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -269,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -303,7 +317,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -345,32 +359,34 @@ "print(updated_description)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Since this request is a bit harder than the previous one, we'll switch the llm engine to use the more powerful [Qwen/Qwen2.5-72B-Instruct](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct)!" + ] + }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mWhich waiter got more total money from tips?\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['time', 'queue', 'random', 'unicodedata', 're', 'collections', 'itertools', 'stat', 'math', 'statistics']\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msql_engine\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mSELECT w.waiter_name, SUM(r.tip) AS total_tip FROM receipts r JOIN waiters w ON r.receipt_id = w.receipt_id GROUP BY w.waiter_name\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[32;20;1m======== New task ========\u001b[0m\n", + "\u001b[37;1mWhich waiter got more total money from tips?\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: I need to first compute the total amount of tips for each waiter. I will use the `sql_engine` tool to perform a query that sums the tips for each waiter.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;144m\"\"\"\u001b[39m\n", + "\u001b[38;5;144mSELECT W.waiter_name, SUM(R.tip) as total_tips\u001b[39m\n", + "\u001b[38;5;144mFROM receipts R\u001b[39m\n", + "\u001b[38;5;144mJOIN waiters W ON R.receipt_id = W.receipt_id\u001b[39m\n", + "\u001b[38;5;144mGROUP BY W.waiter_name\u001b[39m\n", + "\u001b[38;5;144m\"\"\"\u001b[39m\n", + "\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msql_engine\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mquery\u001b[39m\u001b[38;5;7m)\u001b[39m\n", "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", @@ -379,12 +395,272 @@ "('Margaret James', 1.0)\n", "('Michael Watts', 5.67)\n", "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mMichael Watts\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: Now I have the total tips for each waiter. I need to compare these values to find the waiter with the highest total tips. I will use Python code to do this.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;60;03m# Extracting the total tips from the result\u001b[39;00m\n", + "\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7m{\u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m:\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109meval\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m}\u001b[39m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\n", + "\u001b[38;5;60;03m# Finding the waiter with the highest total tips\u001b[39;00m\n", + "\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mmax\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mkey\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mget\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m====\u001b[0m\n", + "\u001b[31;20mCode execution failed due to the following error:\n", + "EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0]: row[1] for row in eval(result)}' because of the following error:\n", + "It is not permitted to evaluate other functions than the provided tools or functions defined in previous code (tried to execute eval).\u001b[0m\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 895, in evaluate_python_code\n", + " result = evaluate_ast(node, state, static_tools, custom_tools, authorized_imports)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 741, in evaluate_ast\n", + " return evaluate_assign(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 322, in evaluate_assign\n", + " result = evaluate_ast(assign.value, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 825, in evaluate_ast\n", + " return evaluate_dictcomp(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 694, in evaluate_dictcomp\n", + " iter_value = evaluate_ast(gen.iter, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 746, in evaluate_ast\n", + " return evaluate_call(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 385, in evaluate_call\n", + " raise InterpreterError(\n", + "transformers.agents.python_interpreter.InterpreterError: It is not permitted to evaluate other functions than the provided tools or functions defined in previous code (tried to execute eval).\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1135, in step\n", + " result = self.python_evaluator(\n", + " ^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 904, in evaluate_python_code\n", + " raise InterpreterError(msg)\n", + "transformers.agents.python_interpreter.InterpreterError: EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0]: row[1] for row in eval(result)}' because of the following error:\n", + "It is not permitted to evaluate other functions than the provided tools or functions defined in previous code (tried to execute eval).\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 811, in direct_run\n", + " step_logs = self.step()\n", + " ^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1155, in step\n", + " raise AgentExecutionError(error_msg)\n", + "transformers.agents.agents.AgentExecutionError: Code execution failed due to the following error:\n", + "EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0]: row[1] for row in eval(result)}' because of the following error:\n", + "It is not permitted to evaluate other functions than the provided tools or functions defined in previous code (tried to execute eval).\n", + "\u001b[31;20mError in generating llm output: (ReadTimeoutError(\"HTTPSConnectionPool(host='api-inference.huggingface.co', port=443): Read timed out. (read timeout=120)\"), '(Request ID: a887a819-3b3b-4bab-ba37-a05b83a8cbf1)').\u001b[0m\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connectionpool.py\", line 537, in _make_request\n", + " response = conn.getresponse()\n", + " ^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connection.py\", line 466, in getresponse\n", + " httplib_response = super().getresponse()\n", + " ^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/http/client.py\", line 1411, in getresponse\n", + " response.begin()\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/http/client.py\", line 324, in begin\n", + " version, status, reason = self._read_status()\n", + " ^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/http/client.py\", line 285, in _read_status\n", + " line = str(self.fp.readline(_MAXLINE + 1), \"iso-8859-1\")\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/socket.py\", line 707, in readinto\n", + " return self._sock.recv_into(b)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/ssl.py\", line 1249, in recv_into\n", + " return self.read(nbytes, buffer)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/ssl.py\", line 1105, in read\n", + " return self._sslobj.read(len, buffer)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "TimeoutError: The read operation timed out\n", + "\n", + "The above exception was the direct cause of the following exception:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/requests/adapters.py\", line 667, in send\n", + " resp = conn.urlopen(\n", + " ^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connectionpool.py\", line 847, in urlopen\n", + " retries = retries.increment(\n", + " ^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/util/retry.py\", line 470, in increment\n", + " raise reraise(type(error), error, _stacktrace)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/util/util.py\", line 39, in reraise\n", + " raise value\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connectionpool.py\", line 793, in urlopen\n", + " response = self._make_request(\n", + " ^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connectionpool.py\", line 539, in _make_request\n", + " self._raise_timeout(err=e, url=url, timeout_value=read_timeout)\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/urllib3/connectionpool.py\", line 370, in _raise_timeout\n", + " raise ReadTimeoutError(\n", + "urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api-inference.huggingface.co', port=443): Read timed out. (read timeout=120)\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1099, in step\n", + " llm_output = self.llm_engine(\n", + " ^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/llm_engine.py\", line 89, in __call__\n", + " response = self.client.chat_completion(messages, stop=stop_sequences, max_tokens=1500)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/huggingface_hub/inference/_client.py\", line 706, in chat_completion\n", + " data = self.post(\n", + " ^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/huggingface_hub/inference/_client.py\", line 259, in post\n", + " response = get_session().post(\n", + " ^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/requests/sessions.py\", line 637, in post\n", + " return self.request(\"POST\", url, data=data, json=json, **kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/requests/sessions.py\", line 589, in request\n", + " resp = self.send(prep, **send_kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/requests/sessions.py\", line 703, in send\n", + " r = adapter.send(request, **kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/huggingface_hub/utils/_http.py\", line 66, in send\n", + " return super().send(request, *args, **kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/venvs/cookbook2/lib/python3.12/site-packages/requests/adapters.py\", line 713, in send\n", + " raise ReadTimeout(e, request=request)\n", + "requests.exceptions.ReadTimeout: (ReadTimeoutError(\"HTTPSConnectionPool(host='api-inference.huggingface.co', port=443): Read timed out. (read timeout=120)\"), '(Request ID: a887a819-3b3b-4bab-ba37-a05b83a8cbf1)')\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 811, in direct_run\n", + " step_logs = self.step()\n", + " ^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1103, in step\n", + " raise AgentGenerationError(f\"Error in generating llm output: {e}.\")\n", + "transformers.agents.agents.AgentGenerationError: Error in generating llm output: (ReadTimeoutError(\"HTTPSConnectionPool(host='api-inference.huggingface.co', port=443): Read timed out. (read timeout=120)\"), '(Request ID: a887a819-3b3b-4bab-ba37-a05b83a8cbf1)').\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: I cannot use `eval` to process the string result. I need to parse the result string in a safer and more direct way. I'll do this by splitting the string and converting it into a dictionary.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;60;03m# Parsing the result string into a list of tuples\u001b[39;00m\n", + "\u001b[38;5;7mresult_list\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mline\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7msplit\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m, \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mline\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7msplit\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;186m\\n\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m]\u001b[39m\n", + "\n", + "\u001b[38;5;60;03m# Converting the list of tuples into a dictionary\u001b[39;00m\n", + "\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7m{\u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;186m\\'\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mfloat\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mresult_list\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mif\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mrow\u001b[39m\u001b[38;5;7m}\u001b[39m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\n", + "\u001b[38;5;60;03m# Finding the waiter with the highest total tips\u001b[39;00m\n", + "\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mmax\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mkey\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mget\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m====\u001b[0m\n", + "\u001b[31;20mCode execution failed due to the following error:\n", + "EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0].strip('\\''): float(row[1].strip()) for row in result_list if row}' because of the following error:\n", + "Index 1 out of bounds for list of length 1\u001b[0m\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 895, in evaluate_python_code\n", + " result = evaluate_ast(node, state, static_tools, custom_tools, authorized_imports)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 741, in evaluate_ast\n", + " return evaluate_assign(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 322, in evaluate_assign\n", + " result = evaluate_ast(assign.value, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 825, in evaluate_ast\n", + " return evaluate_dictcomp(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 700, in evaluate_dictcomp\n", + " val = evaluate_ast(dictcomp.value, new_state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 746, in evaluate_ast\n", + " return evaluate_call(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 394, in evaluate_call\n", + " args.append(evaluate_ast(arg, state, static_tools, custom_tools))\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 746, in evaluate_ast\n", + " return evaluate_call(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 368, in evaluate_call\n", + " obj = evaluate_ast(call.func.value, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 804, in evaluate_ast\n", + " return evaluate_subscript(expression, state, static_tools, custom_tools)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 460, in evaluate_subscript\n", + " raise InterpreterError(f\"Index {index} out of bounds for list of length {len(value)}\")\n", + "transformers.agents.python_interpreter.InterpreterError: Index 1 out of bounds for list of length 1\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1135, in step\n", + " result = self.python_evaluator(\n", + " ^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 904, in evaluate_python_code\n", + " raise InterpreterError(msg)\n", + "transformers.agents.python_interpreter.InterpreterError: EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0].strip('\\''): float(row[1].strip()) for row in result_list if row}' because of the following error:\n", + "Index 1 out of bounds for list of length 1\n", + "\n", + "During handling of the above exception, another exception occurred:\n", + "\n", + "Traceback (most recent call last):\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 811, in direct_run\n", + " step_logs = self.step()\n", + " ^^^^^^^^^^^\n", + " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 1155, in step\n", + " raise AgentExecutionError(error_msg)\n", + "transformers.agents.agents.AgentExecutionError: Code execution failed due to the following error:\n", + "EXECUTION FAILED:\n", + "Evaluation stopped at line 'waiters_tips = {row[0].strip('\\''): float(row[1].strip()) for row in result_list if row}' because of the following error:\n", + "Index 1 out of bounds for list of length 1\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: It appears that the result string is not being processed correctly. I need to ensure that the string is split into a list of tuples in a way that correctly captures each row. I'll inspect the result string to understand its exact format.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;60;03m# Inspect the result string\u001b[39;00m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m\u001b[0m\n", - "\u001b[33;1m>>> Final answer:\u001b[0m\n", + "\u001b[32;20m\n", + "('Corey Johnson', 1.2)\n", + "('Margaret James', 1.0)\n", + "('Michael Watts', 5.67)\n", + "\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: The result string is a list of tuples, but it's not in a format that can be directly parsed using `split`. I need to handle the result string more carefully. I'll use a list comprehension to process the string and extract the waiter names and their total tips.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;60;03m# Split the result string into individual lines\u001b[39;00m\n", + "\u001b[38;5;7mlines\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mresult\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m[]\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mreplace\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m)\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mreplace\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7msplit\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;186m\\n\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\n", + "\u001b[38;5;60;03m# Process each line to create a dictionary of waiters and their total tips\u001b[39;00m\n", + "\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7m{\u001b[39m\u001b[38;5;7m}\u001b[39m\n", + "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mline\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mlines\u001b[39m\u001b[38;5;7m:\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mif\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mline\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;7mwaiter\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mtip\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mline\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7msplit\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m, \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mwaiter\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mfloat\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mtip\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mstrip\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\n", + "\u001b[38;5;60;03m# Finding the waiter with the highest total tips\u001b[39;00m\n", + "\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mmax\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mkey\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7mwaiters_tips\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mget\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mbest_waiter\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m====\u001b[0m\n", + "\u001b[33;1mPrint outputs:\u001b[0m\n", + "\u001b[32;20m{'Corey Johnson': 1.2, 'Margaret James': 1.0, 'Michael Watts': 5.67}\n", + "\u001b[0m\n", + "\u001b[33;1mLast output from code snippet:\u001b[0m\n", + "\u001b[32;20mMichael Watts\u001b[0m\n", + "\u001b[32;20;1mFinal answer:\u001b[0m\n", "\u001b[32;20mMichael Watts\u001b[0m\n" ] }, @@ -394,18 +670,17 @@ "'Michael Watts'" ] }, - "execution_count": 10, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "sql_tool = SQLExecutorTool()\n", - "sql_tool.description = updated_description\n", + "sql_engine.description = updated_description\n", "\n", "agent = ReactCodeAgent(\n", - " tools=[sql_tool],\n", - " llm_engine=HfEngine(\"meta-llama/Meta-Llama-3-70B-Instruct\"),\n", + " tools=[sql_engine],\n", + " llm_engine=HfApiEngine(\"Qwen/Qwen2.5-72B-Instruct\"),\n", ")\n", "\n", "agent.run(\"Which waiter got more total money from tips?\")" @@ -423,9 +698,9 @@ ], "metadata": { "kernelspec": { - "display_name": "disposable", + "display_name": "cookbook2", "language": "python", - "name": "python3" + "name": "cookbook2" }, "language_info": { "codemirror_mode": { @@ -437,7 +712,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.12.0" } }, "nbformat": 4, diff --git a/notebooks/en/agents.ipynb b/notebooks/en/agents.ipynb index 89deadfd..f5050a9d 100644 --- a/notebooks/en/agents.ipynb +++ b/notebooks/en/agents.ipynb @@ -26,16 +26,7 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install \"git+https://github.com/huggingface/transformers.git#egg=transformers[agents]\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "!pip install datasets langchain sentence-transformers faiss-cpu serpapi google-search-results openai langchain-community -q" + "!pip install \"transformers[agents]\" datasets langchain sentence-transformers faiss-cpu duckduckgo-search openai langchain-community --upgrade -q" ] }, { @@ -48,75 +39,26 @@ "\n", "To build it, we simply need to have two tools ready: image generation and web search.\n", "- For image generation, we load a tool from the Hub that uses the HF Inference API (Serverless) to generate images using Stable Diffusion.\n", - "- For the web search, we load a LangChain tool." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "os.environ['SERPAPI_API_KEY'] = ''" + "- For the web search, we use a built-in tool." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "from huggingface_hub import notebook_login\n", - "\n", - "notebook_login()" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[33;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mGenerate me a photo of the car that James bond drove in the latest movie.\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mlatest_movie\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msearch\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mWhat is the latest James Bond movie?\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mLatest James Bond movie:\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mlatest_movie\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;7mbond_car\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msearch\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mWhat car did James Bond drive in the latest movie?\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mJames Bond\u001b[39m\u001b[38;5;144m'\u001b[39m\u001b[38;5;144ms car:\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mbond_car\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20mLatest James Bond movie: No Time to Die\n", - "James Bond's car: Aston Martin DB5\n", - "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mimage\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mimage_generator\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mA high-res, photorealistic image of the Aston Martin DB5 driven by James Bond in No Time to Die\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mimage\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m\u001b[0m\n", - "\u001b[33;1m>>> Final answer:\u001b[0m\n", - "\u001b[32;20m/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/tmptcdd2ra6/2bf48fc0-6fff-4e86-8fb5-85b3221bc0c8.png\u001b[0m\n" - ] - } - ], - "source": [ - "from transformers import Tool, load_tool, ReactCodeAgent, HfEngine\n", + "from transformers import load_tool, ReactCodeAgent, HfApiEngine\n", "\n", "# Import tool from Hub\n", - "image_generation_tool = load_tool(\"m-ric/text-to-image\")\n", + "image_generation_tool = load_tool(\"m-ric/text-to-image\", cache=False)\n", "\n", "# Import tool from LangChain\n", - "from langchain.agents import load_tools\n", - "\n", - "search_tool = Tool.from_langchain(load_tools([\"serpapi\"])[0])\n", + "from transformers.agents.search import DuckDuckGoSearchTool\n", "\n", + "search_tool = DuckDuckGoSearchTool()\n", "\n", - "llm_engine = HfEngine(\"meta-llama/Meta-Llama-3-70B-Instruct\")\n", + "llm_engine = HfApiEngine(\"Qwen/Qwen2.5-72B-Instruct\")\n", "# Initialize the agent with both tools\n", "agent = ReactCodeAgent(\n", " tools=[image_generation_tool, search_tool], llm_engine=llm_engine\n", @@ -158,18 +100,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/aymeric/.pyenv/versions/3.12.0/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", - " from .autonotebook import tqdm as notebook_tqdm\n" - ] - } - ], + "outputs": [], "source": [ "import datasets\n", "\n", @@ -185,9 +118,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/var/folders/6m/9b1tts6d5w960j80wbw9tx3m0000gn/T/ipykernel_16932/1458839689.py:15: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.\n", + " embedding_model = HuggingFaceEmbeddings(model_name=\"thenlper/gte-small\")\n" + ] + } + ], "source": [ "from langchain.docstore.document import Document\n", "from langchain.text_splitter import RecursiveCharacterTextSplitter\n", @@ -220,14 +162,14 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['evaluate', 'course', 'deep-rl-class', 'peft', 'hf-endpoints-documentation', 'blog', 'gradio', 'datasets', 'datasets-server', 'transformers', 'optimum', 'hub-docs', 'pytorch-image-models', 'diffusers']\n" + "['datasets-server', 'datasets', 'optimum', 'gradio', 'blog', 'course', 'hub-docs', 'pytorch-image-models', 'peft', 'evaluate', 'diffusers', 'hf-endpoints-documentation', 'deep-rl-class', 'transformers']\n" ] } ], @@ -236,9 +178,18 @@ "print(all_sources)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "👉 Now let's build a `RetrieverTool` that our agent can leverage to retrieve information from the knowledge base.\n", + "\n", + "Since we need to add a vectordb as an attribute of the tool, we cannot simply use the [simple tool constructor](https://huggingface.co/docs/transformers/main/en/agents#create-a-new-tool) with a `@tool` decorator: so we will follow the advanced setup highlighted in the [advanced agents documentation](https://huggingface.co/docs/transformers/main/en/agents_advanced#directly-define-a-tool-by-subclassing-tool-and-share-it-to-the-hub)." + ] + }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -252,23 +203,25 @@ " description = \"Retrieves some documents from the knowledge base that have the closest embeddings to the input query.\"\n", " inputs = {\n", " \"query\": {\n", - " \"type\": \"text\",\n", + " \"type\": \"string\",\n", " \"description\": \"The query to perform. This should be semantically close to your target documents. Use the affirmative form rather than a question.\",\n", " },\n", - " \"source\": {\"type\": \"text\", \"description\": \"\"},\n", + " \"source\": {\"type\": \"string\", \"description\": \"\"},\n", " \"number_of_documents\": {\n", - " \"type\": \"text\",\n", + " \"type\": \"string\",\n", " \"description\": \"the number of documents to retrieve. Stay under 10 to avoid drowning in docs\",\n", " },\n", " }\n", - " output_type = \"text\"\n", + " output_type = \"string\"\n", "\n", " def __init__(self, vectordb: VectorStore, all_sources: str, **kwargs):\n", " super().__init__(**kwargs)\n", " self.vectordb = vectordb\n", - " self.inputs[\"source\"][\n", - " \"description\"\n", - " ] = f\"The source of the documents to search, as a str representation of a list. Possible values in the list are: {all_sources}. If this argument is not provided, all sources will be searched.\"\n", + " self.inputs[\"source\"][\"description\"] = (\n", + " f\"The source of the documents to search, as a str representation of a list. Possible values in the list are: {all_sources}. If this argument is not provided, all sources will be searched.\".replace(\n", + " \"'\", \"`\"\n", + " )\n", + " )\n", "\n", " def forward(self, query: str, source: str = None, number_of_documents=7) -> str:\n", " assert isinstance(query, str), \"Your search query must be a string\"\n", @@ -311,7 +264,7 @@ "metadata": {}, "outputs": [], "source": [ - "share_to_hub = False\n", + "share_to_hub = True\n", "\n", "if share_to_hub:\n", " from huggingface_hub import login\n", @@ -321,7 +274,14 @@ "\n", " tool = RetrieverTool(vectordb, all_sources)\n", "\n", - " tool.push_to_hub(repo_id=\"m-ric/retriever-tool\")" + " tool.push_to_hub(repo_id=\"m-ric/retriever-tool\")\n", + "\n", + " # Loading the tool\n", + " from transformers.agents import load_tool\n", + "\n", + " retriever_tool = load_tool(\n", + " \"m-ric/retriever-tool\", vectordb=vectordb, all_sources=all_sources\n", + " )" ] }, { @@ -333,41 +293,15 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "A new version of the following files was downloaded from https://huggingface.co/spaces/m-ric/retriever-tool:\n", - "- retriever.py\n", - ". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n", - "\u001b[33;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mPlease show me a LORA finetuning script\u001b[0m\n", - "\u001b[33;1mCalling tool: 'retriever' with arguments: {'number_of_documents': '5', 'query': 'LORA finetuning script', 'source': \"['transformers', 'blog']\"}\u001b[0m\n", - "\u001b[33;1mCalling tool: 'retriever' with arguments: {'number_of_documents': '5', 'query': 'LORA finetuning script'}\u001b[0m\n", - "\u001b[33;1mCalling tool: 'retriever' with arguments: {'number_of_documents': '5', 'query': 'train_text_to_image_lora.py'}\u001b[0m\n", - "\u001b[33;1mCalling tool: 'final_answer' with arguments: https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py\u001b[0m\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Final output:\n", - "https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_lora.py\n" - ] - } - ], + "outputs": [], "source": [ - "from transformers.agents import HfEngine, ReactJsonAgent, load_tool\n", + "from transformers.agents import HfApiEngine, ReactJsonAgent\n", "\n", - "llm_engine = HfEngine(\"meta-llama/Meta-Llama-3-70B-Instruct\")\n", + "llm_engine = HfApiEngine(\"Qwen/Qwen2.5-72B-Instruct\")\n", "\n", - "retriever_tool = load_tool(\n", - " \"m-ric/retriever-tool\", vectordb=vectordb, all_sources=all_sources\n", - ")\n", + "retriever_tool = RetrieverTool(vectordb=vectordb, all_sources=all_sources)\n", "agent = ReactJsonAgent(tools=[retriever_tool], llm_engine=llm_engine, verbose=0)\n", "\n", "agent_output = agent.run(\"Please show me a LORA finetuning script\")\n", @@ -393,137 +327,69 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[33;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mI have some code that creates a bug: please debug it and return the final code\n", + "\u001b[32;20;1m======== New task ========\u001b[0m\n", + "\u001b[37;1mI have some code that creates a bug: please debug it, then run it to make sure it works and return the final code\n", "You have been provided with these initial arguments: {'code': '\\nlist=[0, 1, 2]\\n\\nfor i in range(4):\\n print(list(i))\\n'}.\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;139m4\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", - "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[31;20mFailed while trying to execute the code below:\n", - "\u001b[0mlist=[0, 1, 2]\n", - "print(list)\n", - "for i in range(4):\n", - " print(list[i])\u001b[0m\n", - "This failed due to the following error:\n", - "list index out of range\u001b[0m\n", - "Traceback (most recent call last):\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 823, in step\n", - " result = self.python_evaluator(code_action, available_tools, state=self.state)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 511, in evaluate_python_code\n", - " line_result = evaluate_ast(node, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 404, in evaluate_ast\n", - " return evaluate_for(expression, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 313, in evaluate_for\n", - " line_result = evaluate_ast(node, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 401, in evaluate_ast\n", - " return evaluate_ast(expression.value, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 365, in evaluate_ast\n", - " return evaluate_call(expression, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 215, in evaluate_call\n", - " args = [evaluate_ast(arg, state, tools) for arg in call.args]\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 423, in evaluate_ast\n", - " return evaluate_subscript(expression, state, tools)\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/python_interpreter.py\", line 236, in evaluate_subscript\n", - " return value[int(index)]\n", - " ~~~~~^^^^^^^^^^^^\n", - "IndexError: list index out of range\n", - "\n", - "During handling of the above exception, another exception occurred:\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: The provided code has a bug. The `list` is a built-in type in Python and should not be used as a variable name. Furthermore, the `list` type does not have a `__call__` method, which means that you cannot use parentheses to access its elements. Instead, square brackets should be used to index the list. I will correct the variable name and the indexing syntax and then run the code to ensure it works.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mmy_list\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", "\n", - "Traceback (most recent call last):\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 623, in run\n", - " final_answer = self.step()\n", - " ^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 832, in step\n", - " raise AgentExecutionError(error_msg)\n", - "transformers.agents.agents.AgentExecutionError: Failed while trying to execute the code below:\n", - "\u001b[0mlist=[0, 1, 2]\n", - "print(list)\n", - "for i in range(4):\n", - " print(list[i])\u001b[0m\n", - "This failed due to the following error:\n", - "list index out of range\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;139m3\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", - "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m[0, 1, 2]\n", - "0\n", - "1\n", - "2\n", - "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;139m3\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", - "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m[0, 1, 2]\n", - "0\n", - "1\n", - "2\n", - "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlen\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", - "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;139m4\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mif\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m<\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mlen\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mmy_list\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mmy_list\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01melse\u001b[39;00m\u001b[38;5;7m:\u001b[39m\n", + "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mIndex out of range\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m[0, 1, 2]\n", - "0\n", + "\u001b[32;20m0\n", "1\n", "2\n", + "Index out of range\n", "\u001b[0m\n", - "\u001b[33;1m==== Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m[\u001b[39m\u001b[38;5;139m0\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m1\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2\u001b[39m\u001b[38;5;7m]\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109;01mfor\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01min\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mrange\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;139m3\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m:\u001b[39m\n", - "\u001b[38;5;7m \u001b[39m\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;109mlist\u001b[39m\u001b[38;5;7m[\u001b[39m\u001b[38;5;7mi\u001b[39m\u001b[38;5;7m]\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mcode\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", + "\u001b[0mThought: The code has been corrected and is running as expected, printing the list items for valid indices and an out-of-range message for invalid indices. I will return the final corrected code as the answer.\u001b[0m\n", + "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7manswer\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m'''\u001b[39m\u001b[38;5;144mmy_list = [0, 1, 2]\u001b[39m\n", + "\n", + "\u001b[38;5;144mfor i in range(4):\u001b[39m\n", + "\u001b[38;5;144m if i < len(my_list):\u001b[39m\n", + "\u001b[38;5;144m print(my_list[i])\u001b[39m\n", + "\u001b[38;5;144m else:\u001b[39m\n", + "\u001b[38;5;144m print(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mIndex out of range\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m)\u001b[39m\u001b[38;5;144m'''\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m[0, 1, 2]\n", - "0\n", - "1\n", - "2\n", - "\u001b[0m\n", - "\u001b[33;1m>>> Final answer:\u001b[0m\n", - "\u001b[32;20m\n", - "list=[0, 1, 2]\n", + "\u001b[32;20m\u001b[0m\n", + "\u001b[33;1mLast output from code snippet:\u001b[0m\n", + "\u001b[32;20mmy_list = [0, 1, 2]\n", "\n", "for i in range(4):\n", - " print(list(i))\n", - "\u001b[0m\n" + " if i < len(my_list):\n", + " print(my_list[i])\n", + " else:\n", + " print(\"Index out of range\")\u001b[0m\n", + "\u001b[32;20;1mFinal answer:\u001b[0m\n", + "\u001b[32;20mmy_list = [0, 1, 2]\n", + "\n", + "for i in range(4):\n", + " if i < len(my_list):\n", + " print(my_list[i])\n", + " else:\n", + " print(\"Index out of range\")\u001b[0m\n" ] } ], "source": [ "from transformers import ReactCodeAgent\n", "\n", - "agent = ReactCodeAgent(tools=[])\n", + "agent = ReactCodeAgent(tools=[], llm_engine=HfApiEngine(\"Qwen/Qwen2.5-72B-Instruct\"))\n", "\n", "code = \"\"\"\n", "list=[0, 1, 2]\n", @@ -533,7 +399,7 @@ "\"\"\"\n", "\n", "final_answer = agent.run(\n", - " \"I have some code that creates a bug: please debug it and return the final code\",\n", + " \"I have some code that creates a bug: please debug it, then run it to make sure it works and return the final code\",\n", " code=code,\n", ")" ] @@ -549,19 +415,20 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "list=[0, 1, 2]\n", + "my_list = [0, 1, 2]\n", "\n", "for i in range(4):\n", - " print(list(i))\n", - "\n" + " if i < len(my_list):\n", + " print(my_list[i])\n", + " else:\n", + " print(\"Index out of range\")\n" ] } ], @@ -724,9 +591,9 @@ ], "metadata": { "kernelspec": { - "display_name": "disposable", + "display_name": "cookbook2", "language": "python", - "name": "python3" + "name": "cookbook2" }, "language_info": { "codemirror_mode": { @@ -738,7 +605,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.12.0" } }, "nbformat": 4, diff --git a/notebooks/en/multiagent_web_assistant.ipynb b/notebooks/en/multiagent_web_assistant.ipynb index 1cbe9b60..1c75f43e 100644 --- a/notebooks/en/multiagent_web_assistant.ipynb +++ b/notebooks/en/multiagent_web_assistant.ipynb @@ -43,35 +43,23 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install markdownify duckduckgo-search \"git+https://github.com/huggingface/transformers.git#egg=transformers[agents]\"" + "!pip install markdownify duckduckgo-search \"transformers[agents]\" --upgrade -q" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We will choose to have our model powered by [Qwen/Qwen2.5-72B-Instruct](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct) since it's very powerful and available for free in the HF API." ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 20, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The token has not been saved to the git credentials helper. Pass `add_to_git_credential=True` in this function directly or `--add-to-git-credential` if using via `huggingface-cli` if you want to set the git credential as well.\n", - "Token is valid (permission: fineGrained).\n", - "Your token has been saved to /Users/aymeric/.cache/huggingface/token\n", - "Login successful\n" - ] - } - ], + "outputs": [], "source": [ - "from huggingface_hub import login\n", - "from dotenv import load_dotenv\n", - "import os\n", - "\n", - "load_dotenv()\n", - "\n", - "login(os.getenv(\"HUGGINGFACEHUB_API_TOKEN\"))\n", - "\n", - "model = \"meta-llama/Meta-Llama-3.1-70B-Instruct\"" + "model = \"Qwen/Qwen2.5-72B-Instruct\"" ] }, { @@ -90,46 +78,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "from transformers import Tool\n", + "import re\n", "import requests\n", "from markdownify import markdownify as md\n", "from requests.exceptions import RequestException\n", - "import re\n", + "from transformers.agents import tool\n", + "\n", "\n", + "@tool\n", + "def visit_webpage(url: str) -> str:\n", + " \"\"\"Visits a webpage at the given URL and returns its content as a markdown string.\n", "\n", - "class VisitWebpageTool(Tool):\n", - " name = \"visit_webpage\"\n", - " description = \"Visits a webpage at the given url and returns its content as a markdown string.\"\n", - " inputs = {\n", - " \"url\": {\n", - " \"type\": \"text\",\n", - " \"description\": \"The url of the webpage to visit.\",\n", - " }\n", - " }\n", - " output_type = \"text\"\n", + " Args:\n", + " url: The URL of the webpage to visit.\n", "\n", - " def forward(self, url: str) -> str:\n", - " try:\n", - " # Send a GET request to the URL\n", - " response = requests.get(url)\n", - " response.raise_for_status() # Raise an exception for bad status codes\n", + " Returns:\n", + " The content of the webpage converted to Markdown, or an error message if the request fails.\n", + " \"\"\"\n", + " try:\n", + " # Send a GET request to the URL\n", + " response = requests.get(url)\n", + " response.raise_for_status() # Raise an exception for bad status codes\n", "\n", - " # Convert the HTML content to Markdown\n", - " markdown_content = md(response.text).strip()\n", + " # Convert the HTML content to Markdown\n", + " markdown_content = md(response.text).strip()\n", "\n", - " # Remove multiple line breaks\n", - " markdown_content = re.sub(r\"\\n{3,}\", \"\\n\\n\", markdown_content)\n", + " # Remove multiple line breaks\n", + " markdown_content = re.sub(r\"\\n{3,}\", \"\\n\\n\", markdown_content)\n", "\n", - " return markdown_content\n", + " return markdown_content\n", "\n", - " except RequestException as e:\n", - " return f\"Error fetching the webpage: {str(e)}\"\n", - " except Exception as e:\n", - " return f\"An unexpected error occurred: {str(e)}\"" + " except RequestException as e:\n", + " return f\"Error fetching the webpage: {str(e)}\"\n", + " except Exception as e:\n", + " return f\"An unexpected error occurred: {str(e)}\"" ] }, { @@ -141,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -166,312 +152,12 @@ "* [Current events](/wiki/Portal:Current_events \"Articles related to current events\")\n", "* [Random article](/wiki/Special:Random \"Visit a randomly selected article [x]\")\n", "* [About Wikipedia](/wiki/Wikipedia:About \"Learn about Wikipedia and how it works\")\n", - "* [Contact us](//en.wikipedia.org/wiki/Wikipedia:Contact_us \"How to contact Wikipedia\")\n", - "* [Donate](https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en \"Support us by donating to the Wikimedia Foundation\")\n", - "\n", - " Contribute\n", - " \n", - "\n", - "* [Help](/wiki/Help:Contents \"Guidance on how to use and edit Wikipedia\")\n", - "* [Learn to edit](/wiki/Help:Introduction \"Learn how to edit Wikipedia\")\n", - "* [Community portal](/wiki/Wikipedia:Community_portal \"The hub for editors\")\n", - "* [Recent changes](/wiki/Special:RecentChanges \"A list of recent changes to Wikipedia [r]\")\n", - "* [Upload file](/wiki/Wikipedia:File_upload_wizard \"Add images or other media for use on Wikipedia\")\n", - "\n", - "[![](/static/images/icons/wikipedia.png)\n", - "\n", - "![Wikipedia](/static/images/mobile/copyright/wikipedia-wordmark-en.svg)\n", - "![The Free Encyclopedia](/static/images/mobile/copyright/wikipedia-tagline-en.svg)](/wiki/Main_Page)\n", - "\n", - "[Search](/wiki/Special:Search \"Search Wikipedia [f]\")\n", - "\n", - "Search\n", - "\n", - "Appearance\n", - "\n", - "* [Create account](/w/index.php?title=Special:CreateAccount&returnto=Hugging+Face \"You are encouraged to create an account and log in; however, it is not mandatory\")\n", - "* [Log in](/w/index.php?title=Special:UserLogin&returnto=Hugging+Face \"You're encouraged to log in; however, it's not mandatory. [o]\")\n", - "\n", - "Personal tools\n", - "\n", - "* [Create account](/w/index.php?title=Special:CreateAccount&returnto=Hugging+Face \"You are encouraged to create an account and log in; however, it is not mandatory\")\n", - "* [Log in](/w/index.php?title=Special:UserLogin&returnto=Hugging+Face \"You're encouraged to log in; however, it's not mandatory. [o]\")\n", - "\n", - " Pages for logged out editors [learn more](/wiki/Help:Introduction)\n", - "\n", - "* [Contributions](/wiki/Special:MyContributions \"A list of edits made from this IP address [y]\")\n", - "* [Talk](/wiki/Special:MyTalk \"Discussion about edits from this IP address [n]\")\n", - "\n", - "Contents\n", - "--------\n", - "\n", - "move to sidebar\n", - "hide\n", - "\n", - "* [(Top)](#)\n", - "* [1\n", - "History](#History)\n", - "* [2\n", - "Services and technologies](#Services_and_technologies)\n", - "\n", - "Toggle Services and technologies subsection\n", - "\n", - "\t+ [2\\.1\n", - "\tTransformers Library](#Transformers_Library)\n", - "\t+ [2\\.2\n", - "\tHugging Face Hub](#Hugging_Face_Hub)\n", - "\t+ [2\\.3\n", - "\tOther libraries](#Other_libraries)\n", - "* [3\n", - "See also](#See_also)\n", - "* [4\n", - "References](#References)\n", - "\n", - "Toggle the table of contents\n", - "\n", - "Hugging Face\n", - "============\n", - "\n", - "18 languages\n", - "\n", - "* [Català](https://ca.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Catalan\")\n", - "* [Deutsch](https://de.wikipedia.org/wiki/Hugging_Face \"Hugging Face – German\")\n", - "* [Español](https://es.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Spanish\")\n", - "* [Euskara](https://eu.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Basque\")\n", - "* [فارسی](https://fa.wikipedia.org/wiki/%D9%87%D8%A7%DA%AF%DB%8C%D9%86%DA%AF_%D9%81%DB%8C%D8%B3 \"هاگینگ فیس – Persian\")\n", - "* [Français](https://fr.wikipedia.org/wiki/Hugging_Face \"Hugging Face – French\")\n", - "* [한국어](https://ko.wikipedia.org/wiki/%ED%97%88%EA%B9%85_%ED%8E%98%EC%9D%B4%EC%8A%A4 \"허깅 페이스 – Korean\")\n", - "* [Bahasa Indonesia](https://id.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Indonesian\")\n", - "* [עברית](https://he.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Hebrew\")\n", - "* [Nederlands](https://nl.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Dutch\")\n", - "* [日本語](https://ja.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Japanese\")\n", - "* [Português](https://pt.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Portuguese\")\n", - "* [Runa Simi](https://qu.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Quechua\")\n", - "* [Русский](https://ru.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Russian\")\n", - "* [Suomi](https://fi.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Finnish\")\n", - "* [Türkçe](https://tr.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Turkish\")\n", - "* [Українська](https://uk.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Ukrainian\")\n", - "* [中文](https://zh.wikipedia.org/wiki/Hugging_Face \"Hugging Face – Chinese\")\n", - "\n", - "[Edit links](https://www.wikidata.org/wiki/Special:EntityPage/Q108943604#sitelinks-wikipedia \"Edit interlanguage links\")\n", - "\n", - "* [Article](/wiki/Hugging_Face \"View the content page [c]\")\n", - "* [Talk](/wiki/Talk:Hugging_Face \"Discuss improvements to the content page [t]\")\n", - "\n", - "English\n", - "\n", - "* [Read](/wiki/Hugging_Face)\n", - "* [Edit](/w/index.php?title=Hugging_Face&action=edit \"Edit this page [e]\")\n", - "* [View history](/w/index.php?title=Hugging_Face&action=history \"Past revisions of this page [h]\")\n", - "\n", - "Tools\n", - "\n", - "Tools\n", - "move to sidebar\n", - "hide\n", - "\n", - " Actions\n", - " \n", - "\n", - "* [Read](/wiki/Hugging_Face)\n", - "* [Edit](/w/index.php?title=Hugging_Face&action=edit \"Edit this page [e]\")\n", - "* [View history](/w/index.php?title=Hugging_Face&action=history)\n", - "\n", - " General\n", - " \n", - "\n", - "* [What links here](/wiki/Special:WhatLinksHere/Hugging_Face \"List of all English Wikipedia pages containing links to this page [j]\")\n", - "* [Related changes](/wiki/Special:RecentChangesLinked/Hugging_Face \"Recent changes in pages linked from this page [k]\")\n", - "* [Upload file](/wiki/Wikipedia:File_Upload_Wizard \"Upload files [u]\")\n", - "* [Special pages](/wiki/Special:SpecialPages \"A list of all special pages [q]\")\n", - "* [Permanent link](/w/index.php?title=Hugging_Face&oldid=1238858455 \"Permanent link to this revision of this page\")\n", - "* [Page information](/w/index.php?title=Hugging_Face&action=info \"More information about this page\")\n", - "* [Cite this page](/w/index.php?title=Special:CiteThisPage&page=Hugging_Face&id=1238858455&wpFormIdentifier=titleform \"Information on how to cite this page\")\n", - "* [Get shortened URL](/w/index.php?title=Special:UrlShortener&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHugging_Face)\n", - "* [Download QR code](/w/index.php?title=Special:QrCode&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHugging_Face)\n", - "* [Wikidata item](https://www.wikidata.org/wiki/Special:EntityPage/Q108943604 \"Structured data on this page hosted by Wikidata [g]\")\n", - "\n", - " Print/export\n", - " \n", - "\n", - "* [Download as PDF](/w/index.php?title=Special:DownloadAsPdf&page=Hugging_Face&action=show-download-screen \"Download this page as a PDF file\")\n", - "* [Printable version](/w/index.php?title=Hugging_Face&printable=yes \"Printable version of this page [p]\")\n", - "\n", - " In other projects\n", - " \n", - "\n", - "* [Wikimedia Commons](https://commons.wikimedia.org/wiki/Category:Hugging_Face)\n", - "\n", - "Appearance\n", - "move to sidebar\n", - "hide\n", - "\n", - "From Wikipedia, the free encyclopedia\n", - "\n", - "American software company\n", - "This article is about the company. For the emoji, see [Emoji](/wiki/Emoji \"Emoji\").\n", - "\n", - "| | This article **relies excessively on [references](/wiki/Wikipedia:Verifiability \"Wikipedia:Verifiability\") to [primary sources](/wiki/Wikipedia:No_original_research#Primary,_secondary_and_tertiary_sources \"Wikipedia:No original research\")**. Please improve this article by adding [secondary or tertiary sources](/wiki/Wikipedia:No_original_research#Primary,_secondary_and_tertiary_sources \"Wikipedia:No original research\"). *Find sources:* [\"Hugging Face\"](https://www.google.com/search?as_eq=wikipedia&q=%22Hugging+Face%22) – [news](https://www.google.com/search?tbm=nws&q=%22Hugging+Face%22+-wikipedia&tbs=ar:1) **·** [newspapers](https://www.google.com/search?&q=%22Hugging+Face%22&tbs=bkt:s&tbm=bks) **·** [books](https://www.google.com/search?tbs=bks:1&q=%22Hugging+Face%22+-wikipedia) **·** [scholar](https://scholar.google.com/scholar?q=%22Hugging+Face%22) **·** [JSTOR](https://www.jstor.org/action/doBasicSearch?Query=%22Hugging+Face%22&acc=on&wc=on) *(February 2023)* *([Learn how and when to remove this message](/wiki/Help:Maintenance_template_removal \"Help:Maintenance template removal\"))* |\n", - "| --- | --- |\n", - "\n", - "Hugging Face, Inc.\n", - "| | |\n", - "| --- | --- |\n", - "| Company type | [Private](/wiki/Privately_held_company \"Privately held company\") |\n", - "| Industry | [Artificial intelligence](/wiki/Artificial_intelligence \"Artificial intelligence\"), [machine learning](/wiki/Machine_learning \"Machine learning\"), [software development](/wiki/Software_development \"Software development\") |\n", - "| Founded | 2016; 8 years ago (2016) |\n", - "| Headquarters | [Manhattan](/wiki/Manhattan \"Manhattan\"), [New York City](/wiki/New_York_City \"New York City\") |\n", - "| Area served | Worldwide |\n", - "| Key people | * Clément Delangue (CEO) * Julien Chaumond (CTO) * Thomas Wolf (CSO) |\n", - "| Products | Models, datasets, spaces |\n", - "| Revenue | 15,000,000 United States dollar (2022\\) [Edit this on Wikidata](https://www.wikidata.org/wiki/Q108943604?uselang=en#P2139 \"Edit this on Wikidata\") |\n", - "| Number of employees | 170 (2023\\) [Edit this on Wikidata](https://www.wikidata.org/wiki/Q108943604?uselang=en#P1128 \"Edit this on Wikidata\") |\n", - "| Website | [huggingface.co](https://huggingface.co/) |\n", - "\n", - "**Hugging Face, Inc.** is an American company incorporated under the [Delaware General Corporation Law](/wiki/Delaware_General_Corporation_Law \"Delaware General Corporation Law\")[\\[1]](#cite_note-1) and based in [New York City](/wiki/List_of_tech_companies_in_the_New_York_metropolitan_area \"List of tech companies in the New York metropolitan area\") that develops [computation](/wiki/Computation \"Computation\") tools for building applications using [machine learning](/wiki/Machine_learning \"Machine learning\"). It is most notable for its [transformers](/wiki/Transformer_(machine_learning_model) \"Transformer (machine learning model)\") [library](/wiki/Software_libraries \"Software libraries\") built for [natural language processing](/wiki/Natural_language_processing \"Natural language processing\") applications and its platform that allows users to share machine learning models and [datasets](/wiki/Dataset_(machine_learning) \"Dataset (machine learning)\") and showcase their work.\n", - "\n", - "History\n", - "-------\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=1 \"Edit section: History\")]\n", - "The company was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf in [New York City](/wiki/New_York_City \"New York City\"), originally as a company that developed a [chatbot](/wiki/Chatbot \"Chatbot\") app targeted at teenagers.[\\[2]](#cite_note-:0-2) The company was named after the \"hugging face\" [emoji](/wiki/Emoji \"Emoji\").[\\[2]](#cite_note-:0-2) After [open sourcing](/wiki/Open-source_software \"Open-source software\") the model behind the chatbot, the company [pivoted](/wiki/Lean_startup \"Lean startup\") to focus on being a platform for machine learning.\n", - "\n", - "In March 2021, Hugging Face raised US$40 million in a [Series B](/wiki/Series_B \"Series B\") funding round.[\\[3]](#cite_note-3)\n", - "\n", - "On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open [large language model](/wiki/Large_language_model \"Large language model\").[\\[4]](#cite_note-4) In 2022, the workshop concluded with the announcement of [BLOOM](/wiki/BLOOM_(language_model) \"BLOOM (language model)\"), a multilingual large language model with 176 billion parameters.[\\[5]](#cite_note-5)[\\[6]](#cite_note-6)\n", - "\n", - "In December 2022, the company acquired Gradio, an open source library built for developing machine learning applications in Python.[\\[7]](#cite_note-7)\n", - "\n", - "On May 5, 2022, the company announced its [Series C](/wiki/Series_C \"Series C\") funding round led by [Coatue](/wiki/Coatue_Management \"Coatue Management\") and [Sequoia](/wiki/Sequoia_fund \"Sequoia fund\").[\\[8]](#cite_note-8) The company received a $2 billion valuation.\n", - "\n", - "On August 3, 2022, the company announced the Private Hub, an enterprise version of its public Hugging Face Hub that supports [SaaS](/wiki/Software_as_a_service \"Software as a service\") or [on\\-premises](/wiki/On-premises_software \"On-premises software\") deployment.[\\[9]](#cite_note-9)\n", - "\n", - "In February 2023, the company announced partnership with [Amazon Web Services](/wiki/Amazon_Web_Services \"Amazon Web Services\") (AWS) which would allow Hugging Face's products available to AWS customers to use them as the building blocks for their custom applications. The company also said the next generation of BLOOM will be run on Trainium, a proprietary [machine learning chip](/wiki/Machine_learning_hardware \"Machine learning hardware\") created by AWS.[\\[10]](#cite_note-10)[\\[11]](#cite_note-11)[\\[12]](#cite_note-12)\n", - "\n", - "In August 2023, the company announced that it raised $235 million in a [Series D](/wiki/Series_D \"Series D\") funding, at a $4\\.5 billion valuation. The funding was led by [Salesforce](/wiki/Salesforce \"Salesforce\"), and notable participation came from [Google](/wiki/Google \"Google\"), [Amazon](/wiki/Amazon_(company) \"Amazon (company)\"), [Nvidia](/wiki/Nvidia \"Nvidia\"), [AMD](/wiki/AMD \"AMD\"), [Intel](/wiki/Intel \"Intel\"), [IBM](/wiki/IBM \"IBM\"), and [Qualcomm](/wiki/Qualcomm \"Qualcomm\").[\\[13]](#cite_note-13)\n", - "\n", - "In June 2024, the company announced, along with [Meta](/wiki/Meta_Platforms \"Meta Platforms\") and [Scaleway](/wiki/Scaleway \"Scaleway\"), their launch of a new AI accelerator program for European startups. This initiative aims to help startups integrate open foundation models into their products, accelerating the EU AI ecosystem. The program, based at STATION F in Paris, will run from September 2024 to February 2025\\. Selected startups will receive mentoring, access to AI models and tools, and Scaleway’s computing power.[\\[14]](#cite_note-14)\n", - "\n", - "Services and technologies\n", - "-------------------------\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=2 \"Edit section: Services and technologies\")]\n", - "### Transformers Library\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=3 \"Edit section: Transformers Library\")]\n", - "The Transformers library is a [Python](/wiki/Python_(programming_language) \"Python (programming language)\") package that contains open\\-source implementations of [transformer](/wiki/Transformer_(machine_learning_model) \"Transformer (machine learning model)\") models for text, image, and audio tasks. It is compatible with the [PyTorch](/wiki/PyTorch \"PyTorch\"), [TensorFlow](/wiki/TensorFlow \"TensorFlow\") and [JAX](/wiki/Google_JAX \"Google JAX\") [deep learning](/wiki/Deep_learning \"Deep learning\") libraries and includes implementations of notable models like [BERT](/wiki/BERT_(language_model) \"BERT (language model)\") and [GPT\\-2](/wiki/GPT-2 \"GPT-2\").[\\[15]](#cite_note-15) The library was originally called \"pytorch\\-pretrained\\-bert\"[\\[16]](#cite_note-16) which was then renamed to \"pytorch\\-transformers\" and finally \"transformers.\"\n", - "\n", - "A [javascript](/wiki/JavaScript \"JavaScript\") version (transformers.js[\\[17]](#cite_note-17)) have also been developed, allowing to run models directly in the browser.\n", - "\n", - "### Hugging Face Hub\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=4 \"Edit section: Hugging Face Hub\")]\n", - "The Hugging Face Hub is a platform (centralized [web service](/wiki/Web_service \"Web service\")) for hosting:[\\[18]](#cite_note-18)\n", - "\n", - "* [Git](/wiki/Git \"Git\")\\-based [code repositories](/wiki/Repository_(version_control) \"Repository (version control)\"), including discussions and pull requests for projects.\n", - "* models, also with Git\\-based version control;\n", - "* datasets, mainly in text, images, and audio;\n", - "* web applications (\"spaces\" and \"widgets\"), intended for small\\-scale demos of machine learning applications.\n", - "\n", - "There are numerous pre\\-trained models that support common tasks in different modalities, such as:\n", - "\n", - "* [Natural Language Processing](/wiki/Natural_language_processing \"Natural language processing\"): text classification, named entity recognition, question answering, language modeling, summarization, translation, multiple choice, and text generation.\n", - "* [Computer Vision](/wiki/Computer_vision \"Computer vision\"): image classification, object detection, and segmentation.\n", - "* Audio: automatic speech recognition and audio classification.\n", - "\n", - "### Other libraries\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=5 \"Edit section: Other libraries\")]\n", - "[![](//upload.wikimedia.org/wikipedia/commons/thumb/2/29/Gradio_example.png/220px-Gradio_example.png)](/wiki/File:Gradio_example.png)\n", - "\n", - "Gradio UI Example\n", - "\n", - "In addition to Transformers and the Hugging Face Hub, the Hugging Face ecosystem contains libraries for other tasks, such as [dataset processing](/wiki/Data_processing \"Data processing\") (\"Datasets\"), model evaluation (\"Evaluate\"), and machine learning demos (\"Gradio\").[\\[19]](#cite_note-19)\n", - "\n", - "See also\n", - "--------\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=6 \"Edit section: See also\")]\n", - "* [OpenAI](/wiki/OpenAI \"OpenAI\")\n", - "* [Station F](/wiki/Station_F \"Station F\")\n", - "\n", - "References\n", - "----------\n", - "\n", - "\\[[edit](/w/index.php?title=Hugging_Face&action=edit§ion=7 \"Edit section: References\")]\n", - "\n", - "1. **[^](#cite_ref-1)** [\"Terms of Service – Hugging Face\"](https://huggingface.co/terms-of-service). *huggingface.co*. Retrieved 2024\\-05\\-24.\n", - "2. ^ [***a***](#cite_ref-:0_2-0) [***b***](#cite_ref-:0_2-1) [\"Hugging Face wants to become your artificial BFF\"](https://techcrunch.com/2017/03/09/hugging-face-wants-to-become-your-artificial-bff/). *TechCrunch*. 9 March 2017\\. [Archived](https://web.archive.org/web/20220925012620/https://techcrunch.com/2017/03/09/hugging-face-wants-to-become-your-artificial-bff/) from the original on 2022\\-09\\-25. Retrieved 2023\\-09\\-17.\n", - "3. **[^](#cite_ref-3)** [\"Hugging Face raises $40 million for its natural language processing library\"](https://techcrunch.com/2021/03/11/hugging-face-raises-40-million-for-its-natural-language-processing-library). 11 March 2021\\. [Archived](https://web.archive.org/web/20230728113102/https://techcrunch.com/2021/03/11/hugging-face-raises-40-million-for-its-natural-language-processing-library/) from the original on 28 July 2023. Retrieved 5 August 2022.\n", - "4. **[^](#cite_ref-4)** [\"Inside BigScience, the quest to build a powerful open language model\"](https://venturebeat.com/2022/01/10/inside-bigscience-the-quest-to-build-a-powerful-open-language-model/). 10 January 2022\\. [Archived](https://web.archive.org/web/20220701073233/https://venturebeat.com/2022/01/10/inside-bigscience-the-quest-to-build-a-powerful-open-language-model/) from the original on 1 July 2022. Retrieved 5 August 2022.\n", - "5. **[^](#cite_ref-5)** [\"BLOOM\"](https://bigscience.huggingface.co/blog/bloom). *bigscience.huggingface.co*. [Archived](https://web.archive.org/web/20221114122342/https://bigscience.huggingface.co/blog/bloom) from the original on 2022\\-11\\-14. Retrieved 2022\\-08\\-20.\n", - "6. **[^](#cite_ref-6)** [\"Inside a radical new project to democratize AI\"](https://www.technologyreview.com/2022/07/12/1055817/inside-a-radical-new-project-to-democratize-ai/). *MIT Technology Review*. [Archived](https://web.archive.org/web/20221204184214/https://www.technologyreview.com/2022/07/12/1055817/inside-a-radical-new-project-to-democratize-ai/) from the original on 2022\\-12\\-04. Retrieved 2023\\-08\\-25.\n", - "7. **[^](#cite_ref-7)** Nataraj, Poornima (2021\\-12\\-23\\). [\"Hugging Face Acquires Gradio, A Customizable UI Components Library For Python\"](https://analyticsindiamag.com/hugging-face-acquires-gradio-a-customizable-ui-components-library-for-python/). *Analytics India Magazine*. Retrieved 2024\\-01\\-26.\n", - "8. **[^](#cite_ref-8)** Cai, Kenrick. [\"The $2 Billion Emoji: Hugging Face Wants To Be Launchpad For A Machine Learning Revolution\"](https://www.forbes.com/sites/kenrickcai/2022/05/09/the-2-billion-emoji-hugging-face-wants-to-be-launchpad-for-a-machine-learning-revolution/). *Forbes*. [Archived](https://web.archive.org/web/20221103121236/https://www.forbes.com/sites/kenrickcai/2022/05/09/the-2-billion-emoji-hugging-face-wants-to-be-launchpad-for-a-machine-learning-revolution/) from the original on 2022\\-11\\-03. Retrieved 2022\\-08\\-20.\n", - "9. **[^](#cite_ref-9)** [\"Introducing the Private Hub: A New Way to Build With Machine Learning\"](https://huggingface.co/blog/introducing-private-hub). *huggingface.co*. [Archived](https://web.archive.org/web/20221114122333/https://huggingface.co/blog/introducing-private-hub) from the original on 2022\\-11\\-14. Retrieved 2022\\-08\\-20.\n", - "10. **[^](#cite_ref-10)** Bass, Dina (2023\\-02\\-21\\). [\"Amazon's Cloud Unit Partners With Startup Hugging Face as AI Deals Heat Up\"](https://www.bloomberg.com/news/articles/2023-02-21/amazon-s-aws-joins-with-ai-startup-hugging-face-as-chatgpt-competition-heats-up). *[Bloomberg News](/wiki/Bloomberg_News \"Bloomberg News\")*. [Archived](https://web.archive.org/web/20230522030130/https://www.bloomberg.com/news/articles/2023-02-21/amazon-s-aws-joins-with-ai-startup-hugging-face-as-chatgpt-competition-heats-up) from the original on 2023\\-05\\-22. Retrieved 2023\\-02\\-22.\n", - "11. **[^](#cite_ref-11)** Nellis, Stephen (2023\\-02\\-21\\). [\"Amazon Web Services pairs with Hugging Face to target AI developers\"](https://www.reuters.com/technology/amazon-web-services-pairs-with-hugging-face-target-ai-developers-2023-02-21/). *Reuters*. [Archived](https://web.archive.org/web/20230530091325/https://www.reuters.com/technology/amazon-web-services-pairs-with-hugging-face-target-ai-developers-2023-02-21/) from the original on 2023\\-05\\-30. Retrieved 2023\\-02\\-22.\n", - "12. **[^](#cite_ref-12)** [\"AWS and Hugging Face collaborate to make generative AI more accessible and cost efficient \\| AWS Machine Learning Blog\"](https://aws.amazon.com/blogs/machine-learning/aws-and-hugging-face-collaborate-to-make-generative-ai-more-accessible-and-cost-efficient/). *aws.amazon.com*. 2023\\-02\\-21\\. [Archived](https://web.archive.org/web/20230825202343/https://aws.amazon.com/blogs/machine-learning/aws-and-hugging-face-collaborate-to-make-generative-ai-more-accessible-and-cost-efficient/) from the original on 2023\\-08\\-25. Retrieved 2023\\-08\\-25.\n", - "13. **[^](#cite_ref-13)** Leswing, Kif (2023\\-08\\-24\\). [\"Google, Amazon, Nvidia and other tech giants invest in AI startup Hugging Face, sending its valuation to $4\\.5 billion\"](https://www.cnbc.com/2023/08/24/google-amazon-nvidia-amd-other-tech-giants-invest-in-hugging-face.html). *CNBC*. [Archived](https://web.archive.org/web/20230824141538/https://www.cnbc.com/2023/08/24/google-amazon-nvidia-amd-other-tech-giants-invest-in-hugging-face.html) from the original on 2023\\-08\\-24. Retrieved 2023\\-08\\-24.\n", - "14. **[^](#cite_ref-14)** [\"META Collaboration Launches AI Accelerator for European Startups\"](https://finance.yahoo.com/news/meta-collaboration-launches-ai-accelerator-151500146.html). *Yahoo Finance*. 2024\\-06\\-25. Retrieved 2024\\-07\\-11.\n", - "15. **[^](#cite_ref-15)** [\"🤗 Transformers\"](https://huggingface.co/docs/transformers/index). *huggingface.co*. [Archived](https://web.archive.org/web/20230927023923/https://huggingface.co/docs/transformers/index) from the original on 2023\\-09\\-27. Retrieved 2022\\-08\\-20.\n", - "16. **[^](#cite_ref-16)** [\"First release\"](https://github.com/huggingface/transformers/releases/tag/v0.1.2). *GitHub*. Nov 17, 2018\\. [Archived](https://web.archive.org/web/20230430011038/https://github.com/huggingface/transformers/releases/tag/v0.1.2) from the original on 30 April 2023. Retrieved 28 March 2023.\n", - "17. **[^](#cite_ref-17)** [\"xenova/transformers.js\"](https://github.com/xenova/transformers.js). *GitHub*.\n", - "18. **[^](#cite_ref-18)** [\"Hugging Face Hub documentation\"](https://huggingface.co/docs/hub/index). *huggingface.co*. [Archived](https://web.archive.org/web/20230920185949/https://huggingface.co/docs/hub/index) from the original on 2023\\-09\\-20. Retrieved 2022\\-08\\-20.\n", - "19. **[^](#cite_ref-19)** [\"Hugging Face \\- Documentation\"](https://huggingface.co/docs). *huggingface.co*. [Archived](https://web.archive.org/web/20230930074626/https://huggingface.co/docs) from the original on 2023\\-09\\-30. Retrieved 2023\\-02\\-18.\n", - "\n", - "| * [v](/wiki/Template:Differentiable_computing \"Template:Differentiable computing\") * [t](/wiki/Template_talk:Differentiable_computing \"Template talk:Differentiable computing\") * [e](/wiki/Special:EditPage/Template:Differentiable_computing \"Special:EditPage/Template:Differentiable computing\") Differentiable computing | |\n", - "| --- | --- |\n", - "| [General](/wiki/Differentiable_function \"Differentiable function\") | * **[Differentiable programming](/wiki/Differentiable_programming \"Differentiable programming\")** * [Information geometry](/wiki/Information_geometry \"Information geometry\") * [Statistical manifold](/wiki/Statistical_manifold \"Statistical manifold\") * [Automatic differentiation](/wiki/Automatic_differentiation \"Automatic differentiation\") * [Neuromorphic engineering](/wiki/Neuromorphic_engineering \"Neuromorphic engineering\") * [Pattern recognition](/wiki/Pattern_recognition \"Pattern recognition\") * [Tensor calculus](/wiki/Tensor_calculus \"Tensor calculus\") * [Computational learning theory](/wiki/Computational_learning_theory \"Computational learning theory\") * [Inductive bias](/wiki/Inductive_bias \"Inductive bias\") |\n", - "| Concepts | * [Gradient descent](/wiki/Gradient_descent \"Gradient descent\") \t+ [SGD](/wiki/Stochastic_gradient_descent \"Stochastic gradient descent\") * [Clustering](/wiki/Cluster_analysis \"Cluster analysis\") * [Regression](/wiki/Regression_analysis \"Regression analysis\") \t+ [Overfitting](/wiki/Overfitting \"Overfitting\") * [Hallucination](/wiki/Hallucination_(artificial_intelligence) \"Hallucination (artificial intelligence)\") * [Adversary](/wiki/Adversarial_machine_learning \"Adversarial machine learning\") * [Attention](/wiki/Attention_(machine_learning) \"Attention (machine learning)\") * [Convolution](/wiki/Convolution \"Convolution\") * [Loss functions](/wiki/Loss_functions_for_classification \"Loss functions for classification\") * [Backpropagation](/wiki/Backpropagation \"Backpropagation\") * [Batchnorm](/wiki/Batch_normalization \"Batch normalization\") * [Activation](/wiki/Activation_function \"Activation function\") \t+ [Softmax](/wiki/Softmax_function \"Softmax function\") \t+ [Sigmoid](/wiki/Sigmoid_function \"Sigmoid function\") \t+ [Rectifier](/wiki/Rectifier_(neural_networks) \"Rectifier (neural networks)\") * [Regularization](/wiki/Regularization_(mathematics) \"Regularization (mathematics)\") * [Datasets](/wiki/Training,_validation,_and_test_sets \"Training, validation, and test sets\") \t+ [Augmentation](/wiki/Data_augmentation \"Data augmentation\") * [Diffusion](/wiki/Diffusion_process \"Diffusion process\") * [Autoregression](/wiki/Autoregressive_model \"Autoregressive model\") |\n", - "| Applications | * [Machine learning](/wiki/Machine_learning \"Machine learning\") \t+ [In\\-context learning](/wiki/Prompt_engineering#In-context_learning \"Prompt engineering\") * [Artificial neural network](/wiki/Artificial_neural_network \"Artificial neural network\") \t+ [Deep learning](/wiki/Deep_learning \"Deep learning\") * [Scientific computing](/wiki/Computational_science \"Computational science\") * [Artificial Intelligence](/wiki/Artificial_intelligence \"Artificial intelligence\") * [Language model](/wiki/Language_model \"Language model\") \t+ [Large language model](/wiki/Large_language_model \"Large language model\") |\n", - "| Hardware | * [IPU](/wiki/Graphcore \"Graphcore\") * [TPU](/wiki/Tensor_Processing_Unit \"Tensor Processing Unit\") * [VPU](/wiki/Vision_processing_unit \"Vision processing unit\") * [Memristor](/wiki/Memristor \"Memristor\") * [SpiNNaker](/wiki/SpiNNaker \"SpiNNaker\") |\n", - "| Software libraries | * [TensorFlow](/wiki/TensorFlow \"TensorFlow\") * [PyTorch](/wiki/PyTorch \"PyTorch\") * [Keras](/wiki/Keras \"Keras\") * [Theano](/wiki/Theano_(software) \"Theano (software)\") * [JAX](/wiki/Google_JAX \"Google JAX\") * [Flux.jl](/wiki/Flux_(machine-learning_framework) \"Flux (machine-learning framework)\") * [MindSpore](/wiki/MindSpore \"MindSpore\") |\n", - "| Implementations | | Audio–visual | * [AlexNet](/wiki/AlexNet \"AlexNet\") * [WaveNet](/wiki/WaveNet \"WaveNet\") * [Human image synthesis](/wiki/Human_image_synthesis \"Human image synthesis\") * [HWR](/wiki/Handwriting_recognition \"Handwriting recognition\") * [OCR](/wiki/Optical_character_recognition \"Optical character recognition\") * [Speech synthesis](/wiki/Deep_learning_speech_synthesis \"Deep learning speech synthesis\") * [Speech recognition](/wiki/Speech_recognition \"Speech recognition\") * [Facial recognition](/wiki/Facial_recognition_system \"Facial recognition system\") * [AlphaFold](/wiki/AlphaFold \"AlphaFold\") * [Text\\-to\\-image models](/wiki/Text-to-image_model \"Text-to-image model\") \t+ [DALL\\-E](/wiki/DALL-E \"DALL-E\") \t+ [Midjourney](/wiki/Midjourney \"Midjourney\") \t+ [Stable Diffusion](/wiki/Stable_Diffusion \"Stable Diffusion\") * [Text\\-to\\-video models](/wiki/Text-to-video_model \"Text-to-video model\") \t+ [Sora](/wiki/Sora_(text-to-video_model) \"Sora (text-to-video model)\") \t+ [VideoPoet](/wiki/VideoPoet \"VideoPoet\") * [Whisper](/wiki/Whisper_(speech_recognition_system) \"Whisper (speech recognition system)\") | | --- | --- | | Verbal | * [Word2vec](/wiki/Word2vec \"Word2vec\") * [Seq2seq](/wiki/Seq2seq \"Seq2seq\") * [BERT](/wiki/BERT_(language_model) \"BERT (language model)\") * [Gemini](/wiki/Gemini_(language_model) \"Gemini (language model)\") * [LaMDA](/wiki/LaMDA \"LaMDA\") \t+ [Bard](/wiki/Bard_(chatbot) \"Bard (chatbot)\") * [NMT](/wiki/Neural_machine_translation \"Neural machine translation\") * [Project Debater](/wiki/Project_Debater \"Project Debater\") * [IBM Watson](/wiki/IBM_Watson \"IBM Watson\") * [IBM Watsonx](/wiki/IBM_Watsonx \"IBM Watsonx\") * [Granite](/wiki/IBM_Granite \"IBM Granite\") * [GPT\\-1](/wiki/GPT-1 \"GPT-1\") * [GPT\\-2](/wiki/GPT-2 \"GPT-2\") * [GPT\\-3](/wiki/GPT-3 \"GPT-3\") * [GPT\\-4](/wiki/GPT-4 \"GPT-4\") * [ChatGPT](/wiki/ChatGPT \"ChatGPT\") * [GPT\\-J](/wiki/GPT-J \"GPT-J\") * [Chinchilla AI](/wiki/Chinchilla_AI \"Chinchilla AI\") * [PaLM](/wiki/PaLM \"PaLM\") * [BLOOM](/wiki/BLOOM_(language_model) \"BLOOM (language model)\") * [LLaMA](/wiki/LLaMA \"LLaMA\") * [PanGu\\-Σ](/wiki/Huawei_PanGu \"Huawei PanGu\") | | Decisional | * [AlphaGo](/wiki/AlphaGo \"AlphaGo\") * [AlphaZero](/wiki/AlphaZero \"AlphaZero\") * [Q\\-learning](/wiki/Q-learning \"Q-learning\") * [SARSA](/wiki/State%E2%80%93action%E2%80%93reward%E2%80%93state%E2%80%93action \"State–action–reward–state–action\") * [OpenAI Five](/wiki/OpenAI_Five \"OpenAI Five\") * [Self\\-driving car](/wiki/Self-driving_car \"Self-driving car\") * [MuZero](/wiki/MuZero \"MuZero\") * [Action selection](/wiki/Action_selection \"Action selection\") \t+ [Auto\\-GPT](/wiki/Auto-GPT \"Auto-GPT\") * [Robot control](/wiki/Robot_control \"Robot control\") | |\n", - "| People | * [Yoshua Bengio](/wiki/Yoshua_Bengio \"Yoshua Bengio\") * [Alex Graves](/wiki/Alex_Graves_(computer_scientist) \"Alex Graves (computer scientist)\") * [Ian Goodfellow](/wiki/Ian_Goodfellow \"Ian Goodfellow\") * [Stephen Grossberg](/wiki/Stephen_Grossberg \"Stephen Grossberg\") * [Demis Hassabis](/wiki/Demis_Hassabis \"Demis Hassabis\") * [Geoffrey Hinton](/wiki/Geoffrey_Hinton \"Geoffrey Hinton\") * [Yann LeCun](/wiki/Yann_LeCun \"Yann LeCun\") * [Fei\\-Fei Li](/wiki/Fei-Fei_Li \"Fei-Fei Li\") * [Andrew Ng](/wiki/Andrew_Ng \"Andrew Ng\") * [Jürgen Schmidhuber](/wiki/J%C3%BCrgen_Schmidhuber \"Jürgen Schmidhuber\") * [David Silver](/wiki/David_Silver_(computer_scientist) \"David Silver (computer scientist)\") * [Ilya Sutskever](/wiki/Ilya_Sutskever \"Ilya Sutskever\") |\n", - "| Organizations | * [Anthropic](/wiki/Anthropic \"Anthropic\") * [EleutherAI](/wiki/EleutherAI \"EleutherAI\") * [Google DeepMind](/wiki/Google_DeepMind \"Google DeepMind\") * Hugging Face * [OpenAI](/wiki/OpenAI \"OpenAI\") * [Meta AI](/wiki/Meta_AI \"Meta AI\") * [Mila](/wiki/Mila_(research_institute) \"Mila (research institute)\") * [MIT CSAIL](/wiki/MIT_Computer_Science_and_Artificial_Intelligence_Laboratory \"MIT Computer Science and Artificial Intelligence Laboratory\") * [Huawei](/wiki/Huawei \"Huawei\") |\n", - "| Architectures | * [Neural Turing machine](/wiki/Neural_Turing_machine \"Neural Turing machine\") * [Differentiable neural computer](/wiki/Differentiable_neural_computer \"Differentiable neural computer\") * [Transformer](/wiki/Transformer_(machine_learning_model) \"Transformer (machine learning model)\") * [Recurrent neural network (RNN)](/wiki/Recurrent_neural_network \"Recurrent neural network\") * [Long short\\-term memory (LSTM)](/wiki/Long_short-term_memory \"Long short-term memory\") * [Gated recurrent unit (GRU)](/wiki/Gated_recurrent_unit \"Gated recurrent unit\") * [Echo state network](/wiki/Echo_state_network \"Echo state network\") * [Multilayer perceptron (MLP)](/wiki/Multilayer_perceptron \"Multilayer perceptron\") * [Convolutional neural network](/wiki/Convolutional_neural_network \"Convolutional neural network\") * [Residual neural network](/wiki/Residual_neural_network \"Residual neural network\") * [Mamba](/wiki/Mamba_(deep_learning) \"Mamba (deep learning)\") * [Autoencoder](/wiki/Autoencoder \"Autoencoder\") * [Variational autoencoder (VAE)](/wiki/Variational_autoencoder \"Variational autoencoder\") * [Generative adversarial network (GAN)](/wiki/Generative_adversarial_network \"Generative adversarial network\") * [Graph neural network](/wiki/Graph_neural_network \"Graph neural network\") |\n", - "| * Portals \t+ [Computer programming](/wiki/Portal:Computer_programming \"Portal:Computer programming\") \t+ [Technology](/wiki/Portal:Technology \"Portal:Technology\") * Categories \t+ [Artificial neural networks](/wiki/Category:Artificial_neural_networks \"Category:Artificial neural networks\") \t+ [Machine learning](/wiki/Category:Machine_learning \"Category:Machine learning\") | |\n", - "\n", - "[Portal](/wiki/Wikipedia:Contents/Portals \"Wikipedia:Contents/Portals\"):* ![](//upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Industry5.svg/19px-Industry5.svg.png) [Companies](/wiki/Portal:Companies \"Portal:Companies\")\n", - "\n", - "![](https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1)\n", - "Retrieved from \"[https://en.wikipedia.org/w/index.php?title\\=Hugging\\_Face\\&oldid\\=1238858455](https://en.wikipedia.org/w/index.php?title=Hugging_Face&oldid=1238858455)\"\n", - "[Categories](/wiki/Help:Category \"Help:Category\"): * [Machine learning](/wiki/Category:Machine_learning \"Category:Machine learning\")\n", - "* [Open\\-source artificial intelligence](/wiki/Category:Open-source_artificial_intelligence \"Category:Open-source artificial intelligence\")\n", - "* [Privately held companies based in New York City](/wiki/Category:Privately_held_companies_based_in_New_York_City \"Category:Privately held companies based in New York City\")\n", - "* [American companies established in 2016](/wiki/Category:American_companies_established_in_2016 \"Category:American companies established in 2016\")\n", - "* [2016 establishments in New York City](/wiki/Category:2016_establishments_in_New_York_City \"Category:2016 establishments in New York City\")\n", - "Hidden categories: * [Articles with short description](/wiki/Category:Articles_with_short_description \"Category:Articles with short description\")\n", - "* [Short description is different from Wikidata](/wiki/Category:Short_description_is_different_from_Wikidata \"Category:Short description is different from Wikidata\")\n", - "* [Articles lacking reliable references from February 2023](/wiki/Category:Articles_lacking_reliable_references_from_February_2023 \"Category:Articles lacking reliable references from February 2023\")\n", - "* [All articles lacking reliable references](/wiki/Category:All_articles_lacking_reliable_references \"Category:All articles lacking reliable references\")\n", - "\n", - "* This page was last edited on 6 August 2024, at 01:57 (UTC).\n", - "* Text is available under the [Creative Commons Attribution\\-ShareAlike License 4\\.0](//en.wikipedia.org/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License);\n", - "additional terms may apply. By using this site, you agree to the [Terms of Use](//foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use) and [Privacy Policy](//foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy). Wikipedia® is a registered trademark of the [Wikimedia Foundation, Inc.](//wikimediafoundation.org/), a non\\-profit organization.\n", - "\n", - "* [Privacy policy](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy)\n", - "* [About Wikipedia](/wiki/Wikipedia:About)\n", - "* [Disclaimers](/wiki/Wikipedia:General_disclaimer)\n", - "* [Contact Wikipedia](//en.wikipedia.org/wiki/Wikipedia:Contact_us)\n", - "* [Code of Conduct](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct)\n", - "* [Developers](https://developer.wikimedia.org)\n", - "* [Statistics](https://stats.wikimedia.org/#/en.wikipedia.org)\n", - "* [Cookie statement](https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement)\n", - "* [Mobile view](//en.m.wikipedia.org/w/index.php?title=Hugging_Face&mobileaction=toggle_view_mobile)\n", - "\n", - "* [![Wikimedia Foundation](/static/images/footer/wikimedia-button.svg)](https://wikimediafoundation.org/)\n", - "* [![Powered by MediaWiki](/w/resources/assets/poweredby_mediawiki.svg)](https://www.mediawiki.org/)\n", - "\n", - "*\n" + "* [Co\n" ] } ], "source": [ - "visit_page_tool = VisitWebpageTool()\n", - "\n", - "print(visit_page_tool(\"https://en.wikipedia.org/wiki/Hugging_Face\"))" + "print(visit_webpage(\"https://en.wikipedia.org/wiki/Hugging_Face\")[:500])" ] }, { @@ -489,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -504,7 +190,7 @@ "llm_engine = HfApiEngine(model)\n", "\n", "web_agent = ReactJsonAgent(\n", - " tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],\n", + " tools=[DuckDuckGoSearchTool(), visit_webpage],\n", " llm_engine=llm_engine,\n", " max_iterations=10,\n", ")" @@ -519,13 +205,13 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "managed_web_agent = ManagedAgent(\n", " agent=web_agent,\n", - " name=\"search_agent\",\n", + " name=\"search\",\n", " description=\"Runs web searches for you. Give it your query as an argument.\",\n", ")" ] @@ -543,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -564,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -574,17 +260,17 @@ "\u001b[32;20;1m======== New task ========\u001b[0m\n", "\u001b[37;1mHow many years ago was Stripe founded?\u001b[0m\n", "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: To determine how many years ago Stripe was founded, I need to find the founding year of Stripe. I can use the search_agent to do this.\u001b[0m\n", + "\u001b[0mThought: I need to find out when Stripe was founded and then calculate the number of years since then. I will start by using the `search` tool to find the founding year of Stripe.\u001b[0m\n", "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mfounding_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msearch_agent\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mrequest\u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mWhat year was Stripe founded?\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7mfounding_year\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[0m\u001b[38;5;7mfounding_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7msearch\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mWhen was Stripe founded\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\n", + "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mFounding year:\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m,\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mfounding_year\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[32;20;1m======== New task ========\u001b[0m\n", - "\u001b[37;1mYou're a helpful agent named 'search_agent'.\n", + "\u001b[37;1mYou're a helpful agent named 'search'.\n", "You have been submitted this task by your manager.\n", "---\n", "Task:\n", - "What year was Stripe founded?\n", + "When was Stripe founded\n", "---\n", "You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible so that they have a clear understanding of the answer.\n", "\n", @@ -596,98 +282,58 @@ "Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.\n", "And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.\u001b[0m\n", "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: To answer this question, I can perform a web search using the 'web_search' tool.\u001b[0m\n", - "\u001b[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'Stripe founding year'}\u001b[0m\n", + "\u001b[0mThought: I need to find the founding year of Stripe and related details. The best way to start is by performing a web search.\u001b[0m\n", + "\u001b[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'When was Stripe founded'}\u001b[0m\n", "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: From the web search results, I should be able to find information about Stripe, such as the year it was founded. I'll use the 'visit_webpage' tool to visit one of the webpages returned in the search results to gather more information.\u001b[0m\n", - "\u001b[33;1m>>> Calling tool: 'visit_webpage' with arguments: {'url': 'https://stripe.com/about'}\u001b[0m\n", + "\u001b[0mThought: The search results provide information on when Stripe was founded and additional details about the company. I will now visit the Stripe Wikipedia page for a more detailed overview.\u001b[0m\n", + "\u001b[33;1m>>> Calling tool: 'visit_webpage' with arguments: {'url': 'https://en.wikipedia.org/wiki/Stripe,_Inc.'}\u001b[0m\n", "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: Unfortunately, the webpage provided does not mention the year Stripe was founded.\u001b[0m\n", - "\u001b[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'Stripe founding year'}\u001b[0m\n", - "\u001b[31;20mlist index out of range\u001b[0m\n", - "Traceback (most recent call last):\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 503, in extract_action\n", - " split[-2],\n", - " ~~~~~^^^^\n", - "IndexError: list index out of range\n", - "\u001b[31;20mError: No 'Action:' token provided in your output.\n", - "Your output:\n", - "Thought: The web search results contain information about Stripe's founding year. I will look at the top search result to get the information.\n", - "\n", - "\n", - ". Be sure to include an action, prefaced with 'Action:'!\u001b[0m\n", - "Traceback (most recent call last):\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 503, in extract_action\n", - " split[-2],\n", - " ~~~~~^^^^\n", - "IndexError: list index out of range\n", - "\n", - "During handling of the above exception, another exception occurred:\n", - "\n", - "Traceback (most recent call last):\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 812, in direct_run\n", - " step_logs = self.step()\n", - " ^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 989, in step\n", - " rationale, action = self.extract_action(llm_output=llm_output, split_token=\"Action:\")\n", - " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", - " File \"/Users/aymeric/Documents/Code/original_transformers/transformers/src/transformers/agents/agents.py\", line 508, in extract_action\n", - " raise AgentParsingError(\n", - "transformers.agents.agents.AgentParsingError: Error: No 'Action:' token provided in your output.\n", - "Your output:\n", - "Thought: The web search results contain information about Stripe's founding year. I will look at the top search result to get the information.\n", - "\n", - "\n", - ". Be sure to include an action, prefaced with 'Action:'!\n", - "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: The web search results contain information about Stripe's founding year. I will look at the top search result to get the information.\u001b[0m\n", - "\u001b[33;1m>>> Calling tool: 'web_search' with arguments: {'query': 'When was Stripe founded?'}\u001b[0m\n", - "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: Based on the search results, I found that Stripe was founded in 2010.\u001b[0m\n", - "\u001b[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': '### 1. Task outcome (short version):\\nStripe was founded in 2010.\\n\\n### 2. Task outcome (extremely detailed version):\\nStripe was founded in 2010 by Patrick Collison and John Collison.\\n\\n### 3. Additional context (if relevant):\\nNo additional context is required.'}\u001b[0m\n", + "\u001b[0mThought: I have collected detailed information about Stripe from the Wikipedia page. Now, I will formulate a comprehensive final answer as required for the task.\u001b[0m\n", + "\u001b[33;1m>>> Calling tool: 'final_answer' with arguments: {'answer': \"### 1. Task Outcome (short version):\\nStripe, Inc. was founded in 2010 by Irish brothers John Collison and Patrick Collison, who serve as the company's president and CEO, respectively. The company is headquartered in South San Francisco, California, and Dublin, Ireland. Stripe provides payment processing and financial services for businesses, enabling them to accept payments and manage financial transactions online.\\n\\n### 2. Task Outcome (extremely detailed version):\\nStripe, Inc. is an Irish-American multinational financial services and software as a service (SaaS) company co-founded in 2010 by John Collison and Patrick Collison, two Irish brothers. The company is dual-headquartered in South San Francisco, California, and Dublin, Ireland. Stripe offers a wide range of financial services and tools, primarily focused on payment processing and management for businesses. Some key milestones and details include:\\n\\n- **Founding and Early Years:** The company was founded in 2010 in Palo Alto, California. In 2011, it received a $2 million investment from notable figures such as Elon Musk, Peter Thiel, and venture capital firms like Sequoia Capital. In 2012, Stripe launched its first multiparty payments solution, Stripe Connect.\\n- **Growth and Expansion:** Stripe has rapidly expanded its services and reach. In 2013, it made its first acquisition, Kickoff, a chat and task management application. In 2016, Stripe launched Atlas, a platform to help startups register as U.S. corporations. The company has continued to grow, raising significant rounds of funding and expanding its services to new markets, including Europe and Africa.\\n- **Product Suite:** Stripe offers a comprehensive suite of financial tools, including payment processing, billing, fraud prevention, point-of-sale solutions, and more. Notable products include Radar (anti-fraud tools), Terminal (point-of-sale hardware), and Stripe Capital (merchant cash advances).\\n- **Partnerships and Integrations:** Stripe has formed partnerships with major companies such as Ford, Spotify, and Twitter to handle transactions and payments. It has also launched the Stripe App Marketplace, allowing businesses to integrate third-party apps and services.\\n- **Valuation and Funding:** As of the latest data, Stripe has raised over $6.5 billion in funding and is valued at around $70 billion, making it one of the most valuable privately-held startups globally.\\n- **Challenges and Layoffs:** In 2022, Stripe announced layoffs, cutting 14% of its workforce to prepare for leaner times. However, the company continues to innovate and expand its offerings.\\n\\n### 3. Additional Context (if relevant):\\n- **Impact on the Founders:** John and Patrick Collison have been influential in shaping the fintech industry. Their vision and leadership have driven Stripe's success and innovation.\\n- **Industry Position:** Stripe is a leader in the fintech sector, competing with other payment processors and financial service providers. Its robust product suite and global reach have solidified its position in the market.\\n- **Future Outlook:** Stripe continues to invest in new technologies and services, including AI and carbon capture initiatives. The company's focus on innovation and customer needs positions it well for future growth.\"}\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m### 1. Task outcome (short version):\n", - "Stripe was founded in 2010.\n", - "\n", - "### 2. Task outcome (extremely detailed version):\n", - "Stripe was founded in 2010 by Patrick Collison and John Collison.\n", - "\n", - "### 3. Additional context (if relevant):\n", - "No additional context is required.\n", + "\u001b[32;20mFounding year: ### 1. Task Outcome (short version):\n", + "Stripe, Inc. was founded in 2010 by Irish brothers John Collison and Patrick Collison, who serve as the company's president and CEO, respectively. The company is headquartered in South San Francisco, California, and Dublin, Ireland. Stripe provides payment processing and financial services for businesses, enabling them to accept payments and manage financial transactions online.\n", + "\n", + "### 2. Task Outcome (extremely detailed version):\n", + "Stripe, Inc. is an Irish-American multinational financial services and software as a service (SaaS) company co-founded in 2010 by John Collison and Patrick Collison, two Irish brothers. The company is dual-headquartered in South San Francisco, California, and Dublin, Ireland. Stripe offers a wide range of financial services and tools, primarily focused on payment processing and management for businesses. Some key milestones and details include:\n", + "\n", + "- **Founding and Early Years:** The company was founded in 2010 in Palo Alto, California. In 2011, it received a $2 million investment from notable figures such as Elon Musk, Peter Thiel, and venture capital firms like Sequoia Capital. In 2012, Stripe launched its first multiparty payments solution, Stripe Connect.\n", + "- **Growth and Expansion:** Stripe has rapidly expanded its services and reach. In 2013, it made its first acquisition, Kickoff, a chat and task management application. In 2016, Stripe launched Atlas, a platform to help startups register as U.S. corporations. The company has continued to grow, raising significant rounds of funding and expanding its services to new markets, including Europe and Africa.\n", + "- **Product Suite:** Stripe offers a comprehensive suite of financial tools, including payment processing, billing, fraud prevention, point-of-sale solutions, and more. Notable products include Radar (anti-fraud tools), Terminal (point-of-sale hardware), and Stripe Capital (merchant cash advances).\n", + "- **Partnerships and Integrations:** Stripe has formed partnerships with major companies such as Ford, Spotify, and Twitter to handle transactions and payments. It has also launched the Stripe App Marketplace, allowing businesses to integrate third-party apps and services.\n", + "- **Valuation and Funding:** As of the latest data, Stripe has raised over $6.5 billion in funding and is valued at around $70 billion, making it one of the most valuable privately-held startups globally.\n", + "- **Challenges and Layoffs:** In 2022, Stripe announced layoffs, cutting 14% of its workforce to prepare for leaner times. However, the company continues to innovate and expand its offerings.\n", + "\n", + "### 3. Additional Context (if relevant):\n", + "- **Impact on the Founders:** John and Patrick Collison have been influential in shaping the fintech industry. Their vision and leadership have driven Stripe's success and innovation.\n", + "- **Industry Position:** Stripe is a leader in the fintech sector, competing with other payment processors and financial service providers. Its robust product suite and global reach have solidified its position in the market.\n", + "- **Future Outlook:** Stripe continues to invest in new technologies and services, including AI and carbon capture initiatives. The company's focus on innovation and customer needs positions it well for future growth.\n", "\u001b[0m\n", "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: Now that I know Stripe was founded in 2010, I can calculate how many years ago it was founded. I'll use the current year and subtract 2010 from it.\u001b[0m\n", + "\u001b[0mThought: The search result shows that Stripe was founded in 2010. Now I need to calculate how many years ago that was. I will use the current year to make this calculation.\u001b[0m\n", "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;109;01mfrom\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mdatetime\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01mimport\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mdate\u001b[39m\n", + "\u001b[0m\u001b[38;5;109;01mimport\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mdatetime\u001b[39m\n", "\n", - "\u001b[38;5;7mcurrent_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mdate\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mtoday\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7myear\u001b[39m\n", + "\u001b[38;5;7mcurrent_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mdatetime\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mdatetime\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7mnow\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;109;01m.\u001b[39;00m\u001b[38;5;7myear\u001b[39m\n", "\u001b[38;5;7mfounding_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;139m2010\u001b[39m\n", - "\u001b[38;5;7myears_since_founding\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mcurrent_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m-\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mfounding_year\u001b[39m\n", - "\u001b[38;5;109mprint\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7myears_since_founding\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", - "\u001b[33;1m====\u001b[0m\n", - "\u001b[33;1mPrint outputs:\u001b[0m\n", - "\u001b[32;20m14\n", - "\u001b[0m\n", - "\u001b[33;1m=== Agent thoughts:\u001b[0m\n", - "\u001b[0mThought: I now have the number of years since Stripe was founded. I can use this to provide the final answer.\u001b[0m\n", - "\u001b[33;1m>>> Agent is executing the code below:\u001b[0m\n", - "\u001b[0m\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144mStripe was founded \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m+\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;109mstr\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7myears_since_founding\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m+\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;144m years ago.\u001b[39m\u001b[38;5;144m\"\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", + "\u001b[38;5;7myears_since_founded\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m=\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mcurrent_year\u001b[39m\u001b[38;5;7m \u001b[39m\u001b[38;5;109;01m-\u001b[39;00m\u001b[38;5;7m \u001b[39m\u001b[38;5;7mfounding_year\u001b[39m\n", + "\u001b[38;5;7mfinal_answer\u001b[39m\u001b[38;5;7m(\u001b[39m\u001b[38;5;7myears_since_founded\u001b[39m\u001b[38;5;7m)\u001b[39m\u001b[0m\n", "\u001b[33;1m====\u001b[0m\n", "\u001b[33;1mPrint outputs:\u001b[0m\n", "\u001b[32;20m\u001b[0m\n", "\u001b[33;1mLast output from code snippet:\u001b[0m\n", - "\u001b[32;20mStripe was founded 14 years ago.\u001b[0m\n", + "\u001b[32;20m14\u001b[0m\n", "\u001b[32;20;1mFinal answer:\u001b[0m\n", - "\u001b[32;20mStripe was founded 14 years ago.\u001b[0m\n" + "\u001b[32;20m14\u001b[0m\n" ] }, { "data": { "text/plain": [ - "'Stripe was founded 14 years ago.'" + "14" ] }, - "execution_count": 11, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -712,9 +358,9 @@ ], "metadata": { "kernelspec": { - "display_name": "disposable", + "display_name": "cookbook2", "language": "python", - "name": "python3" + "name": "cookbook2" }, "language_info": { "codemirror_mode": { @@ -726,7 +372,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.12.0" } }, "nbformat": 4,