Spaces:
No application file
No application file
Update README.md
Browse files
README.md
CHANGED
|
@@ -5,39 +5,71 @@ emoji: 👀
|
|
| 5 |
colorFrom: blue
|
| 6 |
colorTo: green
|
| 7 |
short_description: AI agent for web search, calculations, and image retrieval u
|
| 8 |
-
sdk_version:
|
| 9 |
hf_oauth: true
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Chuck Agent
|
| 13 |
|
| 14 |
-
This agent
|
| 15 |
-
1. Retrieving information from the web using the Serper API
|
| 16 |
-
2. Performing calculations when needed
|
| 17 |
-
3. Processing and analyzing images from web pages
|
| 18 |
|
| 19 |
-
##
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
-
##
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
## Implementation Details
|
| 32 |
|
| 33 |
-
|
| 34 |
-
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
| 5 |
colorFrom: blue
|
| 6 |
colorTo: green
|
| 7 |
short_description: AI agent for web search, calculations, and image retrieval u
|
| 8 |
+
sdk_version: 4.29.0
|
| 9 |
hf_oauth: true
|
| 10 |
+
app_file: ap.py
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Chuck Agent - Evaluation Runner
|
| 14 |
|
| 15 |
+
This application implements an AI agent using the `smolagents` framework. The agent is designed to answer questions by leveraging a suite of tools for various tasks. This Gradio interface allows users to run an evaluation against a set of questions fetched from a Hugging Face hosted API and submit the agent's answers for scoring.
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
## Core Agent Capabilities
|
| 18 |
|
| 19 |
+
The agent can:
|
| 20 |
+
* **Retrieve information from the web:** Utilizes the Serper API for real-time web searches.
|
| 21 |
+
* **Perform calculations:** Evaluates mathematical expressions.
|
| 22 |
+
* **Process and analyze images:** Retrieves images from URLs and stores them (currently in memory).
|
| 23 |
|
| 24 |
+
## How it Works
|
| 25 |
|
| 26 |
+
1. **Authentication:** Users log in with their Hugging Face account.
|
| 27 |
+
2. **Question Fetching:** The application fetches a list of questions from the [Unit 4 Scoring API](https://huggingface.co/spaces/agents-course/unit4_scoring_api).
|
| 28 |
+
3. **Agent Processing:** For each question:
|
| 29 |
+
* The `QuestionAnsweringAgent` (a `smolagents.CodeAgent`) plans and executes steps.
|
| 30 |
+
* It uses its tools (`WebSearchTool`, `CalculatorTool`, `ImageRetrievalTool`) as needed.
|
| 31 |
+
* It formulates a final answer based on its reasoning and tool outputs.
|
| 32 |
+
* The default LLM for the agent is `gpt-3.5-turbo` (configurable to `gpt-4`).
|
| 33 |
+
4. **Submission & Scoring:** The agent's answers are submitted back to the scoring API, and the results, including an overall score, are displayed.
|
| 34 |
+
|
| 35 |
+
## Requirements for Running
|
| 36 |
+
|
| 37 |
+
To successfully run the evaluation, you'll need:
|
| 38 |
+
* An **OpenAI API key**: For the underlying language model (e.g., GPT-3.5 Turbo or GPT-4).
|
| 39 |
+
* A **Serper API key**: For the web search functionality.
|
| 40 |
+
* A **Hugging Face account**: To log in and submit answers for scoring.
|
| 41 |
+
|
| 42 |
+
These API keys must be set as **Secrets** in your Hugging Face Space environment:
|
| 43 |
+
* `OPENAI_API_KEY`
|
| 44 |
+
* `SERPER_API_KEY`
|
| 45 |
+
|
| 46 |
+
## Tools Used by the Agent
|
| 47 |
+
|
| 48 |
+
* **`WebSearchTool`**: Searches the web using the Serper API to find relevant information.
|
| 49 |
+
* **`CalculatorTool`**: Performs mathematical calculations based on string expressions.
|
| 50 |
+
* **`ImageRetrievalTool`**: Retrieves images from given URLs. Currently stores image data in memory and returns a confirmation message.
|
| 51 |
|
| 52 |
## Implementation Details
|
| 53 |
|
| 54 |
+
* **Framework**: `smolagents` for agent and tool creation.
|
| 55 |
+
* **Agent Type**: `smolagents.CodeAgent` which allows for multi-step reasoning and tool invocation.
|
| 56 |
+
* **LLM Model**: Configured to use `gpt-3.5-turbo` by default for a balance of speed and capability. Can be switched to `gpt-4` in the `AppConfig` section of the script for more complex reasoning, at the cost of speed and potential expense.
|
| 57 |
+
* **Asynchronous Operations**: Tools requiring network I/O (web search, image retrieval) are implemented asynchronously using `aiohttp` with a shared client session for efficiency.
|
| 58 |
+
* **Error Handling**: Includes error handling for API key checks, network requests, and agent processing steps.
|
| 59 |
+
* **User Interface**: Built with Gradio, providing a simple interface to trigger the evaluation and view results.
|
| 60 |
+
|
| 61 |
+
## Usage Instructions
|
| 62 |
+
|
| 63 |
+
1. **Log In:** Click the "Login with Hugging Face" button.
|
| 64 |
+
2. **Run Evaluation:** Once logged in, click the "Run Evaluation & Submit All Answers" button.
|
| 65 |
+
* This will fetch questions, have the agent process each one, and then submit all answers.
|
| 66 |
+
3. **View Results:**
|
| 67 |
+
* The "Run Status / Submission Result" textbox will display the overall outcome of the submission, including the score.
|
| 68 |
+
* The "Questions and Agent Answers" table will show each question, the agent's submitted answer, and the reasoning trace.
|
| 69 |
|
| 70 |
+
## Configuration
|
| 71 |
|
| 72 |
+
Key configurations can be found in the `AppConfig` class within the script (`app.py`):
|
| 73 |
+
* `OPENAI_MODEL_ID`: Change between `"gpt-3.5-turbo"` and `"gpt-4"`.
|
| 74 |
+
* `SERPER_API_NUM_RESULTS`: Number of search results the `WebSearchTool` aims to process.
|
| 75 |
+
* `AGENT_MAX_STEPS`: Maximum number of steps the agent can take to answer a question.
|