Skip to content

Streaming Output issue got unnecesory text in output #753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aliraza108 opened this issue May 24, 2025 · 3 comments
Open

Streaming Output issue got unnecesory text in output #753

aliraza108 opened this issue May 24, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@aliraza108
Copy link

aliraza108 commented May 24, 2025

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():

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>

@aliraza108 aliraza108 added the bug Something isn't working label May 24, 2025
@knowsuchagency
Copy link

@aliraza108 I strongly recommend you disable that api key immediately

@aliraza108
Copy link
Author

@aliraza108 I strongly recommend you disable that api key immediately

thanks I have totally forgot about it

@robtinn robtinn self-assigned this May 30, 2025
@robtinn
Copy link
Contributor

robtinn commented May 30, 2025

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants