agentev1 / app.py
x0pr4nt3s's picture
Update app.py
3571b42 verified
raw
history blame
928 Bytes
from agents import Agent, ModelSettings, function_tool, Runner
import asyncio
import gradio as gr
@function_tool
def get_weather(city: str) -> str:
print("Llamada a la funcion!")
return f"El clima en {city} es diferente!"
@function_tool
def get_sum(sum: str) ->str:
print("Se llamo a la funcion 2")
return str(5+3)
agent = Agent(
name="Agente del clima",
instructions="Responde como reportero del clima, siempre usa tus herramientas.",
model="gpt-4.1-mini",
tools=[get_weather, get_sum],
)
# Función asíncrona
async def chat_fn(user_message, history):
context = {"history": history}
result = await Runner.run(agent, user_message, context=context)
return result.final_output
demo = gr.ChatInterface(
fn=chat_fn,
description="Pregunta el clima.",
)
if __name__ == "__main__":
import os
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
demo.launch()