Class OpenAIMultiModalTool
java.lang.Object
io.agentscope.extensions.model.openai.tool.OpenAIMultiModalTool
OpenAI multimodal tool.
Supports:
- Text to image(s)
- Image to text (via vision models)
- Text to audio (speech)
- Audio to text (transcription)
This implementation uses the custom OpenAIClient HTTP client instead of the OpenAI
Java SDK, keeping the core module lightweight and dependency-free.
Please refer to the OpenAI documentation for more details.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedOpenAIMultiModalTool(OpenAIClient client) Create a new OpenAIMultiModalTool with custom client (for testing).protectedOpenAIMultiModalTool(OpenAIClient client, String defaultModelName) Create a new OpenAIMultiModalTool with custom client and default model (for testing).OpenAIMultiModalTool(String apiKey) Create a new OpenAIMultiModalTool with default base URL.OpenAIMultiModalTool(String apiKey, String baseUrl) Create a new OpenAIMultiModalTool with custom base URL.OpenAIMultiModalTool(String apiKey, String baseUrl, String defaultModelName) Create a new OpenAIMultiModalTool with custom base URL and default vision model. -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock>openaiAudioToText(String audioUrl, String model, String language, String prompt, String responseFormat, Double temperature) Convert audio to text (transcription) using OpenAI Whisper models.reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock>openaiImageToText(String imageUrls, String prompt, String model, Integer maxTokens) Convert image(s) to text using vision models.reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock>Convert text to audio (speech) using OpenAI TTS models.reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock>openaiTextToImage(String prompt, String model, Integer n, String size, String quality, String responseFormat) Generate image(s) based on the given prompt.
-
Constructor Details
-
OpenAIMultiModalTool
Create a new OpenAIMultiModalTool with default base URL.- Parameters:
apiKey- the OpenAI API key
-
OpenAIMultiModalTool
Create a new OpenAIMultiModalTool with custom base URL.- Parameters:
apiKey- the OpenAI API keybaseUrl- the base URL (null for default https://api.openai.com)
-
OpenAIMultiModalTool
Create a new OpenAIMultiModalTool with custom base URL and default vision model.- Parameters:
apiKey- the OpenAI API keybaseUrl- the base URL (null for default https://api.openai.com)defaultModelName- the default vision model name used when the caller omits the model parameter (e.g., "gpt-4o" for OpenAI, or your backend's vision model name)
-
OpenAIMultiModalTool
Create a new OpenAIMultiModalTool with custom client (for testing).- Parameters:
client- the OpenAI client
-
OpenAIMultiModalTool
Create a new OpenAIMultiModalTool with custom client and default model (for testing).- Parameters:
client- the OpenAI clientdefaultModelName- the default vision model name
-
-
Method Details
-
openaiTextToImage
@Tool(name="openai_text_to_image", description="Generate image(s) based on the given prompt using OpenAI DALL-E models. Returns image URL(s) or base64 data.") public reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock> openaiTextToImage(@ToolParam(name="prompt",description="The text prompt to generate image") String prompt, @ToolParam(name="model",description="The model to use, e.g., \'dall-e-3\', \'dall-e-2\'",required=false) String model, @ToolParam(name="n",description="The number of images to generate (1 for dall-e-3, 1-10 for dall-e-2)",required=false) Integer n, @ToolParam(name="size",description="Size of the image, e.g., \'1024x1024\', \'1792x1024\', \'1024x1792\'",required=false) String size, @ToolParam(name="quality",description="The quality of the image (\'standard\' or \'hd\' for dall-e-3)",required=false) String quality, @ToolParam(name="response_format",description="The format of the response (\'url\' or \'b64_json\')",required=false) String responseFormat) Generate image(s) based on the given prompt.- Parameters:
prompt- the text prompt to generate imagemodel- the model to use (e.g., "dall-e-3", "dall-e-2")n- the number of images to generate (1 for dall-e-3, 1-10 for dall-e-2)size- the size of the image (e.g., "1024x1024", "1792x1024", "1024x1792")quality- the quality of the image ("standard" or "hd" for dall-e-3)responseFormat- the format of the response ("url" or "b64_json")- Returns:
- a ToolResultBlock containing the generated image(s)
-
openaiImageToText
@Tool(name="openai_image_to_text", description="Convert image(s) to text using OpenAI vision models. Analyzes images and returns text descriptions.") public reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock> openaiImageToText(@ToolParam(name="image_urls",description="The URLs of the images to analyze (comma-separated)") String imageUrls, @ToolParam(name="prompt",description="The text prompt describing what to extract from the images",required=false) String prompt, @ToolParam(name="model",description="The vision model to use (leave empty to use the configured default)",required=false) String model, @ToolParam(name="max_tokens",description="The maximum number of tokens in the response",required=false) Integer maxTokens) Convert image(s) to text using vision models.- Parameters:
imageUrls- the URLs of the images to analyzeprompt- the text prompt describing what to extract from the imagesmodel- the vision model to use (leave empty to use the configured default)maxTokens- the maximum number of tokens in the response- Returns:
- a ToolResultBlock containing the text description of the images
-
openaiTextToAudio
@Tool(name="openai_text_to_audio", description="Convert text to audio (speech) using OpenAI TTS models. Returns audio as base64 data.") public reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock> openaiTextToAudio(@ToolParam(name="text",description="The text to convert to speech") String text, @ToolParam(name="model",description="The TTS model to use, e.g., \'tts-1\', \'tts-1-hd\'",required=false) String model, @ToolParam(name="voice",description="The voice to use: \'alloy\', \'echo\', \'fable\', \'onyx\', \'nova\', \'shimmer\'",required=false) String voice, @ToolParam(name="response_format",description="The audio format: \'mp3\', \'opus\', \'aac\', \'flac\'",required=false) String responseFormat, @ToolParam(name="speed",description="The speed of the speech (0.25 to 4.0)",required=false) Double speed) Convert text to audio (speech) using OpenAI TTS models.- Parameters:
text- the text to convert to speechmodel- the TTS model to use (e.g., "tts-1", "tts-1-hd")voice- the voice to use ("alloy", "echo", "fable", "onyx", "nova", "shimmer")responseFormat- the audio format ("mp3", "opus", "aac", "flac")speed- the speed of the speech (0.25 to 4.0)- Returns:
- a ToolResultBlock containing the audio as base64 data
-
openaiAudioToText
@Tool(name="openai_audio_to_text", description="Convert audio to text (transcription) using OpenAI Whisper models. Requires audio file URL.") public reactor.core.publisher.Mono<io.agentscope.core.message.ToolResultBlock> openaiAudioToText(@ToolParam(name="audio_url",description="The URL of the audio file to transcribe") String audioUrl, @ToolParam(name="model",description="The transcription model to use, e.g., \'whisper-1\'",required=false) String model, @ToolParam(name="language",description="The language of the audio (ISO-639-1 code, optional)",required=false) String language, @ToolParam(name="prompt",description="Optional text to guide the model\'s style",required=false) String prompt, @ToolParam(name="response_format",description="The format of the response: \'json\', \'text\', \'verbose_json\', etc.",required=false) String responseFormat, @ToolParam(name="temperature",description="The temperature for sampling (0.0 to 1.0)",required=false) Double temperature) Convert audio to text (transcription) using OpenAI Whisper models.Note: This requires multipart/form-data upload, which is not yet fully supported. This is a placeholder implementation.
- Parameters:
audioUrl- the URL of the audio file to transcribemodel- the transcription model to use (e.g., "whisper-1")language- the language of the audio (ISO-639-1 code, optional)prompt- optional text to guide the model's styleresponseFormat- the format of the response ("json", "text", "verbose_json", etc.)temperature- the temperature for sampling (0.0 to 1.0)- Returns:
- a ToolResultBlock containing the transcribed text
-