weaviate
weaviate copied to clipboard
generative-openai module does not use `baseURL` when calling Azure OpenAI API
How to reproduce this bug?
Example Configuration of the generative-openai module when trying to connect to Azure OpenAI that causes this issue:
Example using the v4 client:
generative_config=wvc.config.Configure.Generative.azure_openai(
base_url=azure_base_url,
resource_name = "some-resource-name",
deployment_id="gpt-4-32k",
temperature=0.1,
top_p=0.5),
What is the expected behavior?
The expected behavior would be that the baseURL value would exist in the if statement of modules/generative-openai/clients/openai.go and it would take precedence over the resourceName and create a URL that follows the following structure:
https://<baseURL>/openai/deployments/<deploymentID>/chat/completions?api-version=2023-03-15-preview
Since some companies use a proxy URL, in this case, the baseURL, although you are mandating in the code that both resourceName and deploymentID are provided, you should first check if baseURL is provided and construct the URL using that instead of the resourceName for Azure OpenAI.
Ideally the openai.go file would look something like this since my company is not using the openai.azure.com domain but their own proxy domain:
func buildUrlFn(isLegacy bool, resourceName, deploymentID, baseURL string) (string, error) {
if resourceName != "" && deploymentID != "" {
if baseURL != "" {
host := "https://" + baseURL
}
else {
host := "https://" + resourceName + ".openai.azure.com"
}
path := "openai/deployments/" + deploymentID + "/chat/completions"
queryParam := "api-version=2023-03-15-preview"
return fmt.Sprintf("%s/%s?%s", host, path, queryParam), nil
}
path := "/v1/chat/completions"
if isLegacy {
path = "/v1/completions"
}
return url.JoinPath(baseURL, path)
What is the actual behavior?
The actual behavior is that when Azure OpenAI is used, since resourceName and deploymentID are required to be non empty and the baseURL is not used inside the if statement of modules/generative-openai/clients/openai.go, you end up creating the wrong URL which in this case would be:
https://<resourceName>.openai.azure.com/openai/deployments/<deploymentID>/chat/completions?api-version=2023-03-15-preview
In the case of the configuration I provided earlier, I end up with the following wrong URL:
Post "https://some-resource-name.openai.azure.com/openai/deployments/gpt-4-32k/chat/completions?api-version=2023-03-15-preview":
dial tcp: lookup some-resource-name.openai.azure.com on <some_ip>:53: no such host.
Supporting information
No response
Server Version
1.23.6
Code of Conduct
- [X] I have read and agree to the Weaviate's Contributor Guide and Code of Conduct
@antas-marcin I saw you last worked on that file so you might be the best person to look into this
@OSS-GR I have created a PR that addresses this issue.
Hi @antas-marcin I saw your PR. Thank you for working on this. I left a comment for you about the queryParam in the PR you shared.
I'm having this issue as well. Just saw the PR #4124, Can we also make the API version configurable accessing using Azure OpenAI through BaseURL? My org currently supports OPENAI_API_VERSION = "2023-03-15-preview"
Thanks you for working on this @antas-marcin, can we have this issue (baseURL & apiVersion) fixed across multiple modules. ex: #3966, modules/text2vec-openai/clients/openai.go