davidradl commented on code in PR #27163: URL: https://github.com/apache/flink/pull/27163#discussion_r2472646565
########## flink-models/flink-model-openai/src/main/java/org/apache/flink/model/openai/OpenAIOptions.java: ########## @@ -0,0 +1,234 @@ +/* + * 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.model.openai; + +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigOptions; +import org.apache.flink.configuration.description.Description; + +import java.time.Duration; + +import static org.apache.flink.configuration.description.TextElement.code; +import static org.apache.flink.configuration.description.TextElement.text; + +/** Options for OpenAI API Model Functions. */ +public class OpenAIOptions { + + // ------------------------------------------------------------------------ + // Common Options + // ------------------------------------------------------------------------ + + 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()); + + public static final ConfigOption<AbstractOpenAIModelFunction.ErrorHandlingStrategy> + ERROR_HANDLING_STRATEGY = + ConfigOptions.key("error-handling-strategy") + .enumType(AbstractOpenAIModelFunction.ErrorHandlingStrategy.class) + .defaultValue(AbstractOpenAIModelFunction.ErrorHandlingStrategy.RETRY) + .withDescription( + Description.builder() + .text( Review Comment: Can we retry the requests when the error is retryable? -- 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]
