-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Fix OpenApiDocumentParser fail when X-API-version is provide in…
… the content key (#9959) ### Motivation and Context 1. Closes #9952 2. Also includes an OpenAI text embedding sample ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: SergeyMenshykh <[email protected]>
- Loading branch information
1 parent
e66883e
commit e883843
Showing
9 changed files
with
178 additions
and
6 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
dotnet/samples/Concepts/Memory/OpenAI_EmbeddingGeneration.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Embeddings; | ||
using xRetry; | ||
|
||
#pragma warning disable format // Format item can be simplified | ||
#pragma warning disable CA1861 // Avoid constant arrays as arguments | ||
|
||
namespace Memory; | ||
|
||
// The following example shows how to use Semantic Kernel with OpenAI. | ||
public class OpenAI_EmbeddingGeneration(ITestOutputHelper output) : BaseTest(output) | ||
{ | ||
[RetryFact(typeof(HttpOperationException))] | ||
public async Task RunEmbeddingAsync() | ||
{ | ||
Assert.NotNull(TestConfiguration.OpenAI.EmbeddingModelId); | ||
Assert.NotNull(TestConfiguration.OpenAI.ApiKey); | ||
|
||
IKernelBuilder kernelBuilder = Kernel.CreateBuilder(); | ||
kernelBuilder.AddOpenAITextEmbeddingGeneration( | ||
modelId: TestConfiguration.OpenAI.EmbeddingModelId!, | ||
apiKey: TestConfiguration.OpenAI.ApiKey!); | ||
Kernel kernel = kernelBuilder.Build(); | ||
|
||
var embeddingGenerator = kernel.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Generate embeddings for the specified text. | ||
var embeddings = await embeddingGenerator.GenerateEmbeddingsAsync(["Semantic Kernel is a lightweight, open-source development kit that lets you easily build AI agents and integrate the latest AI models into your C#, Python, or Java codebase."]); | ||
|
||
Console.WriteLine($"Generated {embeddings.Count} embeddings for the provided 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
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