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

Implemented OpenAI Chat Complations.

Open SOE-YoungS opened this issue 2 years ago • 2 comments

Motivation and Context

Description

I've branched the current Completions implementation and have built out a Chat Completions implementation that is working with Open AI's Chat Completions endpoint.

Azure OpenAI Chat Completions are not implemented yet. Neither is message history (context), or token handling.

Would really appreciate some feedback on this.

Example Usage

Instantiate a Kernel instance via dependency injection (other other means). Then refer to below code for an example of how to interact with the Open AI Chat Completions endpoint.

            IKernel sk = _sk;
            var chatPromptTemplateConfig = new ChatPromptTemplateConfig();
            var chatPromptTemplate = new ChatPromptTemplate(string.Empty, chatPromptTemplateConfig, sk);
            var skChatFunctionConfig = new SemanticChatFunctionConfig(chatPromptTemplateConfig, chatPromptTemplate);
            pipeline = sk.RegisterSemanticChatFunction("ChatBot", "completion", skChatFunctionConfig);
            
            Console.WriteLine("Please enter a prompt.");
            var prompt = string.Empty;
            while(string.isNullOrEmpty(prompt))
            {
                prompt = Console.ReadLine();
            }
            var response = await sk.RunChatAsync(prompt, pipeline);
            
            Console.WriteLine(response.Result);

Contribution Checklist

  • [ ] The code builds clean without any errors or warnings
  • [ ] The PR follows SK Contribution Guidelines (https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
  • [ ] The code follows the .NET coding conventions (https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) verified with dotnet format
  • [ ] All unit tests pass, and I have added new tests where possible
  • [ ] I didn't break anyone :smile:

SOE-YoungS avatar Mar 24 '23 22:03 SOE-YoungS

@microsoft-github-policy-service agree

SOE-YoungS avatar Mar 24 '23 22:03 SOE-YoungS

Closed as @dluc's #161 is superior!

SOE-YoungS avatar Mar 26 '23 23:03 SOE-YoungS