Skip to content

Commit c5dbcf1

Browse files
committed
Use GitHub Models in code
The documentation suggests that the code is using GitHub Models, but the current implementation appears to rely on Ollama being present. This change updates the code to use GitHub Models
1 parent b8d0f6a commit c5dbcf1

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

03-CoreGenerativeAITechniques/02-retrieval-augmented-generation.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ We'll use the Microsoft.Extension.AI along with the [Microsoft.Extensions.Vector
8484
3. Our next task then is to convert our knowledge store (the `movieData` object) into embeddings and then store them into the in-memory vector store. When we create the embeddings we'll use a different model - an embeddings model instead of a language model.
8585

8686
```csharp
87-
var endpoint = new Uri("https://models.inference.ai.azure.com");
88-
var modelId = "text-embedding-3-small";
8987
// get embeddings generator and generate embeddings for movies
90-
IEmbeddingGenerator<string, Embedding<float>> generator =
91-
new OllamaEmbeddingGenerator(new Uri("http://localhost:11434/"), "all-minilm");
88+
var githubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? throw new InvalidOperationException("GITHUB_TOKEN environment variable is not set.");
89+
var endpoint = new Uri("https://models.inference.ai.azure.com");
90+
var modelId = "text-embedding-3-small";
91+
92+
var embeddingsClient = new EmbeddingsClient(endpoint, new AzureKeyCredential(githubToken));
93+
IEmbeddingGenerator<string, Embedding<float>> generator = embeddingsClient.AsIEmbeddingGenerator(modelId);
94+
9295
foreach (var movie in movieData)
9396
{
9497
movie.Vector = await generator.GenerateVectorAsync(movie.Description);

03-CoreGenerativeAITechniques/src/RAGSimple-02MEAIVectorsMemory/Program.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.Extensions.AI;
1+
using Azure;
2+
using Azure.AI.Inference;
3+
using Microsoft.Extensions.AI;
24
using Microsoft.SemanticKernel.Connectors.InMemory;
35

46
var vectorStore = new InMemoryVectorStore();
@@ -9,8 +11,12 @@
911
var movieData = MovieFactory<int>.GetMovieVectorList();
1012

1113
// get embeddings generator and generate embeddings for movies
12-
IEmbeddingGenerator<string, Embedding<float>> generator =
13-
new OllamaEmbeddingGenerator(new Uri("http://localhost:11434/"), "all-minilm");
14+
var githubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN") ?? throw new InvalidOperationException("GITHUB_TOKEN environment variable is not set.");
15+
var endpoint = new Uri("https://models.inference.ai.azure.com");
16+
var modelId = "text-embedding-3-small";
17+
18+
var embeddingsClient = new EmbeddingsClient(endpoint, new AzureKeyCredential(githubToken));
19+
IEmbeddingGenerator<string, Embedding<float>> generator = embeddingsClient.AsIEmbeddingGenerator(modelId);
1420
foreach (var movie in movieData)
1521
{
1622
movie.Vector = await generator.GenerateVectorAsync(movie.Description);

03-CoreGenerativeAITechniques/src/RAGSimple-02MEAIVectorsMemory/RAGSimple-02MEAIVectorsMemory.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
</PropertyGroup>
99
<ItemGroup>
1010
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.5.0-preview.1.25265.7" />
11+
<PackageReference Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25265.7" />
1112
<PackageReference Include="Microsoft.Extensions.VectorData.Abstractions" Version="9.5.0" />
1213
<PackageReference Include="Microsoft.SemanticKernel.Connectors.InMemory" Version="1.54.0-preview" />
1314
</ItemGroup>

0 commit comments

Comments
 (0)