question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Hardcoded Endpoint for OpenAI

See original GitHub issue

Library name and version

Azure.AI.OpenAI_1.0.0-beta.6

Describe the bug

Hi Team!

Companies create internal API proxies to avoid direct calls to https://api.openai.com/ . But Azure has OpenAI endpoint hardcoded https://github.com/Azure/azure-sdk-for-net/blob/c8b27f9fca17384a481a1debf565052ffc97b2b9/sdk/openai/Azure.AI.OpenAI/src/Custom/OpenAIClient.cs#L28 without possibility to specify custom endpoint. Constructors use only hardcoded PublicOpenAIEndpoint property https://github.com/Azure/azure-sdk-for-net/blob/c8b27f9fca17384a481a1debf565052ffc97b2b9/sdk/openai/Azure.AI.OpenAI/src/Custom/OpenAIClient.cs#L120-L131

Expected behavior

It should be possible to specify a custom endpoint. Maybe add one more constructor with _nonAzureOpenAIApiKey = openAIApiKey; code. See https://github.com/Azure/azure-sdk-for-net/blob/c8b27f9fca17384a481a1debf565052ffc97b2b9/sdk/openai/Azure.AI.OpenAI/src/Custom/OpenAIClient.cs#L120-L131

Actual behavior

Constructors use only hardcoded PublicOpenAIEndpoint property https://github.com/Azure/azure-sdk-for-net/blob/c8b27f9fca17384a481a1debf565052ffc97b2b9/sdk/openai/Azure.AI.OpenAI/src/Custom/OpenAIClient.cs#L120-L131

Reproduction Steps

OpenAIClient client = new OpenAIClient("your-api-key-from-platform.openai.com");

Response<Completions> response = await client.GetCompletionsAsync(
    "text-davinci-003", // assumes a matching model deployment or model name
    "Hello, world!");

foreach (Choice choice in response.Value.Choices)
{
    Console.WriteLine(choice.Text);
}

Environment

No response

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
trrwilsoncommented, Jul 27, 2023

@gingters – fully understood about environment-variable-based configuration not being viable.

From that second link I shared, there’s also a programmatic mechanism to configure a proxy server via client options; pulling that page together with the OpenAI code, it’d be along the lines of:

var httpClientHandler = new HttpClientHandler()
{
    Proxy = new WebProxy("http://my-enterprise.proxy-server.com"),
};
var httpClientWithProxy = new HttpClient(httpClientHandler);
var openAIClientOptions = new OpenAIClientOptions()
{
    Transport = new HttpClientTransport(httpClientWithProxy),
};
var client = new OpenAIClient(
    endpoint: new Uri("https://destination-aoai-resource.openai.azure.com"),
    new AzureKeyCredential("fake-key-to-be-replaced-by-proxy"),
    openAIClientOptions);

This will configure the OpenAIClient instance to use the underlying HttpClient provided, which has in turn been configured (in code, sans environment variable involvement) to use a proxy.

I’ve scheduled some work for us to add better documentation and test automation coverage to clarify this, but in the interim I’ve validated by hand that this does indeed invoke a proxy request.

0reactions
victor-v-radcommented, Jul 26, 2023

@trrwilson Thank you for sharing the proxy configuration. It works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Hardcoded Endpoint for OpenAI
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer...
Read more >
Getting 400 error with new endpoint url - API
since the endpoint url is changed now my code is giving me this error , failed to open stream: HTTP request failed! HTTP/1.1...
Read more >
GPT models - OpenAI API
Our latest models, gpt-4 and gpt-3.5-turbo , are accessed through the chat completions API endpoint. Currently, only the older legacy models are available ......
Read more >
Moderation Endpoint vs Content Filter alpha - API
I am trying to evaluate potential strategies to “filter out” objectionable content sent by the user. Here are my observations: The new ...
Read more >
Problem with Azure Api and ChatGPT (python)
The problem was solved by removing os.getenv from the code, and writing the given keys and endpoint directly into a variable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found