yunfengzhou-hub commented on code in PR #27163:
URL: https://github.com/apache/flink/pull/27163#discussion_r2481091843


##########
flink-models/flink-model-openai/src/main/java/org/apache/flink/model/openai/AbstractOpenAIModelFunction.java:
##########
@@ -31,75 +28,51 @@
 import org.apache.flink.table.functions.FunctionContext;
 import org.apache.flink.table.types.logical.LogicalType;
 import org.apache.flink.table.types.logical.VarCharType;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.Preconditions;
 
 import com.openai.client.OpenAIClientAsync;
+import com.openai.errors.OpenAIIoException;
+import com.openai.errors.OpenAIServiceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.annotation.Nullable;
 
+import java.io.IOException;
+import java.time.Duration;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
-import static org.apache.flink.configuration.description.TextElement.code;
-
 /** Abstract parent class for {@link AsyncPredictFunction}s for OpenAI API. */
 public abstract class AbstractOpenAIModelFunction extends AsyncPredictFunction 
{
     private static final Logger LOG = 
LoggerFactory.getLogger(AbstractOpenAIModelFunction.class);
 
-    public static final ConfigOption<String> ENDPOINT =
-            ConfigOptions.key("endpoint")
-                    .stringType()
-                    .noDefaultValue()
-                    .withDescription(
-                            Description.builder()
-                                    .text(
-                                            "Full URL of the OpenAI API 
endpoint, e.g., %s or %s",
-                                            
code("https://api.openai.com/v1/chat/completions";),
-                                            
code("https://api.openai.com/v1/embeddings";))
-                                    .build());
-
-    public static final ConfigOption<String> API_KEY =
-            ConfigOptions.key("api-key")
-                    .stringType()
-                    .noDefaultValue()
-                    .withDescription("OpenAI API key for authentication.");
-
-    public static final ConfigOption<String> MODEL =
-            ConfigOptions.key("model")
-                    .stringType()
-                    .noDefaultValue()
-                    .withDescription(
-                            Description.builder()
-                                    .text(
-                                            "Model name, e.g., %s, %s.",
-                                            code("gpt-3.5-turbo"), 
code("text-embedding-ada-002"))
-                                    .build());
-
-    public static final ConfigOption<Integer> MAX_CONTEXT_SIZE =
-            ConfigOptions.key("max-context-size")
-                    .intType()
-                    .noDefaultValue()
-                    .withDescription(
-                            "Max number of tokens for context. 
context-overflow-action would be triggered if this threshold is exceeded.");
-
-    public static final ConfigOption<ContextOverflowAction> 
CONTEXT_OVERFLOW_ACTION =
-            ConfigOptions.key("context-overflow-action")
-                    .enumType(ContextOverflowAction.class)
-                    .defaultValue(ContextOverflowAction.TRUNCATED_TAIL)
-                    .withDescription(
-                            Description.builder()
-                                    .text("Action to handle context overflows. 
Supported actions:")
-                                    .linebreak()
-                                    
.text(ContextOverflowAction.getAllValuesAndDescriptions())
-                                    .build());
+    private static final Set<Integer> RETRYABLE_ERROR_CODES =
+            new HashSet<>() {
+                {
+                    add(408); // Retry on request timeouts
+                    add(409); // Retry on lock timeouts
+                    add(429); // Retry on rate limits
+                    add(500); // Retry internal errors

Review Comment:
   Thanks for the suggestion. Have used RetryingHttpClient to simplify the 
implementation and avoid defining retryable error codes.



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