Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Streaming Structured Output with Gemini Model over vertex-ai #2242

Open
Assignees
DouweM
Labels
questionFurther information is requested
@limchr

Description

@limchr

Question

Hi community,

I've tried some time getting a structured output to be streamed with Gemini and vertex-ai. It works when I run the example with DeepSeek. With Gemini, the output is not streamed. I want to realize a streamed output of a list of dataclasses, which I want to stream to a web front end, where I want to animate them.

Maybe it is just a simple thing I cannot see. I considered other issues here and your docs but could not find the solution. If someone could give me a hint, that would be awesome.

fromtypingimportOptional,TypedDictfrompydantic_aiimportAgentfrompydantic_ai.models.geminiimportGeminiModelimportasynciofromtyping_extensionsimportTypedDictfrompydantic_ai.models.geminiimportGeminiModel,GeminiModelSettingsmodel_settings=GeminiModelSettings(gemini_thinking_config={'thinking_budget':128})model=GeminiModel('gemini-2.5-pro',provider='google-vertex')classUserProfile(TypedDict,total=False):name:strage:Optional[int]=Nonebio:stragent=Agent(model=model,output_type=list[UserProfile],stream=True,model_settings=model_settings)# --- Streaming logic ---asyncdefstream_chat(prompt:str):asyncwithagent.run_stream(prompt)asresult:asyncforprofileinresult.stream_structured(debounce_by=None):yieldprofileasyncdefprint_llm_response(prompt):response=stream_chat(prompt)asyncforchunkinresponse:print(chunk,end="",flush=True)if__name__=="__main__":asyncio.run(print_llm_response("Make up 10 different persons with their unique stories."))

Additional Context

No response

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp