|
1 |
| -using AIPromptIntegration.Components; |
| 1 | +using AIPromptIntegration.Components; |
2 | 2 | using Microsoft.Extensions.AI;
|
3 |
| -using Azure; |
4 |
| -using OpenAI; |
| 3 | + |
| 4 | +// Optional model provider implementations: |
| 5 | +// Azure models |
| 6 | +using Azure; |
5 | 7 | using Azure.AI.OpenAI;
|
| 8 | +// OpenAI models |
| 9 | +using OpenAI; |
| 10 | +// GitHub models |
| 11 | +using System.ClientModel; |
6 | 12 |
|
7 | 13 | var builder = WebApplication.CreateBuilder(args);
|
8 | 14 |
|
9 | 15 | // Add services to the container.
|
10 | 16 | builder.Services.AddRazorComponents()
|
11 |
| - .AddInteractiveServerComponents(); |
| 17 | + .AddInteractiveServerComponents(); |
12 | 18 |
|
13 | 19 | builder.Services.AddTelerikBlazor();
|
14 | 20 |
|
15 |
| -#region Azure AI Inference Client registration |
16 |
| - |
17 |
| -//builder.Services.AddChatClient( |
18 |
| -// new Azure.AI.Inference.ChatCompletionsClient( |
19 |
| -// new Uri("https://models.inference.ai.azure.com"), |
20 |
| -// new AzureKeyCredential("YOUR_AZURE_OPENAI_CREDENTIAL") |
21 |
| -// ).AsChatClient("Phi-3.5-MoE-instruct")); |
22 |
| - |
23 |
| -#endregion Azure AI Inference Client registration |
24 |
| - |
25 |
| -#region OpenAI Client registration |
26 |
| - |
27 |
| -//builder.Services.AddSingleton(new OpenAIClient("YOUR_API_KEY")); |
28 |
| - |
29 |
| -//builder.Services.AddChatClient(services => services.GetRequiredService<OpenAIClient>().AsChatClient("YOUR_MODEL_NAME")); |
30 |
| - |
31 |
| -#endregion OpenAI Client registration |
32 |
| - |
33 |
| -#region Azure OpenAI Client registration |
34 |
| - |
35 |
| -//builder.Services.AddSingleton(new AzureOpenAIClient( |
36 |
| -// new Uri("YOUR_AZURE_OPENAI_ENDPOINT"), |
37 |
| -// new AzureKeyCredential("YOUR_AZURE_OPENAI_CREDENTIAL"))); |
38 |
| - |
39 |
| -//builder.Services.AddChatClient(services => services.GetRequiredService<AzureOpenAIClient>().AsChatClient("gpt-4o-mini")); |
40 |
| - |
41 |
| -#endregion Azure OpenAI Client registration |
42 |
| - |
43 |
| -#region Ollama Chat Client registration |
44 |
| - |
45 |
| -//builder.Services.AddChatClient(new OllamaChatClient(new Uri("THE_URI_OF_YOUR_CLIENT"), "llama3.1")); |
46 |
| - |
47 |
| -#endregion Ollama Chat Client registration |
| 21 | +// You will need to set the endpoint and key to your own values |
| 22 | +// You can do this using Visual Studio's "Manage User Secrets" UI, or on the command line 💻: |
| 23 | +// cd this-project-directory |
| 24 | +// dotnet user-secrets set Endpoint https://YOUR-DEPLOYMENT-NAME.openai.azure.com |
| 25 | +// dotnet user-secrets set ApiKey super-secret-api-key |
| 26 | + |
| 27 | +// 🌐 The Uri of your provider |
| 28 | +var endpoint = builder.Configuration["Endpoint"] ?? throw new InvalidOperationException("Missing configuration: AzureOpenAi:Endpoint. See the README for details."); |
| 29 | +// 🔑 The API Key for your provider |
| 30 | +var apikey = builder.Configuration["ApiKey"] ?? throw new InvalidOperationException("Missing configuration: AzureOpenAi:ApiKey. See the README for details."); |
| 31 | +// 🧠 The model name or azure deployment name |
| 32 | +var model = "YOUR_MODEL_NAME"; |
| 33 | + |
| 34 | +// Replace the innerClient below with your preferred model provider |
| 35 | +var innerClient = new OpenAIClient( |
| 36 | + new ApiKeyCredential(apikey), |
| 37 | + new OpenAIClientOptions() |
| 38 | + { |
| 39 | + Endpoint = new Uri(endpoint) |
| 40 | + } |
| 41 | + ).AsChatClient(model); |
| 42 | + |
| 43 | +builder.Services.AddChatClient(innerClient) // 🤖 Add the configured chat client |
| 44 | + .UseFunctionInvocation() // 🛠️ Include tool calling |
| 45 | + .UseLogging(); //🐞 Include Logging |
48 | 46 |
|
49 | 47 | var app = builder.Build();
|
50 | 48 |
|
51 | 49 | // Configure the HTTP request pipeline.
|
52 | 50 | if (!app.Environment.IsDevelopment())
|
53 | 51 | {
|
54 |
| - app.UseExceptionHandler("/Error", createScopeForErrors: true); |
55 |
| - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
56 |
| - app.UseHsts(); |
| 52 | + app.UseExceptionHandler("/Error", createScopeForErrors: true); |
| 53 | + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. |
| 54 | + app.UseHsts(); |
57 | 55 | }
|
58 | 56 |
|
59 | 57 | app.UseHttpsRedirection();
|
|
62 | 60 | app.UseAntiforgery();
|
63 | 61 |
|
64 | 62 | app.MapRazorComponents<App>()
|
65 |
| - .AddInteractiveServerRenderMode(); |
| 63 | + .AddInteractiveServerRenderMode(); |
66 | 64 |
|
67 | 65 | app.Run();
|
0 commit comments