44public record
OpenAiConfig(String apiKey, URI baseUri, Duration timeout, String organization, String project,
45 Map<String, String> defaultHeaders) {
47 private static final URI DEFAULT_BASE_URI = URI.create(
"https://api.openai.com/v1/");
48 private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(30);
63 Objects.requireNonNull(apiKey,
"apiKey");
64 if (apiKey.isBlank()) {
65 throw new IllegalArgumentException(
"apiKey must not be blank");
67 baseUri = normalizeBaseUri(baseUri ==
null ? DEFAULT_BASE_URI : baseUri);
68 timeout = timeout ==
null ? DEFAULT_TIMEOUT : timeout;
69 organization = organization ==
null ?
"" : organization;
70 project = project ==
null ?
"" : project;
71 defaultHeaders = defaultHeaders ==
null ? Map.of() : Map.copyOf(defaultHeaders);
81 return new OpenAiConfig(apiKey, DEFAULT_BASE_URI, DEFAULT_TIMEOUT,
"",
"", Map.of());
89 public URI chatCompletionsUri() {
90 return baseUri.resolve(
"chat/completions");
93 private static URI normalizeBaseUri(
final URI baseUri) {
94 final String value = baseUri.toString();
95 return URI.create(value.endsWith(
"/") ? value : value +
"/");
record OpenAiConfig(String apiKey, URI baseUri, Duration timeout, String organization, String project, Map< String, String > defaultHeaders)
Configuración para conectarse a la API de OpenAI.