Skip to content

Streaming Output issue got unnecesory text in output #753

Closed
@aliraza108

Description

@aliraza108

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>

Activity

knowsuchagency

knowsuchagency commented on May 24, 2025

@knowsuchagency

@aliraza108 I strongly recommend you disable that api key immediately

aliraza108

aliraza108 commented on May 25, 2025

@aliraza108
Author

@aliraza108 I strongly recommend you disable that api key immediately

thanks I have totally forgot about it

self-assigned this
on May 30, 2025
robtinn

robtinn commented on May 30, 2025

@robtinn
Contributor

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

aliraza108

aliraza108 commented on May 30, 2025

@aliraza108
Author
rm-openai

rm-openai commented on Jun 2, 2025

@rm-openai
Collaborator

Thanks @.robtinn, that is indeed a log not from the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @knowsuchagency@aliraza108@rm-openai@robtinn

      Issue actions

        Streaming Output issue got unnecesory text in output · Issue #753 · openai/openai-agents-python