agentev1 / app.py
salmg's picture
Update app.py
f1f6260 verified
raw
history blame contribute delete
924 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(suma: str) -> str:
print("Se llamo a la funcion 2")
return str(3+4)
agent = Agent(
name="Agente del clima",
instructions="Responde como reportero del clima, siempre usa tus herramientas.",
model="gpt-4.1",
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()