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


##########
docs/content/docs/development/media_models/_index.md:
##########
@@ -0,0 +1,338 @@
+---
+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 rather than
+conversational chat responses:
+
+- **Image generation and editing**: produce or transform images from prompts 
and
+  optional reference images.
+- **Video generation**: generate video clips from text prompts, conditioning
+  media blocks, or both.
+- **Transcription**: extract text transcripts from audio or video recordings.
+- **Speech synthesis**: synthesize spoken audio from text and voice settings.
+
+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
+
+### Register a connection
+
+Declare a `MEDIA_MODEL_CONNECTION` resource using `@media_model_connection` in
+Python, `@MediaModelConnection` in Java, or `media_model_connections` in YAML.
+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.agents.agent import Agent
+from flink_agents.api.decorators import media_model_connection
+from flink_agents.api.resource import ResourceDescriptor, ResourceName
+
+
+class PosterAgent(Agent):
+    @media_model_connection
+    @staticmethod
+    def media() -> ResourceDescriptor:
+        return ResourceDescriptor(
+            clazz=ResourceName.MediaModel.DASHSCOPE_CONNECTION,
+            request_timeout=60.0,
+        )
+```
+{{< /tab >}}
+{{< tab "Java" >}}
+```java
+import org.apache.flink.agents.api.agents.Agent;
+import org.apache.flink.agents.api.annotation.MediaModelConnection;
+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 {
+    @MediaModelConnection
+    public static ResourceDescriptor media() {
+        return PythonResourceDescriptor.Builder.newBuilder(
+                        ResourceName.MediaModel.Python.DASHSCOPE_CONNECTION)
+                .addInitialArgument("request_timeout", 60.0)
+                .build();
+    }
+}
+```
+{{< /tab >}}
+{{< tab "YAML" >}}
+```yaml
+media_model_connections:
+  - name: media
+    clazz: dashscope
+    type: python
+    request_timeout: 60
+```
+{{< /tab >}}
+{{< /tabs >}}
+
+To register a shared connection through the execution environment instead, call
+`agents_env.add_resource("media", ResourceType.MEDIA_MODEL_CONNECTION, 
descriptor)`
+in Python (or `agentsEnv.addResource(...)` in Java). See
+[Registering Resources]({{< ref 
"docs/development/create-agent/resources#registering-resources" >}})
+and [YAML Resources]({{< ref "docs/development/create-agent/yaml#resources" 
>}}).
+
+### Declare and use a media model setup
+
+Declare a media model setup with a connection, model name, and default
+parameters, then retrieve it by name in an Action:
+
+{{< 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.",
+    model_parameters={"n": 1},
+    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.chat.messages.ImageBlock;
+import org.apache.flink.agents.api.media.BaseImageGenerationModelSetup;
+import org.apache.flink.agents.api.media.ImageGenerationRequest;
+import org.apache.flink.agents.api.media.MediaResult;
+import org.apache.flink.agents.api.resource.PythonResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+import org.apache.flink.agents.api.resource.ResourceName;
+import org.apache.flink.agents.api.resource.ResourceType;
+
+import java.time.Duration;
+import java.util.Map;
+
+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.", 
Map.of("n", 1)),

Review Comment:
   `ImageGenerationRequest` only provides `of(String)`, so this example does 
not compile. Could we use the builder to set the per-call parameters?
   
   ```java
   ImageGenerationRequest.builder("A navy notebook on a white desk.")
           .modelParameter("n", 1)
           .build()
   ```



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