Skip to content

Multimodal response generation support #206

Closed

Description

@inspire-boy

Some models support generate image in context.

Google doc

Documentation for Gemini: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal-response-generation

Model

  • gemini-2.0-flash-exp
  • gemini-2.0-flash-exp-image-generation

Request raw content sample

{
  "contents": [
    {
      "parts": [
        {
          "text": "Create a image of a red cat."
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "responseMimeType": "text/plain",
    "responseModalities": [
      "Text",
      "Image"
    ]
  }
}

Response raw content sample

{
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "[------IMAGE BASE64------]"
            }
          }
        ],
        "role": "model"
      },
      "index": 0
    },
}

Activity

  1. hangfei commented on Apr 15, 2025

    @hangfei
    Collaborator

    What's your request or question?

  2. self-assigned this
    on Apr 15, 2025
  3. inspire-boy commented on Apr 15, 2025

    @inspire-boy
    Author

    What's your request or question?
    Thank your reply.I want to use multimodal output to generate images, does adk currently have this capability and does it require any special configuration?
    Image

  4. boyangsvl commented on Apr 19, 2025

    @boyangsvl
    Collaborator

    I think this should work already as long as you:

    • use the right model
    • set text and image as response modalities

    Please reopen the issue if it doesn't work.

  5. inspire-boy commented on Apr 20, 2025

    @inspire-boy
    Author

    @boyangsvl
    I use the custom app code example:https://google.github.io/adk-docs/get-started/quickstart-streaming/#5.-build-custom-app
    Just appened "IMAGE" item in response_modalities
    Image
    Then execute:uvicorn main:app --reload start a service.
    Error Trace log:

    INFO:     Will watch for changes in these directories: ['D:\\py\\adk\\demo\\adk_streaming\\app']
    INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
    INFO:     Started reloader process [103584] using StatReload
    INFO:     Started server process [79244]
    INFO:     Waiting for application startup.
    INFO:     Application startup complete.   
    INFO:     ('127.0.0.1', 61876) - "WebSocket /ws/85863365" [accepted]
    Client #85863365 connected
    DEBUG: Starting run_live with session: Session(id='85863365', app_name='ADK Streaming example', user_id='85863365', state={}, events=[], last_update_time=1745129469.9442961)
    DEBUG: Starting run_live with run_config: RunConfig(speech_config=None, response_modalities=['TEXT', 'IMAGE'], save_input_blobs_as_artifacts=False, support_cfc=False, streaming_mode=<StreamingMode.NONE: None>, output_audio_transcription=None, max_llm_calls=500)
    INFO:     connection open
    ERROR:    Exception in ASGI application
    Traceback (most recent call last):
      File "D:\py\adk\demo\venv\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 243, in run_asgi
        result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]       
      File "D:\py\adk\demo\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 60, in __call__
        return await self.app(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\fastapi\applications.py", line 1054, in __call__
        await super().__call__(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\applications.py", line 112, in __call__
        await self.middleware_stack(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\middleware\errors.py", line 152, in __call__
        await self.app(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\middleware\exceptions.py", line 62, in __call__
        await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
        raise exc
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
        await app(scope, receive, sender)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\routing.py", line 714, in __call__
        await self.middleware_stack(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\routing.py", line 734, in app
        await route.handle(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\routing.py", line 362, in handle
        await self.app(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\routing.py", line 95, in app
        await wrap_app_handling_exceptions(app, session)(scope, receive, send)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\_exception_handler.py", line 53, in wrapped_app
        raise exc
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\_exception_handler.py", line 42, in wrapped_app
        await app(scope, receive, sender)
      File "D:\py\adk\demo\venv\lib\site-packages\starlette\routing.py", line 93, in app
        await func(session)
      File "D:\py\adk\demo\venv\lib\site-packages\fastapi\routing.py", line 383, in app
        await dependant.call(**solved_result.values)
      File "D:\py\adk\demo\adk_streaming\app\main.py", line 144, in websocket_endpoint
        await asyncio.gather(agent_to_client_task, client_to_agent_task)
      File "D:\py\adk\demo\adk_streaming\app\main.py", line 71, in agent_to_client_messaging
        async for event in live_events:
      File "D:\py\adk\demo\venv\lib\site-packages\google\adk\runners.py", line 296, in run_live
        async for event in invocation_context.agent.run_live(invocation_context):
      File "D:\py\adk\demo\venv\lib\site-packages\google\adk\agents\base_agent.py", line 168, in run_live
        async for event in self._run_live_impl(ctx):
      File "D:\py\adk\demo\venv\lib\site-packages\google\adk\agents\llm_agent.py", line 240, in _run_live_impl
        async for event in self._llm_flow.run_live(ctx):
      File "D:\py\adk\demo\venv\lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 82, in run_live
        async with llm.connect(llm_request) as llm_connection:
      File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 199, in __aenter__
        return await anext(self.gen)
      File "D:\py\adk\demo\venv\lib\site-packages\google\adk\models\google_llm.py", line 208, in connect
        async with self._live_api_client.aio.live.connect(
      File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 199, in __aenter__
        return await anext(self.gen)
      File "D:\py\adk\demo\venv\lib\site-packages\google\genai\live.py", line 1832, in connect
        logger.info(await ws.recv(decode=False))
      File "D:\py\adk\demo\venv\lib\site-packages\websockets\asyncio\connection.py", line 322, in recv
        raise self.protocol.close_exc from self.recv_exc
    websockets.exceptions.ConnectionClosedError: received 1007 (invalid frame payload data) Request contains an invalid argument.; then sent 1007 (invalid frame payload data) Request contains 
    an invalid argument.
    INFO:     connection closed
    

    Did I make the right modify like this? Are there any relevant examples of the returned images of gemini-2.0-flash-exp? Very thanks!

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions