Spaces:
Sleeping
Sleeping
File size: 924 Bytes
ab4c3ae b5db208 4a880c1 e7a045e b5db208 2a68242 fda2e6d 4a880c1 f1f6260 4a880c1 5c97072 551d58b f1f6260 4a880c1 fda2e6d b5db208 4a880c1 b5db208 4a880c1 b5db208 4a880c1 b5db208 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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() |