weiqingy commented on code in PR #945:
URL: https://github.com/apache/flink-agents/pull/945#discussion_r3730722571


##########
integrations/chat-models/openai/src/main/java/org/apache/flink/agents/integrations/chatmodels/openai/VLLMChatModelConnection.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+package org.apache.flink.agents.integrations.chatmodels.openai;
+
+import org.apache.flink.agents.api.resource.ResourceContext;
+import org.apache.flink.agents.api.resource.ResourceDescriptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Chat model connection for a <a href="https://docs.vllm.ai";>vLLM</a> server.
+ *
+ * <p>vLLM exposes an OpenAI-compatible API, so this connection reuses {@link
+ * OpenAICompletionsConnection} with vLLM-friendly defaults:
+ *
+ * <ul>
+ *   <li><b>api_base_url</b> (optional): defaults to {@code 
http://localhost:8000/v1}, the default
+ *       address of {@code vllm serve}
+ *   <li><b>api_key</b> (optional): defaults to a placeholder value, since 
vLLM servers started
+ *       without {@code --api-key} do not require a credential (the underlying 
OpenAI SDK requires a
+ *       non-empty key, but the server ignores it). Set it explicitly when the 
server is started
+ *       with {@code --api-key}.
+ * </ul>
+ *
+ * <p>All other connection arguments ({@code timeout}, {@code max_retries}, 
{@code default_headers},
+ * {@code model}) behave exactly as in {@link OpenAICompletionsConnection}.
+ *
+ * <p>Example usage:
+ *
+ * <pre>{@code
+ * public class MyAgent extends Agent {
+ *   @ChatModelConnection
+ *   public static ResourceDescriptor vllm() {
+ *     return 
ResourceDescriptor.Builder.newBuilder(VLLMChatModelConnection.class.getName())
+ *             .addInitialArgument("api_base_url", 
"http://my-vllm-host:8000/v1";)
+ *             .build();
+ *   }
+ * }
+ * }</pre>
+ */
+public class VLLMChatModelConnection extends OpenAICompletionsConnection {

Review Comment:
   `main` has since grown a native structured-output path on the parents: 
`OpenAICompletionsConnection.supportsNativeStructuredOutput(String)` in Java, 
`supports_native_structured_output` in the Python `OpenAIChatModelConnection`. 
It gates strict `json_schema` on an allowlist whose own comment reads "Models 
for which OpenAI documents json_schema strict Structured Outputs support": 
prefixes `gpt-4o-mini`, `gpt-4.1`, `gpt-5`, `o3`, `o4-mini`, plus exact 
`gpt-4o` and `o1`.
   
   Inheriting that unchanged keys the predicate on OpenAI's hosted names, while 
a vLLM deployment's model name is whatever it serves, so the match is 
coincidental both ways. `Qwen/Qwen2.5-7B-Instruct` never matches and always 
takes the prompt fallback; a server serving `gpt-4o`, or any name starting with 
`gpt-4.1` / `gpt-5` / `o3`, does match and gets strict OpenAI `json_schema` 
sent to it.
   
   Both hooks look built to be overridden, `protected` in Java and public in 
Python. Nothing to fix at this head since your branch predates that merge. 
Would overriding them belong in this PR, or would you rather handle it when you 
rebase?



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