Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.35k stars 1.99k forks source link

[OpenAI] Support for other request path than "/openai" #41438

Open ralscha opened 3 months ago

ralscha commented 3 months ago

Query/Question

Our endpoint on Azure uses a different path /openai-gpt-4o instead of the standard path /openai. We use different API Management setups so we route them to the desired one with this path.

But the Java SDK always adds /openai to the endpoint. Is there a way to overwrite that?

Given this example. The SDK sends the request to https://this-and-that.azure-api.net/openai-gpt-4o/openai/deployments/gpt-4o/chat/completions. Notice the additional /openai/ in the path. But this fails because this URL does not exist.

        String endpoint = "https://this-and-that.azure-api.net/openai-gpt-4o";

        var client = new OpenAIClientBuilder().credential(new AzureKeyCredential(apiKey))
                .endpoint(endpoint)
                .buildClient();

        List<ChatRequestMessage> chatMessages = new ArrayList<>();
        chatMessages.add(new ChatRequestUserMessage("Hello, how are you?"));

        ChatCompletionsOptions chatCompletionsOptions = new ChatCompletionsOptions(
                chatMessages);
        chatCompletionsOptions.setTemperature(0.0);
        chatCompletionsOptions.setMaxTokens(100);

        var response = client.getChatCompletions("gpt-4o", chatCompletionsOptions);
        System.out.println(response.getChoices().get(0).getMessage().getContent());

Setup (please complete the following information if applicable):

mssfang commented 2 months ago

@ralscha Thank you for reaching out to us. The reason why we have a fixed path is from this line. Do you know what the APIM endpoint pattern is? Can the path parameter be any value?

github-actions[bot] commented 2 months ago

Hi @ralscha. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

ralscha commented 2 months ago

@mssfang Our endpoint currently is /openai-gpt-4o. It could be any value. But I can easily fix it in the APIM by creating a path /openai-gpt-4o/openai. The Python SDK from OpenAI does not have a problem with the path /openai-gpt-4o. Looks like their implementation does not hardcode /openai

mssfang commented 2 months ago

@mssfang Our endpoint currently is /openai-gpt-4o. It could be any value. But I can easily fix it in the APIM by creating a path /openai-gpt-4o/openai. The Python SDK from OpenAI does not have a problem with the path /openai-gpt-4o. Looks like their implementation does not hardcode /openai

Yeah. Python SDK is not using the same spec to generate. This hardcode /openai only affect those generated language SDKs based on the spec. Currently, Java is one of them depends on the spec.