-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump SK to 1.0.0-rc3 , KM to 0.18 (#79)
* 🔄 Rename ERNIEBotTextGeneration to ERNIEBotTextGenerator - Updated package versions for Microsoft.KernelMemory.Core, Microsoft.SemanticKernel.Abstractions, Microsoft.SemanticKernel.Core, Microsoft.SemanticKernel.Plugins.Core, and Microsoft.SemanticKernel.Plugins.Memory. - Fixed code in ERNIE-Bot-Kernel-Memory.Sample/Program.cs and SK-ERNIE-Bot.Sample/Controllers/ApiController.cs. - Renamed ERNIE-Bot.KernelMemory/ERNIEBotTextEmbeddingGeneration.cs to ERNIE-Bot.KernelMemory/ERNIEBotTextEmbeddingGenerator.cs. - Updated ERNIEBotTextEmbeddingGenerator class to implement ITextEmbeddingGenerator interface. - Added MaxTokens property and GenerateEmbeddingAsync method to ERNIEBotTextEmbeddingGenerator class. - Added CountTokens method to ERNIEBotTextEmbeddingGenerator class. - Updated summary formatting in ERNIEBotTextEmbeddingGenerator class. - Added two new model endpoints: XuanYuan_70B_Chat_4bit and ChatLaw. - Updated the bge-large-zh and bge-large-en embedding models to include a size of 512. - Refactored ERNIEBotKernelBuilderExtensions to simplify code and improve readability. 🔧 Update ModelEndpoints and ERNIEBotKernelBuilderExtensions - Added two new model endpoints: XuanYuan_70B_Chat_4bit and ChatLaw. - Updated the bge-large-zh and bge-large-en embedding models to include a size of 512. - Refactored ERNIEBotKernelBuilderExtensions to simplify code and improve readability. * bump version 0.12
- Loading branch information
Showing
10 changed files
with
72 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
...Memory/ERNIEBotTextEmbeddingGeneration.cs → ...lMemory/ERNIEBotTextEmbeddingGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
using ERNIE_Bot.SDK; | ||
using Microsoft.KernelMemory; | ||
using Microsoft.KernelMemory.AI; | ||
using Microsoft.SemanticKernel.AI.Embeddings; | ||
|
||
namespace ERNIE_Bot.KernelMemory | ||
{ | ||
/// <summary> | ||
/// Generating text embeddings using ERNIEBotClient. | ||
/// </summary> | ||
public class ERNIEBotTextEmbeddingGeneration : ITextEmbeddingGeneration | ||
public class ERNIEBotTextEmbeddingGenerator : ITextEmbeddingGenerator | ||
{ | ||
private readonly ERNIEBotClient _client; | ||
private readonly EmbeddingModelEndpoint _endpoint; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ERNIEBotTextEmbeddingGeneration"/> class. | ||
/// Initializes a new instance of the <see cref="ERNIEBotTextEmbeddingGenerator"/> class. | ||
/// </summary> | ||
/// <param name="client">The ERNIEBotClient instance to use for generating embeddings.</param> | ||
/// <param name="endpoint">The endpoint to use for the embedding model. Defaults to ModelEndpoints.Embedding_v1.</param> | ||
public ERNIEBotTextEmbeddingGeneration(ERNIEBotClient client, EmbeddingModelEndpoint? endpoint = null) | ||
public ERNIEBotTextEmbeddingGenerator(ERNIEBotClient client, EmbeddingModelEndpoint? endpoint = null) | ||
{ | ||
this._client = client; | ||
_endpoint = endpoint ?? ModelEndpoints.Embedding_v1; | ||
} | ||
|
||
private readonly Dictionary<string, string> _attributes = new(); | ||
public IReadOnlyDictionary<string, string> Attributes => _attributes; | ||
public int MaxTokens => _endpoint.MaxTokens; | ||
|
||
/// <inheritdoc/> | ||
public async Task<IList<ReadOnlyMemory<float>>> GenerateEmbeddingsAsync(IList<string> data, CancellationToken cancellationToken = default) | ||
public async Task<Embedding> GenerateEmbeddingAsync(string text, CancellationToken cancellationToken = default) | ||
{ | ||
var embeddings = await _client.EmbeddingsAsync(new SDK.Models.EmbeddingsRequest() | ||
{ | ||
Input = data.ToList() | ||
Input = [text] | ||
}, _endpoint, cancellationToken); | ||
|
||
return embeddings.Data.Select(d => new ReadOnlyMemory<float>(d.Embedding.Select(e => (float)e).ToArray())).ToList(); | ||
return new Embedding(embeddings.Data[0].Embedding.Select(e => (float)e).ToArray()); | ||
} | ||
|
||
public int CountTokens(string text) | ||
{ | ||
return Tokenizer.ApproxNumTokens(text); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters