Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ public static final class ChatModel {
"org.apache.flink.agents.integrations.chatmodels.ollama.OllamaChatModelSetup";

// OpenAI
public static final String OPENAI_CONNECTION =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIChatModelConnection";
public static final String OPENAI_SETUP =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIChatModelSetup";
public static final String OPENAI_COMPLETIONS_CONNECTION =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAICompletionsConnection";
public static final String OPENAI_COMPLETIONS_SETUP =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAICompletionsSetup";

// OpenAI Responses API
public static final String OPENAI_RESPONSES_CONNECTION =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIResponsesModelConnection";
public static final String OPENAI_RESPONSES_SETUP =
"org.apache.flink.agents.integrations.chatmodels.openai.OpenAIResponsesModelSetup";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. According to the documents, the formal name of the API is "Responses API". Let's make it consistent and use RESPONSES (rather than RESPONSE) for the constants and class names.

  2. I'd suggest to also change OPENAI_CONNECTION to OPENAI_COMPLETIONS_CONNECTION, as well as the class names, to avoid confusion.

  3. There are some string constants for referencing java integrations from python codes in resource.py, which should also be updated.

Copy link
Author

@addu390 addu390 Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed those in resource.py, I made the changes to fix naming across the code-base.

Should we also rename OpenAIChatModelConnection to OpenAICompletionsConnection, OpenAIChatModelSetup to OpenAICompletionsSetup for consistency in naming?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also rename OpenAIChatModelConnection to OpenAICompletionsConnection, OpenAIChatModelSetup to OpenAICompletionsSetup for consistency in naming?

Yes, I think we should also change the class names to avoid confusion, as well as the resource.py.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too! Updated the class names and the references.

// Python Wrapper
public static final String PYTHON_WRAPPER_CONNECTION =
Expand Down Expand Up @@ -99,9 +105,9 @@ public static final class Python {
"flink_agents.integrations.chat_models.ollama_chat_model.OllamaChatModelSetup";

// OpenAI
public static final String OPENAI_CONNECTION =
public static final String OPENAI_COMPLETIONS_CONNECTION =
"flink_agents.integrations.chat_models.openai.openai_chat_model.OpenAIChatModelConnection";
public static final String OPENAI_SETUP =
public static final String OPENAI_COMPLETIONS_SETUP =
"flink_agents.integrations.chat_models.openai.openai_chat_model.OpenAIChatModelSetup";

// Tongyi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ public static ResourceDescriptor chatModelConnection() {
.build();
} else if (provider.equals("OPENAI")) {
String apiKey = System.getenv().get("OPENAI_API_KEY");
return ResourceDescriptor.Builder.newBuilder(ResourceName.ChatModel.OPENAI_CONNECTION)
return ResourceDescriptor.Builder.newBuilder(
ResourceName.ChatModel.OPENAI_COMPLETIONS_CONNECTION)
.addInitialArgument("api_key", apiKey)
.build();
} else if (provider.equals("OPENAI_RESPONSES")) {
return ResourceDescriptor.Builder.newBuilder(
ResourceName.ChatModel.OPENAI_RESPONSES_CONNECTION)
.addInitialArgument("api_key", System.getenv().get("OPENAI_API_KEY"))
.build();
} else if (provider.equals("ANTHROPIC")) {
String apiKey = System.getenv().get("ANTHROPIC_API_KEY");
return ResourceDescriptor.Builder.newBuilder(
Expand Down Expand Up @@ -126,7 +132,17 @@ public static ResourceDescriptor chatModel() {
List.of("calculateBMI", "convertTemperature", "createRandomNumber"))
.build();
} else if (provider.equals("OPENAI")) {
return ResourceDescriptor.Builder.newBuilder(ResourceName.ChatModel.OPENAI_SETUP)
return ResourceDescriptor.Builder.newBuilder(
ResourceName.ChatModel.OPENAI_COMPLETIONS_SETUP)
.addInitialArgument("connection", "chatModelConnection")
.addInitialArgument("model", "gpt-4o-mini")
.addInitialArgument(
"tools",
List.of("calculateBMI", "convertTemperature", "createRandomNumber"))
.build();
} else if (provider.equals("OPENAI_RESPONSES")) {
return ResourceDescriptor.Builder.newBuilder(
ResourceName.ChatModel.OPENAI_RESPONSES_SETUP)
.addInitialArgument("connection", "chatModelConnection")
.addInitialArgument("model", "gpt-4o-mini")
.addInitialArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ChatModelIntegrationTest() throws IOException {
}

@ParameterizedTest()
@ValueSource(strings = {"ANTHROPIC", "AZURE", "OLLAMA", "OPENAI"})
@ValueSource(strings = {"ANTHROPIC", "AZURE", "OLLAMA", "OPENAI", "OPENAI_RESPONSES"})
public void testChatModeIntegration(String provider) throws Exception {
Assumptions.assumeTrue(
(OLLAMA.equals(provider) && ollamaReady)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* public class MyAgent extends Agent {
* @ChatModelConnection
* public static ResourceDesc openAI() {
* return ResourceDescriptor.Builder.newBuilder(OpenAIChatModelConnection.class.getName())
* return ResourceDescriptor.Builder.newBuilder(OpenAICompletionsConnection.class.getName())
* .addInitialArgument("api_key", System.getenv("OPENAI_API_KEY"))
* .addInitialArgument("api_base_url", "https://api.openai.com/v1")
* .addInitialArgument("timeout", 120)
Expand All @@ -91,15 +91,15 @@
* }
* }</pre>
*/
public class OpenAIChatModelConnection extends BaseChatModelConnection {
public class OpenAICompletionsConnection extends BaseChatModelConnection {

private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<>() {};

private final ObjectMapper mapper = new ObjectMapper();
private final OpenAIClient client;
private final String defaultModel;

public OpenAIChatModelConnection(
public OpenAICompletionsConnection(
ResourceDescriptor descriptor, BiFunction<String, ResourceType, Resource> getResource) {
super(descriptor, getResource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
*
* <p>Responsible for providing per-chat configuration such as model, temperature, tool bindings,
* and additional OpenAI parameters. The setup delegates execution to {@link
* OpenAIChatModelConnection}.
* OpenAICompletionsConnection}.
*
* <p>Example usage:
*
* <pre>{@code
* public class MyAgent extends Agent {
* @ChatModelSetup
* public static ResourceDesc openAI() {
* return ResourceDescriptor.Builder.newBuilder(OpenAIChatModelSetup.class.getName())
* return ResourceDescriptor.Builder.newBuilder(OpenAICompletionsSetup.class.getName())
* .addInitialArgument("connection", "myOpenAIConnection")
* .addInitialArgument("model", "gpt-4o-mini")
* .addInitialArgument("temperature", 0.3d)
Expand All @@ -58,7 +58,7 @@
* }
* }</pre>
*/
public class OpenAIChatModelSetup extends BaseChatModelSetup {
public class OpenAICompletionsSetup extends BaseChatModelSetup {

private static final String DEFAULT_MODEL = "gpt-3.5-turbo";
private static final double DEFAULT_TEMPERATURE = 0.1d;
Expand All @@ -74,7 +74,7 @@ public class OpenAIChatModelSetup extends BaseChatModelSetup {
private final String reasoningEffort;
private final Map<String, Object> additionalArguments;

public OpenAIChatModelSetup(
public OpenAICompletionsSetup(
ResourceDescriptor descriptor, BiFunction<String, ResourceType, Resource> getResource) {
super(descriptor, getResource);
this.temperature =
Expand Down Expand Up @@ -126,7 +126,7 @@ public OpenAIChatModelSetup(
}
}

public OpenAIChatModelSetup(
public OpenAICompletionsSetup(
String model,
double temperature,
Integer maxTokens,
Expand Down Expand Up @@ -188,7 +188,7 @@ private static ResourceDescriptor createDescriptor(
Map<String, Object> additionalArguments,
List<String> tools) {
ResourceDescriptor.Builder builder =
ResourceDescriptor.Builder.newBuilder(OpenAIChatModelSetup.class.getName())
ResourceDescriptor.Builder.newBuilder(OpenAICompletionsSetup.class.getName())
.addInitialArgument("model", model)
.addInitialArgument("temperature", temperature);

Expand Down
Loading