CompleteAlfred / app.py
DiogoPinheiro's picture
Complete Alfred smolagents
be6f51b
import gradio as gr
import random
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
from langchain_ollama import ChatOllama
# Import our custom tools from their modules
from tools import WeatherInfoTool, HubStatsTool
from retriever import load_guest_dataset
# Initialize the Hugging Face model
model = LiteLLMModel(
model_id="ollama_chat/qwen2.5-coder:7b",
api_base="http://localhost:xxxx",
temperature=0
)
# Initialize the web search tool
search_tool = DuckDuckGoSearchTool()
# Initialize the weather tool
weather_info_tool = WeatherInfoTool()
# Initialize the Hub stats tool
hub_stats_tool = HubStatsTool()
# Load the guest dataset and initialize the guest info tool
guest_info_tool = load_guest_dataset()
# Create Alfred with all the tools
alfred = CodeAgent(tools=[guest_info_tool, search_tool, hub_stats_tool, weather_info_tool], model=model)
if __name__ == "__main__":
# query = "Tell me about 'Lady Ada Lovelace'"
# query = "What's the weather like in Paris tonight? Will it be suitable for our fireworks display?"
# query = "One of our guests is from Qwen. What can you tell me about their most popular model?"
query = "I need to speak with Dr. Nikola Tesla about recent advancements in wireless energy. Can you help me prepare for this conversation?"
# First interaction
# response1 = alfred_with_memory.run("Tell me about Lady Ada Lovelace.")
# print("🎩 Alfred's First Response:")
# print(response1)
# # Second interaction (referencing the first)
# response2 = alfred_with_memory.run("What projects is she currently working on?", reset=False)
# print("🎩 Alfred's Second Response:")
# print(response2)
response = alfred.run(query)
print("🎩 Alfred's Response:")
print(response)