murphynetworks's picture
Add Hugging Face Spaces configuration to README.md
17a1045
|
Raw History Blame Contribute Delete
5.72 kB

A newer version of the Gradio SDK is available: 6.32.0

Upgrade
metadata
title: Enhanced Agent for API Evaluation
emoji: 🤖
colorFrom: indigo
colorTo: purple
sdk: gradio
sdk_version: 5.25.2
app_file: app.py
pinned: false
hf_oauth: true
hf_oauth_expiration_minutes: 480

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

Enhanced Agent for API Question Evaluation

This project implements an advanced AI agent capable of answering questions from an evaluation API. The agent uses OpenRouter to access LLMs and is equipped with specialized tools for handling different types of data and performing various tasks.

Key Features

  • Multiple Specialized Tools: Web search, Excel analysis, audio transcription, code execution, and more
  • File Attachment Handling: Automatically downloads and processes file attachments from the API
  • Minimal Answer Enforcement: Ensures answers are concise and match the expected format
  • Robust Error Handling: Prevents crashes with fallbacks for all tool operations
  • Comprehensive Logging: Detailed colorful logs for all agent operations
  • Multi-Engine Web Search: Falls back between search engines for more reliable results

Project Structure

  • enhanced_agent.py: Main agent implementation with all specialized tools integrated
  • tools/: Directory containing specialized tool implementations
    • attachment_handler.py: File download and cleanup utilities
    • audio_transcription.py: Audio transcription with specialized extractors
    • enhanced_web_search.py: Multi-engine web search with fallbacks
    • code_execution.py: Safe Python code execution in sandbox
  • enhanced_integration.py: Script to integrate the enhanced agent with the evaluation system
  • run_enhanced_evaluation.py: Script to run the enhanced agent against the API
  • test_enhanced_agent.py: Test script for the enhanced agent with various question types

Setup Instructions

  1. Clone this repository:

    git clone https://github.com/your-username/ai-agent-evaluation.git
    cd ai-agent-evaluation
    
  2. Create a virtual environment and install dependencies:

    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  3. Set up your OpenRouter API key:

    • Create an account at OpenRouter
    • Obtain an API key
    • Copy .env.example to .env and add your API key:
      cp .env.example .env
      
    • Edit the .env file with the following variables:
      OPENROUTER_API_KEY=your_api_key_here
      OPENROUTER_MODEL=anthropic/claude-3-5-sonnet
      USERNAME=your_username_here
      CODE_LINK=your_github_repo_link_here
      

Usage

Running the Evaluation

# Run the evaluation against the API
python run_enhanced_evaluation.py

# Use a different model
python run_enhanced_evaluation.py --model anthropic/claude-3-opus-20240229

# Run with parallel workers (experimental)
python run_enhanced_evaluation.py --workers 2

# Provide username and code link via command line
python run_enhanced_evaluation.py --username "YourName" --code-link "https://github.com/yourusername/your-repo"

Testing the Agent

# Run tests with basic questions
python test_enhanced_agent.py

# Test with a specific model
python test_enhanced_agent.py --model openai/gpt-4o

# Test file attachment handling with a task ID
python test_enhanced_agent.py --task-id your_task_id_here

# Use custom test questions from a JSON file
python test_enhanced_agent.py --questions custom_questions.json

How It Works

  1. Question Processing: The agent analyzes the question to determine what tools are needed
  2. Tool Selection: The appropriate specialized tools are invoked based on the question type
  3. File Handling: If a file attachment is referenced, it's downloaded and processed
  4. Answer Generation: The LLM generates a detailed answer using the tool outputs
  5. Answer Enforcement: The answer is post-processed to ensure it's minimal and correctly formatted
  6. Submission: The minimal answer is submitted to the evaluation API

Agent Tools

The enhanced agent is equipped with the following specialized tools:

  1. Enhanced Web Search: Multi-engine web search with automatic fallbacks
  2. Web Browsing: Fetch and extract content from a specific URL
  3. Audio Transcription: Transcribe audio files and extract specific information
  4. Excel Analysis: Analyze Excel files and extract data based on queries
  5. Code Execution: Safely execute Python code to determine outputs
  6. File Reading: Read and process files attached to questions
  7. Image Analysis: Analyze images and extract information
  8. Attachment Handler: Download and manage file attachments from the API

Evaluation API

The agent is evaluated using the API at https://agents-course-unit4-scoring.hf.space, which provides:

  • /questions: All questions for evaluation
  • /files/{task_id}: Files associated with questions
  • /submit: Endpoint for submitting answers

Submission Requirements

For submission, the API requires:

  1. Username: Your Hugging Face username
  2. Code Link: URL to your Hugging Face Space code
  3. Answers: List of responses for scoring, formatted as {"task_id": "...", "submitted_answer": "..."}

Important Notes

  • The agent is designed to provide minimal answers without explanations or reasoning
  • Special handling is implemented for different question types (who/what/where, lists, yes/no, etc.)
  • The agent can automatically download and process file attachments referenced in questions
  • Multiple fallbacks and error recovery mechanisms ensure the agent always returns a response