From d2707388a5ee4168c59f92ce33794a933d8296f1 Mon Sep 17 00:00:00 2001
From: Dimo Dimov <961014+dimodi@users.noreply.github.com>
Date: Wed, 21 May 2025 17:08:56 +0300
Subject: [PATCH] Update to official MS AI package
---
.../AIPromptIntegration.csproj | 10 ++++----
.../AIPromptIntegration/Program.cs | 23 +++++++++++++++----
.../AIPromptIntegration/readme.md | 15 ++++++++----
3 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/AIPromptIntegration.csproj b/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/AIPromptIntegration.csproj
index 9ebef997..ba07dc56 100644
--- a/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/AIPromptIntegration.csproj
+++ b/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/AIPromptIntegration.csproj
@@ -11,11 +11,11 @@
-
-
-
-
-
+
+
+
+
+
diff --git a/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/Program.cs b/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/Program.cs
index 52c45cca..b33a177a 100644
--- a/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/Program.cs
+++ b/common/microsoft-extensions-ai-integration/AIPromptIntegration/AIPromptIntegration/Program.cs
@@ -28,22 +28,35 @@
var endpoint = builder.Configuration["Endpoint"] ?? throw new InvalidOperationException("Missing configuration: Endpoint. See the README for details.");
// 🔑 The API Key for your provider
var apikey = builder.Configuration["ApiKey"] ?? throw new InvalidOperationException("Missing configuration: ApiKey. See the README for details.");
-// 🧠 The model name or azure deployment name
+// 🧠 The model name or Azure deployment name
var model = "YOUR_MODEL_NAME";
-// Replace the innerClient below with your preferred model provider
-var innerClient = new OpenAIClient(
+// Use your preferred AI client below
+
+// If using OpenAIClient
+builder.Services.AddSingleton(new OpenAIClient(
new ApiKeyCredential(apikey),
new OpenAIClientOptions()
{
Endpoint = new Uri(endpoint)
}
- ).AsChatClient(model);
+));
-builder.Services.AddChatClient(innerClient) // 🤖 Add the configured chat client
+builder.Services.AddChatClient(services => services.GetRequiredService().GetChatClient(model).AsIChatClient()) // 🤖 Add the configured chat client
.UseFunctionInvocation() // 🛠️ Include tool calling
.UseLogging(); //🐞 Include Logging
+// OR
+
+// If using AzureOpenAIClient
+
+// builder.Services.AddSingleton(new AzureOpenAIClient(
+// new Uri(endpoint),
+// new AzureKeyCredential(apikey)
+// ));
+
+// builder.Services.AddChatClient(services => services.GetRequiredService().GetChatClient(model).AsIChatClient());
+
var app = builder.Build();
// Configure the HTTP request pipeline.
diff --git a/common/microsoft-extensions-ai-integration/AIPromptIntegration/readme.md b/common/microsoft-extensions-ai-integration/AIPromptIntegration/readme.md
index 7b03c51d..d805c316 100644
--- a/common/microsoft-extensions-ai-integration/AIPromptIntegration/readme.md
+++ b/common/microsoft-extensions-ai-integration/AIPromptIntegration/readme.md
@@ -35,7 +35,7 @@ To run the project successfully, you need to provide your endpoint and credentia
var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
- ).AsChatClient(model);
+ );
```
**Azure OpenAI Client registration**
@@ -45,15 +45,20 @@ var innerClient = new Azure.AI.Inference.ChatCompletionsClient(
var innerClient = new AzureOpenAIClient(
new Uri(endpoint),
new AzureKeyCredential(apikey)
- ).AsChatClient(model);
+ );
```
**OpenAI Client registration**
>Program.cs
```csharp
-var innerClient = new OpenAIClient(apikey)
- .AsChatClient(model);
+var innerClient = new OpenAIClient(
+ new ApiKeyCredential(apikey),
+ new OpenAIClientOptions()
+ {
+ Endpoint = new Uri(endpoint)
+ }
+);
```
**GitHub Models Client registration**
@@ -66,7 +71,7 @@ var innerClient = new OpenAIClient(
{
Endpoint = new Uri(endpoint)
}
- ).AsChatClient(model);
+ );
```
**Ollama Client registration**