joeyutong commented on code in PR #1382:
URL: https://github.com/apache/flink-agents/pull/1382#discussion_r4695374413


##########
docs/content/docs/development/media_models/_index.md:
##########
@@ -0,0 +1,400 @@
+---
+title: "Media Models"
+weight: 9
+type: docs
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Media Models
+
+## Overview
+
+Use media models when an Agent needs dedicated media operations—such as
+generating images or videos, transcribing recordings, or synthesizing speech.
+By default, register a shared `MEDIA_MODEL_CONNECTION` for your service
+connection and declare named `MEDIA_MODEL` setups (subclasses of
+`BaseImageGenerationModelSetup`, `BaseVideoGenerationModelSetup`,
+`BaseTranscriptionModelSetup`, or `BaseSpeechSynthesisModelSetup`, such as
+DashScope's `DashScopeImageGenerationModelSetup`) retrieved via
+`ctx.get_resource(name, ResourceType.MEDIA_MODEL)`. Declaring named setups 
keeps
+model selection and default parameters out of Action code, enables YAML
+configuration, and makes models easy to reuse across Actions and share between
+Java and Python.
+
+If your workflow uses conversation-style multimodal messages instead, see
+[Chat with Models]({{< ref "docs/development/calling-llms/chat" >}}). For
+available implementations and provider options, see
+[Built-in Media Model Connections]({{< ref 
"docs/development/media_models/providers" >}}).
+
+## Quick start
+
+### 1. Register a connection
+
+Register a `MEDIA_MODEL_CONNECTION` resource with your chosen connection
+descriptor. The example below uses DashScope; replace it with any 
implementation
+from [Built-in Media Model Connections]({{< ref 
"docs/development/media_models/providers" >}}):
+
+{{< tabs "Register a media model connection" >}}
+{{< tab "Python" >}}
+```python
+from flink_agents.api.resource import ResourceDescriptor, ResourceName, 
ResourceType
+
+agents_env.add_resource(
+    "media",
+    ResourceType.MEDIA_MODEL_CONNECTION,
+    ResourceDescriptor(clazz=ResourceName.MediaModel.DASHSCOPE_CONNECTION),
+)
+```
+{{< /tab >}}
+{{< tab "Java" >}}
+```java
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceName;
+import org.apache.flink.agents.api.resource.ResourceType;
+
+agentsEnv.addResource(
+        "media",
+        ResourceType.MEDIA_MODEL_CONNECTION,
+        PythonResourceDescriptor.Builder.newBuilder(
+                        ResourceName.MediaModel.Python.DASHSCOPE_CONNECTION)
+                .build());
+```
+{{< /tab >}}
+{{< tab "YAML" >}}
+```yaml
+media_model_connections:
+  - name: media
+    clazz: dashscope
+    type: python
+    request_timeout: 60
+```
+{{< /tab >}}
+{{< /tabs >}}
+
+You can also declare a connection using `@media_model_connection` in Python,
+`@MediaModelConnection` in Java, or the YAML `media_model_connections` section.
+See [Registering Resources]({{< ref 
"docs/development/create-agent/resources#registering-resources" >}})
+and [YAML Resources]({{< ref "docs/development/create-agent/yaml#resources" 
>}}).
+
+### 2. Declare a media model setup and call it
+
+Declare a named, pre-configured `MEDIA_MODEL` setup (for example

Review Comment:
   Done. Shortened the setup introduction to focus directly on declaring and 
retrieving a setup.



##########
docs/content/docs/development/media_models/_index.md:
##########
@@ -0,0 +1,400 @@
+---
+title: "Media Models"
+weight: 9
+type: docs
+---
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Media Models
+
+## Overview
+
+Use media models when an Agent needs dedicated media operations—such as
+generating images or videos, transcribing recordings, or synthesizing speech.
+By default, register a shared `MEDIA_MODEL_CONNECTION` for your service
+connection and declare named `MEDIA_MODEL` setups (subclasses of
+`BaseImageGenerationModelSetup`, `BaseVideoGenerationModelSetup`,
+`BaseTranscriptionModelSetup`, or `BaseSpeechSynthesisModelSetup`, such as
+DashScope's `DashScopeImageGenerationModelSetup`) retrieved via
+`ctx.get_resource(name, ResourceType.MEDIA_MODEL)`. Declaring named setups 
keeps
+model selection and default parameters out of Action code, enables YAML
+configuration, and makes models easy to reuse across Actions and share between
+Java and Python.
+
+If your workflow uses conversation-style multimodal messages instead, see
+[Chat with Models]({{< ref "docs/development/calling-llms/chat" >}}). For
+available implementations and provider options, see
+[Built-in Media Model Connections]({{< ref 
"docs/development/media_models/providers" >}}).
+
+## Quick start
+
+### 1. Register a connection
+
+Register a `MEDIA_MODEL_CONNECTION` resource with your chosen connection
+descriptor. The example below uses DashScope; replace it with any 
implementation
+from [Built-in Media Model Connections]({{< ref 
"docs/development/media_models/providers" >}}):
+
+{{< tabs "Register a media model connection" >}}
+{{< tab "Python" >}}
+```python
+from flink_agents.api.resource import ResourceDescriptor, ResourceName, 
ResourceType
+
+agents_env.add_resource(
+    "media",
+    ResourceType.MEDIA_MODEL_CONNECTION,
+    ResourceDescriptor(clazz=ResourceName.MediaModel.DASHSCOPE_CONNECTION),
+)
+```
+{{< /tab >}}
+{{< tab "Java" >}}
+```java
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceName;
+import org.apache.flink.agents.api.resource.ResourceType;
+
+agentsEnv.addResource(
+        "media",
+        ResourceType.MEDIA_MODEL_CONNECTION,
+        PythonResourceDescriptor.Builder.newBuilder(
+                        ResourceName.MediaModel.Python.DASHSCOPE_CONNECTION)
+                .build());
+```
+{{< /tab >}}
+{{< tab "YAML" >}}
+```yaml
+media_model_connections:
+  - name: media
+    clazz: dashscope
+    type: python
+    request_timeout: 60
+```
+{{< /tab >}}
+{{< /tabs >}}
+
+You can also declare a connection using `@media_model_connection` in Python,
+`@MediaModelConnection` in Java, or the YAML `media_model_connections` section.
+See [Registering Resources]({{< ref 
"docs/development/create-agent/resources#registering-resources" >}})
+and [YAML Resources]({{< ref "docs/development/create-agent/yaml#resources" 
>}}).
+
+### 2. Declare a media model setup and call it
+
+Declare a named, pre-configured `MEDIA_MODEL` setup (for example
+`DashScopeImageGenerationModelSetup` or a custom subclass of
+`BaseImageGenerationModelSetup`, `BaseVideoGenerationModelSetup`,
+`BaseTranscriptionModelSetup`, or `BaseSpeechSynthesisModelSetup`) using
+`@media_model_setup` / `@MediaModelSetup`,
+`add_resource(..., ResourceType.MEDIA_MODEL, ...)` / `addResource(...)`, or 
YAML
+`media_model_setups`. This keeps Action code independent of specific model 
names
+and default parameters:
+
+{{< tabs "Declare a media model setup" >}}
+{{< tab "Python" >}}
+```python
+from flink_agents.api.agents.agent import Agent
+from flink_agents.api.decorators import media_model_setup
+from flink_agents.api.resource import ResourceDescriptor, ResourceName, 
ResourceType
+
+
+class PosterAgent(Agent):
+    @media_model_setup
+    @staticmethod
+    def poster_image() -> ResourceDescriptor:
+        return ResourceDescriptor(
+            clazz=ResourceName.MediaModel.DASHSCOPE_IMAGE_GENERATION_SETUP,
+            connection="media",
+            model="qwen-image-3.0",
+            size="512*512",
+        )
+```
+
+Retrieve the setup inside an Action via `ResourceType.MEDIA_MODEL`:
+
+```python
+image_model = ctx.get_resource("poster_image", ResourceType.MEDIA_MODEL)
+result = image_model.generate("A navy notebook on a white desk.", timeout=180)
+generated_image = result.content[0]
+```
+{{< /tab >}}
+{{< tab "Java" >}}
+```java
+import org.apache.flink.agents.api.agents.Agent;
+import org.apache.flink.agents.api.annotation.MediaModelSetup;
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceName;
+
+public class PosterAgent extends Agent {
+    @MediaModelSetup
+    public static ResourceDescriptor posterImage() {
+        return PythonResourceDescriptor.Builder.newBuilder(
+                        
ResourceName.MediaModel.Python.DASHSCOPE_IMAGE_GENERATION_SETUP)
+                .addInitialArgument("connection", "media")
+                .addInitialArgument("model", "qwen-image-3.0")
+                .addInitialArgument("size", "512*512")
+                .build();
+    }
+}
+```
+
+Retrieve the setup inside an Action via `ResourceType.MEDIA_MODEL`:
+
+```java
+BaseImageGenerationModelSetup imageModel =
+        (BaseImageGenerationModelSetup) ctx.getResource("posterImage", 
ResourceType.MEDIA_MODEL);
+MediaResult<ImageBlock> result =
+        imageModel.generate(
+                ImageGenerationRequest.of("A navy notebook on a white desk."),
+                Duration.ofMinutes(3));
+ImageBlock generatedImage = result.getContent().get(0);
+```
+{{< /tab >}}
+{{< tab "YAML" >}}
+```yaml
+media_model_setups:
+  - name: poster_image
+    clazz: dashscope_image_generation
+    connection: media
+    model: qwen-image-3.0
+    size: "512*512"
+```
+
+Retrieve the setup inside an Action with
+`ctx.get_resource("poster_image", ResourceType.MEDIA_MODEL)` (Java:
+`ctx.getResource("poster_image", ResourceType.MEDIA_MODEL)`). Omitted `type:`
+defaults to `python`; set `type: java` with a Java setup class name in
+Java-loaded YAML.
+{{< /tab >}}
+{{< /tabs >}}
+
+Media model setups require both `connection` and `model`. Concrete
+integration setups (such as DashScope setups) declare common typed parameters
+directly alongside optional `additional_kwargs` for provider-specific
+extensions (and `BaseSpeechSynthesisModelSetup` adds optional `voice`). Setups
+share their connection's lifetime, detach without closing the shared connection
+when closed, and preserve `AsyncJobModel` support whenever the setup is
+asynchronous.
+
+Each call returns a `MediaResult` containing typed output blocks in `content`
+(`getContent()`), along with optional `expires_at_ms`, `usage`, `request_id`,
+and `metadata`.
+
+## Capabilities

Review Comment:
   Done. Renamed the section to `Supported Media Models`, updated the table to 
`Media task` / `API` / `Input` / `Result content` (dropping `Base setup class` 
and noting `MediaResult`), moved sync/async execution into `Asynchronous jobs`, 
and removed the separate `Parameters` subsection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to