Minor changes for alignment

Signed-off-by: Víctor Mayoral Vilches <v.mayoralv@gmail.com>
This commit is contained in:
Víctor Mayoral Vilches 2025-03-26 18:55:21 +01:00
parent adb358baae
commit 21048444c6
2 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from dotenv import load_dotenv
from openai import AsyncOpenAI
from cai.agents import OpenAIChatCompletionsModel,Agent,Runner
from cai.agents import set_default_openai_client, set_tracing_disabled
from openai.types.responses import ResponseTextDeltaEvent
# Load environment variables from .env file
load_dotenv()
@ -31,5 +32,23 @@ agent = Agent(
)
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)
def run_sync_haiku():
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)
async def stream_jokes():
result = Runner.run_streamed(agent, input="Please tell me 5 jokes.")
async for event in result.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
print(event.data.delta, end="", flush=True)
########################################################
# async
# import asyncio
# asyncio.run(stream_jokes())
# sync
run_sync_haiku()

View File

@ -138,6 +138,8 @@ validation:
unrecognized_links: warn
anchors: warn
dev_addr: localhost:8088
extra_css:
- stylesheets/extra.css