semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

KernelConfig.CompletionBackends is closed, cannot add custom ai backend to the kernel.

Open matiazo opened this issue 2 years ago • 4 comments

Can we open CompletionBackends so we can use custom AI backends, my team has a service layer before OpenAI/AzureOpenAI so we need to inject a custom client.

matiazo avatar Mar 23 '23 19:03 matiazo

@matiazo without disclosing private info, could you provide the technical changes you would make? we can try adding support for more scenarios

dluc avatar Mar 24 '23 02:03 dluc

Goal is not add more implementation but open Kernel to accept new implementations of IBackendConfig and ITextCompletionClient. We also need to review usage of IEmbeddingGenerator implementations.

I'm working in a PR but the overall changes so far:

  • add KernelConfig.AddCompletionBackend(IBackendConfig)
  • add public ITextCompletionClient CreateAIBackend() to IBackendConfig
  • Kernel.CreateSemanticFunction - replace a swtich on concrete implementation of IBackendConfig

matiazo avatar Mar 24 '23 05:03 matiazo

right, that's in line with current work in progress:

add KernelConfig.AddCompletionBackend(IBackendConfig)

spot on. Currently the list is hardcoded, we're removing that and simply work with interfaces 👍

add public ITextCompletionClient CreateAIBackend() to IBackendConfig

that could be a temporary stop gap, but we're removing this hard coded assumptions about what kind of AI is used.

Kernel.CreateSemanticFunction - replace a swtich on concrete implementation of IBackendConfig

yup makes sense, in fact I would suggest limiting the changes to a minimum and only in this area, without worrying too much about hardcoding a new option. In other words it's ok following the current approach and hardcoding a new option, because we're taking care of that and it's a rather big change

dluc avatar Mar 24 '23 05:03 dluc

@matiazo I have a PR almost ready addressing this, thanks for raising this issue

dluc avatar Mar 25 '23 22:03 dluc

@matiazo this should help https://github.com/microsoft/semantic-kernel/pull/161 - Here's an example showing how to plug in custom backends: https://github.com/dluc/semantic-kernel/blob/dluc99-backends/samples/dotnet/kernel-syntax-examples/Example16_CustomLLM.cs

dluc avatar Mar 26 '23 22:03 dluc

Updating thread with the link that is now in main https://github.com/microsoft/semantic-kernel/blob/main/samples/dotnet/kernel-syntax-examples/Example16_CustomLLM.cs

awharrison-28 avatar Mar 29 '23 00:03 awharrison-28

Shipped

dluc avatar Mar 31 '23 02:03 dluc