Skip to content
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

How to provide custom endpoint for Azure OpenAi service? (gateway URL) #1272

Closed
egarkavy opened this issue May 15, 2023 · 9 comments · Fixed by #1792
Closed

How to provide custom endpoint for Azure OpenAi service? (gateway URL) #1272

egarkavy opened this issue May 15, 2023 · 9 comments · Fixed by #1792
Assignees
Labels
help wanted This would make a good PR

Comments

@egarkavy
Copy link

In my company we use gateway url to access Azure open AI service to do chat completions. It looks like this: https://xxx-xxx-openai.azure-api.net.
From your sourcecode I see that endpoint is set directly in the completeionWithRetry method
image

Is there any way to work with your Azure OpenAI class but having custom endpoint ?

@simpdanny
Copy link

simpdanny commented May 16, 2023

Same issue here. I personally hope the endpoint could be modified in the form of
${this.azureOpenApiBasePath}/openai/deployments/${azureOpenAIApiDeploymentName}.

But for this issue, you could somewhat override endpoint by providing basePath/baseOptions.

const model = new ChatOpenAI(
    { 
          openAIApiKey: xxx,
          modelName: <my_deployment>
    },
    new Configuration (
          basePath: "https://<my_endpoint_path>/openai/deployments/<my_deployment>",
          baseOptions: {
              'headers' : { 'api-key': xxx, 'Host': yyy },
              'params' : { 'api-version': zzz }
          }
    )
)

@nfcampos nfcampos added the help wanted This would make a good PR label May 17, 2023
@nfcampos
Copy link
Collaborator

Yes, this would be a good change to make

@egarkavy
Copy link
Author

egarkavy commented May 31, 2023

Just in case the only one option I found right now is to override private client prop of the base class. I basically copy pasted the code which instantiates it in the internal implementation

class AzureOpenAi extends ChatOpenAI {
  constructor(
    fields: AzureOpenAiConfig &
      Partial<OpenAIChatInput> &
      Partial<AzureOpenAIInput> &
      BaseChatModelParams & {
        concurrency?: number;
        cache?: boolean;
        openAIApiKey?: string;
      },
    configuration?: ConfigurationParameters,
  ) {
    super(
      {
        ...fields,
      },
      configuration,
    );

    const endpoint = `https://${fields.baseUrl}/openai/deployments/${fields.azureOpenAIApiDeploymentName}`;
 
    // this is actually an internal code but with custom overrides
    const clientConfig = new Configuration({
      ...(this as any).clientConfig,
      basePath: endpoint,
      baseOptions: {
        timeout: this.timeout,
        ...(this as any).clientConfig.baseOptions,
      },
    });
    (this as any).client = new OpenAIApi(clientConfig);
  }
}

@govind-kumarr
Copy link

Yes, this would be a good change to make

can you assign this to me

@chelouche9
Copy link

@nfcampos if this problem is still not taken care of I can do it. Please let me know :)

@govind-kumarr
Copy link

@nfcampos if this problem is still not taken care of I can do it. Please let me know :)

yes go ahead

@chelouche9
Copy link

By the way, I think there are two ways to solve it.

  1. Adding a new property to the class (azureOpenAIApiDomainName) that has a default value of "openai.azure.com"
  2. Adding a custom domain property that overrides the url concatenation entirely.

@nfcampos what do you think?

@holwerda
Copy link

By the way, I think there are two ways to solve it.

  1. Adding a new property to the class (azureOpenAIApiDomainName) that has a default value of "openai.azure.com"
  2. Adding a custom domain property that overrides the url concatenation entirely.

@nfcampos what do you think?

That would be awesome to allow a custom domain IMO

@clemenspeters
Copy link
Contributor

clemenspeters commented Jun 28, 2023

Thanks for raising this issue @egarkavy 👏 👍

I created a PR to suggest a solution for this. ✅
What's the fastest way to get this reviewed and merged? 🚀
Can I support this process in any way? 😃

CC: @nfcampos @chelouche9 @holwerda @govind-kumarr

jacoblee93 added a commit that referenced this issue Jul 5, 2023
* 🎨 Add util function to generate openAI endpoint.

* ✅ Add unit tests for openAI endpoint util function.

* 🏷️ Add 'azureOpenAiBasePath' to 'AzureOpenAIInput'.

* ✨ Use new getEndpoint function with full support for AZURE_OPENAI_BASE_PATH env.

* 📝 Add AZURE_OPENAI_BASE_PATH env to documentation.

* 🎨 Auto code style fixes from `yarn format`.

* ✏️ Remove trailing slash.

* ✏️ Capitalize AI to match convention.

* Add check for azureOpenAIApiKey.

* Make full azureOpenAIBasePath configurable.

* ✅ Update unit test for new azureOpenAIBasePath.

* 📝 Update documentation on azureOpenAIBasePath.

* Fix case for normal OpenAI calls, lint and format

* 🎨 `yarn format` auto code style fixes.

---------

Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted This would make a good PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants