semantic-kernel
semantic-kernel copied to clipboard
Implemented OpenAI Chat Complations.
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:
@microsoft-github-policy-service agree
Closed as @dluc's #161 is superior!