You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from agents import AsyncOpenAI, OpenAIChatCompletionsModel,Runner,Agent,RunConfig, set_tracing_disabled
from agents.extensions.models.litellm_model import LitellmModel
agent = Agent(
name='test agent',
model=LitellmModel(model=MODEL, api_key=api_key1),
instructions="your are llm agent")
result = Runner.run_streamed(
agent,
input="who is elon mask"
)
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)
asyncio.run(main())
output got :
uv run main.py
Elon Musk is a South African-born American entrepreneur and businessman. He is the founder, CEO, and CTO of SpaceX; angel investor, CEO, product architect and former chairman of Tesla, Inc.; founder of The Boring Company; and co-founder of Neuralink and OpenAI.
He's a pretty prominent figure known for his ambitious ventures and often controversial statements. He's aiming to revolutionize transportation, both on Earth and in space, and is deeply involved in technologies like artificial intelligence and brain-computer interfaces.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001F00F7D8F20>
Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x000001F01126A630>, 14663.515)])']
connector: <aiohttp.connector.TCPConnector object at 0x000001F01123FB00>
(video cretor ai) PS C:\Users\HP\OneDrive\Desktop\video cretor ai>
The text was updated successfully, but these errors were encountered:
I don't think its unnecessary text in output, I think its how the connector is being closed/not-closed. I haven't been able to repro as this works with OpenAI models and I don't have a Gemini API key. I would suggest try wrapping the for loop in a try except block as a workaround, will have a think..
Uh oh!
There was an error while loading. Please reload this page.
from agents import AsyncOpenAI, OpenAIChatCompletionsModel,Runner,Agent,RunConfig, set_tracing_disabled
from agents.extensions.models.litellm_model import LitellmModel
import asyncio
from openai.types.responses import ResponseTextDeltaEvent
api_key1 = 'AIzaSyCZjwd0GLjpXu4kWx-lU4dbcsB8PTfztxo'
base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
set_tracing_disabled(True)
MODEL = 'gemini/gemini-2.0-flash'
async def main():
asyncio.run(main())
output got :
uv run main.py
Elon Musk is a South African-born American entrepreneur and businessman. He is the founder, CEO, and CTO of SpaceX; angel investor, CEO, product architect and former chairman of Tesla, Inc.; founder of The Boring Company; and co-founder of Neuralink and OpenAI.
He's a pretty prominent figure known for his ambitious ventures and often controversial statements. He's aiming to revolutionize transportation, both on Earth and in space, and is deeply involved in technologies like artificial intelligence and brain-computer interfaces.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001F00F7D8F20>
Unclosed connector
connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x000001F01126A630>, 14663.515)])']
connector: <aiohttp.connector.TCPConnector object at 0x000001F01123FB00>
(video cretor ai) PS C:\Users\HP\OneDrive\Desktop\video cretor ai>
The text was updated successfully, but these errors were encountered: