microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.39k stars 3.15k forks source link

.Net: Cannot specify apiVersion on AzureOpenAIChatCompletion #6446

Open MitaWinata opened 3 months ago

MitaWinata commented 3 months ago

If i am not mistaken , currently apiService is not yet open as a param yet in AzureOpenAIChatCompletion.

In AzureOpenAIChatCompletionService.cs

    public AzureOpenAIChatCompletionService(
        string deploymentName,
        string endpoint,
        string apiKey,
        string? modelId = null,
        HttpClient? httpClient = null,
        ILoggerFactory? loggerFactory = null)
    {
        this._core = new(deploymentName, endpoint, apiKey, httpClient, loggerFactory?.CreateLogger(typeof(AzureOpenAIChatCompletionService)));

        this._core.AddAttribute(AIServiceExtensions.ModelIdKey, modelId);
    }

or in OpenAIServiceCollectionExtensions,cs

  public static IKernelBuilder AddAzureOpenAIChatCompletion(
      this IKernelBuilder builder,
      string deploymentName,
      string endpoint,
      string apiKey,
      string? serviceId = null,
      string? modelId = null,
      HttpClient? httpClient = null)
  {
...
}

We would like to be able to specify which version of the api we want to use.

        public AzureOpenAIChatCompletionService(
        string deploymentName,
        string endpoint,
        string apiKey,
        string? modelId = null,
        **string? apiVersion= null,**
        HttpClient? httpClient = null,
        ILoggerFactory? loggerFactory = null)
    {
        this._core = new(deploymentName, endpoint, apiKey, httpClient, loggerFactory?.CreateLogger(typeof(AzureOpenAIChatCompletionService)));

        this._core.AddAttribute(AIServiceExtensions.ModelIdKey, modelId);

       **this._core.AddAttribute(AIServiceExtensions.ApiVersionKey, apiVersion);**
    }

and

 public static IKernelBuilder AddAzureOpenAIChatCompletion(
      this IKernelBuilder builder,
      string deploymentName,
      string endpoint,
      string apiKey,
      string? serviceId = null,
      string? modelId = null,
     **string? apiVersion = null,**
      HttpClient? httpClient = null)
  {
...
}
dmytrostruk commented 3 months ago

@MitaWinata Thanks for reporting this issue!

Since the number of possible parameters is growing, I would probably handle this issue after we introduce Options classes for service classes and extension methods: https://github.com/microsoft/semantic-kernel/issues/6081

MitaWinata commented 3 months ago

Thanks @dmytrostruk for replying. Is there any ETA on when this will be introduced?

dmytrostruk commented 3 months ago

@MitaWinata Options classes are not prioritized at the moment, but we will try to resolve it in upcoming weeks. After this, it should be relatively easy to add new ApiVersion property.

In theory, you should be able to specify API version today in different way, by providing your own HttpClient in AzureOpenAIChatCompletionService constructor/extension method. Since API version is a query parameter (e.g. /completions?api-version=2024-02-01), you can try to modify request URL by adding API version to it. Would it be possible for you to test this approach and see if it works?