Skip to content

Construct non-Azure OpenAI clients for default and EU endpoints #43228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -3,6 +3,7 @@
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.azure.ai.openai;

import static com.azure.ai.openai.implementation.NonAzureOpenAIClientImpl.EU_OPEN_AI_ENDPOINT;
import static com.azure.ai.openai.implementation.NonAzureOpenAIClientImpl.OPEN_AI_ENDPOINT;

import com.azure.ai.openai.implementation.NonAzureOpenAIClientImpl;
Expand Down Expand Up @@ -333,7 +334,7 @@ private HttpPipeline createHttpPipeline() {
private NonAzureOpenAIClientImpl buildInnerNonAzureOpenAIClient() {
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
NonAzureOpenAIClientImpl client
= new NonAzureOpenAIClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter());
= new NonAzureOpenAIClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint);
return client;
}

Expand Down Expand Up @@ -363,10 +364,10 @@ public OpenAIClient buildClient() {

/**
* OpenAI service can be used by either not setting the endpoint or by setting the endpoint to start with
* "https://api.openai.com/"
* "https://api.openai.com/" or "https://eu.api.openai.com/".
*/
private boolean useNonAzureOpenAIService() {
return endpoint == null || endpoint.startsWith(OPEN_AI_ENDPOINT);
return endpoint == null || endpoint.startsWith(OPEN_AI_ENDPOINT) || endpoint.startsWith(EU_OPEN_AI_ENDPOINT);
Copy link
Author

Choose a reason for hiding this comment

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

This isn't the most extensible design. Might make more sense to check for whether the endpoint contains the OpenAI domain, but my security best practices are a bit shaky and I'm not sure how easily that could be exploited to direct requests somewhere they're not supposed to go.

}

private void validateClient() {
Expand Down
Loading
Loading