Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Semantic Kernel ITextCompletion As ITextGeneration #183

Merged
merged 17 commits into from
Mar 18, 2024

Conversation

xbotter
Copy link
Contributor

@xbotter xbotter commented Dec 3, 2023

Motivation and Context (Why the change? What's the scenario?)

This seems somewhat recursive, to use Semantic Kernel as the infrastructure for Kernel Memory. However, the interfaces of both are very similar. So, I added an adapter that can directly use SK's ITextCompletion to maximize the reuse of LLM adapted for SK.

High level description (Approach, Design)

Add a new file SemanticKernelTextGeneration.cs to implement the ITextGeneration interface for Semantic Kernel Text Completion. This class provides the functionality to generate text asynchronously based on a prompt and text generation options. The AIRequestSettings are converted from the TextGenerationOptions to set parameters such as temperature, top-p, presence penalty, frequency penalty, stop sequences, max tokens, results per prompt, and token selection biases. The SemanticKernelTextGeneration class is added to the KernelMemoryBuilderExtensions as an extension method to configure the Semantic Kernel Text Completion service.
@dluc
Copy link
Collaborator

dluc commented Dec 6, 2023

could you upgrade the code to work with SK RC2 please? (e.g. rebase to latest main)

@xbotter
Copy link
Contributor Author

xbotter commented Dec 6, 2023

Updated

Copy link
Collaborator

@dluc dluc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a few changes, mostly moving the files from Core to Abstractions. There's an error in the new example, easy fix

@xbotter xbotter requested a review from dluc December 6, 2023 07:08
@dluc
Copy link
Collaborator

dluc commented Dec 7, 2023

putting on hold this, until #189 is merged. Some important changes to accommodate third-party/OSS models.

@xbotter
Copy link
Contributor Author

xbotter commented Dec 8, 2023

The new changes have brought some configurable options, and I will adapt the interface as soon as possible.

@dluc
Copy link
Collaborator

dluc commented Dec 8, 2023

#189 merged

please note that there are some extra feature in ITextGenerator about tokenization, that are critical to execute RAG and other prompts correctly, also to size the partitioning/chunking.

I would be careful not to inject SK interface without including the tokenization logic, because it would go against the intended use.

- Refactored the Semantic Kernel Text Generation and Embedding Generation classes to improve code organization and readability.
- Added a new class, SemanticKernelConfig, to store configuration settings for the Text Generator and Embedding Generator.
- Updated the KernelMemoryBuilderExtensions class to include methods for injecting the new Text Generator and Embedding Generator implementations.
- The Text Generator and Embedding Generator now use the provided configuration and tokenizer instances.
- Renamed the SemanticKernelTextGeneration class to SemanticKernelTextGenerator to better reflect its purpose.
- The SemanticKernelTextEmbeddingGenerator class now implements the ITextEmbeddingGenerator interface and uses the provided Text Tokenizer to count tokens.
- The GenerateEmbeddingAsync method in the SemanticKernelTextEmbeddingGenerator class now calls the GenerateEmbeddingAsync method in the ITextEmbeddingGeneration instance.
- The CountTokens method in the SemanticKernelTextEmbeddingGenerator class now calls the CountTokens method in the provided Text Tokenizer.
- Update SemanticKernelTextEmbeddingGenerator.cs to add a using statement and modify the constructor to handle null arguments.
- Update SemanticKernelTextGenerator.cs to add a using statement and modify the constructor to handle null arguments.
@xbotter
Copy link
Contributor Author

xbotter commented Dec 8, 2023

@dluc updated, please review again.

@dluc
Copy link
Collaborator

dluc commented Dec 14, 2023

Looks like there are more breaking changes coming from RC4, let's wait until next week to reduce churn

@dluc dluc merged commit 7f72ce4 into microsoft:main Mar 18, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants