CoolFace
Apppublic

bitcloud2/Final_Assignment_Template

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes
my_agent.py46 linesDownload Raw Back to root
1import math2import os3import re4 5from bs4 import BeautifulSoup6import httpx7from smolagents import CodeAgent8from tools import search_tool9from gemini_model import GeminiApiModel10 11 12class SmolAgent:13    """14    A simple agent using the custom GeminiApiModel.15    Replace the __call__ method with your actual agent logic16    using Hugging Face libraries (e.g., smolagents, transformers, inference API).17    """18 19    def __init__(self):20        model = GeminiApiModel(model_id="gemini-2.0-flash")21        self.agent = CodeAgent(22            tools=[search_tool],23            model=model,24            max_steps=5,25            verbosity_level=0,26            additional_authorized_imports=["httpx", "math", "os", "re", "bs4"],27        )28        print("SmolAgent initialized with GeminiApiModel.")29        # Initialize any required components here30        # e.g., load a model, tokenizer, setup API clients31 32    def __call__(self, question: str) -> str:33        """34        Processes the input question and returns an answer.35        This is where the core agent logic should reside.36        """37        print(f"SmolAgent received question (first 50 chars): {question[:50]}...")38 39        # --- Agent Logic ---40        # The CodeAgent will now use GeminiApiModel internally41        answer = self.agent.run(question)42        # -------------------------43 44        print(f"SmolAgent returning answer (first 50 chars): {str(answer)[:50]}...")45        return str(answer)46