Skip to content

Commit

Permalink
Update M.E.AI to 9.0.1-preview.1.24570.5 (#629)
Browse files Browse the repository at this point in the history
* Update M.E.AI to 9.0.1-preview.1.24570.5

* Apply suggestions from code review

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>

---------

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
  • Loading branch information
stephentoub and eerhardt authored Nov 22, 2024
1 parent 4065e1e commit 10c3b4b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
<!-- Xabaril packages -->
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
<!-- AI -->
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.0.0-preview.9.24556.5" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.0-preview.9.24556.5" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24556.5" />
<PackageVersion Include="Microsoft.Extensions.AI.Ollama" Version="9.0.0-preview.9.24556.5" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.0.1-preview.1.24570.5" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.0.1-preview.1.24570.5" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.1-preview.1.24570.5" />
<PackageVersion Include="Microsoft.Extensions.AI.Ollama" Version="9.0.1-preview.1.24570.5" />
<!-- Open Telemetry -->
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
Expand Down
10 changes: 4 additions & 6 deletions src/Catalog.API/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ public static void AddApplicationServices(this IHostApplicationBuilder builder)

if (builder.Configuration["AI:Ollama:Endpoint"] is string ollamaEndpoint && !string.IsNullOrWhiteSpace(ollamaEndpoint))
{
builder.Services.AddEmbeddingGenerator<string, Embedding<float>>(b => b
builder.Services.AddEmbeddingGenerator(new OllamaEmbeddingGenerator(ollamaEndpoint, builder.Configuration["AI:Ollama:EmbeddingModel"]))
.UseOpenTelemetry()
.UseLogging()
.Use(new OllamaEmbeddingGenerator(
new Uri(ollamaEndpoint),
builder.Configuration["AI:Ollama:EmbeddingModel"])));
.Build();
}
else if (!string.IsNullOrWhiteSpace(builder.Configuration.GetConnectionString("openai")))
{
builder.AddOpenAIClientFromConfiguration("openai");
builder.Services.AddEmbeddingGenerator<string, Embedding<float>>(b => b
builder.Services.AddEmbeddingGenerator(sp => sp.GetRequiredService<OpenAIClient>().AsEmbeddingGenerator(builder.Configuration["AI:OpenAI:EmbeddingModel"]!))
.UseOpenTelemetry()
.UseLogging()
.Use(b.Services.GetRequiredService<OpenAIClient>().AsEmbeddingGenerator(builder.Configuration["AI:OpenAI:EmbeddingModel"]!)));
.Build();
}

builder.Services.AddScoped<ICatalogAI, CatalogAI>();
Expand Down
2 changes: 1 addition & 1 deletion src/Catalog.API/Services/CatalogAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async ValueTask<Vector> GetEmbeddingAsync(string text)
{
long timestamp = Stopwatch.GetTimestamp();

var embedding = (await _embeddingGenerator.GenerateAsync(new[] { text }))[0].Vector;
var embedding = await _embeddingGenerator.GenerateEmbeddingVectorAsync(text);
embedding = embedding[0..EmbeddingDimensions];

if (_logger.IsEnabled(LogLevel.Trace))
Expand Down
10 changes: 4 additions & 6 deletions src/WebApp/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,23 @@ private static void AddAIServices(this IHostApplicationBuilder builder)
string? ollamaEndpoint = builder.Configuration["AI:Ollama:Endpoint"];
if (!string.IsNullOrWhiteSpace(ollamaEndpoint))
{
builder.Services.AddChatClient(b => b
builder.Services.AddChatClient(new OllamaChatClient(ollamaEndpoint, builder.Configuration["AI:Ollama:ChatModel"] ?? "llama3.1"))
.UseFunctionInvocation()
.UseOpenTelemetry(configure: t => t.EnableSensitiveData = true)
.UseLogging()
.Use(new OllamaChatClient(
new Uri(ollamaEndpoint),
builder.Configuration["AI:Ollama:ChatModel"] ?? "llama3.1")));
.Build();
}
else
{
var chatModel = builder.Configuration.GetSection("AI").Get<AIOptions>()?.OpenAI?.ChatModel;
if (!string.IsNullOrWhiteSpace(builder.Configuration.GetConnectionString("openai")) && !string.IsNullOrWhiteSpace(chatModel))
{
builder.AddOpenAIClientFromConfiguration("openai");
builder.Services.AddChatClient(b => b
builder.Services.AddChatClient(sp => sp.GetRequiredService<OpenAIClient>().AsChatClient(chatModel ?? "gpt-4o-mini"))
.UseFunctionInvocation()
.UseOpenTelemetry(configure: t => t.EnableSensitiveData = true)
.UseLogging()
.Use(b.Services.GetRequiredService<OpenAIClient>().AsChatClient(chatModel ?? "gpt-4o-mini")));
.Build();
}
}
}
Expand Down

0 comments on commit 10c3b4b

Please sign in to comment.