{"id":941,"date":"2025-01-09T22:50:05","date_gmt":"2025-01-10T06:50:05","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=941"},"modified":"2025-01-09T22:50:05","modified_gmt":"2025-01-10T06:50:05","slug":"%e9%80%9a%e8%bf%87-net-aspire-%e4%bd%bf%e7%94%a8%e6%9c%ac%e5%9c%b0-ai-%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/%e9%80%9a%e8%bf%87-net-aspire-%e4%bd%bf%e7%94%a8%e6%9c%ac%e5%9c%b0-ai-%e6%a8%a1%e5%9e%8b\/","title":{"rendered":"\u901a\u8fc7 .NET Aspire \u4f7f\u7528\u672c\u5730 AI \u6a21\u578b"},"content":{"rendered":"<p style=\"text-align: center;\"><span style=\"font-family: arial, helvetica, sans-serif;\"><em>\u672c\u6587\u7ffb\u8bd1\u81ea<a class=\"read-more\" href=\"https:\/\/devblogs.microsoft.com\/dotnet\/author\/aapowell\" data-bi-area=\"body_author_top\" data-bi-id=\"post_page_body_author_top_name\" data-bi-name=\"Aaron Powell\">Aaron Powell<\/a>\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/local-ai-models-with-dotnet-aspire\/\">Using Local AI models with .NET Aspire<\/a><\/em><\/span><\/p>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u4f7f\u7528\u672c\u5730 AI \u6a21\u578b\u662f\u5728\u60a8\u81ea\u5df1\u7684\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5b9e\u9a8c\u7684\u4e00\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\uff0c\u5b83\u65e0\u9700\u5c06\u8d44\u6e90\u90e8\u7f72\u5230\u4e91\u4e2d\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528.NET Aspire \u548c\u00a0<a href=\"https:\/\/ollama.com\/\">Ollama<\/a> \u5728\u672c\u5730\u8fd0\u884c AI \u6a21\u578b\uff0c\u540c\u65f6\u4f7f\u7528 Microsoft.Extensions.AI \u62bd\u8c61\u4f7f\u5176\u5728\u90e8\u7f72\u65f6\u8fc7\u6e21\u5230\u4e91\u6258\u7ba1\u6a21\u578b\u3002<\/span><\/p>\n<h2><span style=\"font-family: arial, helvetica, sans-serif; font-size: 18pt;\"><strong>\u5728 .NET Aspire <\/strong><strong>\u4e2d\u8bbe\u7f6e Ollama<\/strong><\/span><\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u6211\u4eec\u9700\u8981\u67d0\u79cd\u65b9\u6cd5\u6765\u4ece .NET Aspire \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 Ollama\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528 .NET Aspire \u793e\u533a\u5de5\u5177\u5305\u4e2d\u7684 <a href=\"https:\/\/learn.microsoft.com\/dotnet\/aspire\/community-toolkit\/ollama\">Ollama \u6258\u7ba1\u96c6\u6210<\/a>\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7 Visual Studio \u5de5\u5177\u3001VS Code \u5de5\u5177\u6216 .NET CLI \u4ece NuGet \u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u5c06 Ollama \u6258\u7ba1\u96c6\u6210\u5b89\u88c5\u5230\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u9879\u76ee\u4e2d\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">dotnet add package CommunityToolkit.Aspire.Hosting.Ollama<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728 <code>Program.cs<\/code> \u6587\u4ef6\u4e2d\u5bf9\u5176\u8fdb\u884c\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u914d\u7f6e Ollama \u6258\u7ba1\u96c6\u6210\u7684\u793a\u4f8b\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">var ollama =\r\n        builder.AddOllama(\"ollama\")\r\n               .WithDataVolume()\r\n               .WithOpenWebUI();<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u8fd9\u91cc\uff0c\u6211\u4eec\u4f7f\u7528 <code>AddOllama<\/code> \u6269\u5c55\u65b9\u6cd5\u5c06\u5bb9\u5668\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u3002\u7531\u4e8e\u6211\u4eec\u9700\u8981\u4e0b\u8f7d\u4e00\u4e9b\u6a21\u578b\uff0c\u56e0\u6b64\u6211\u4eec\u5e0c\u671b\u5728\u5bb9\u5668\u91cd\u542f\u540e\u4fdd\u7559\u8be5\u6570\u636e\u91cf\uff08\u8fd9\u610f\u5473\u7740\u6211\u4eec\u4e0d\u5fc5\u5728\u6bcf\u6b21\u542f\u52a8\u5bb9\u5668\u65f6\u90fd\u8981\u91cd\u65b0\u83b7\u53d6\u597d\u51e0 GB \u7684\u6570\u636e\uff01\uff09\u3002\u6b64\u5916\uff0c\u6211\u4eec\u6709\u4e86\u4e00\u4e2a\u6d4b\u8bd5\u73af\u5883\uff0c\u6211\u4eec\u5c06\u6dfb\u52a0 <code>OpenWebUI<\/code> \u5bb9\u5668\uff0c\u6765\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e00\u4e2a\u5728\u5e94\u7528\u7a0b\u5e8f\u4e4b\u5916\u4e0e\u6a21\u578b\u8fdb\u884c\u4ea4\u4e92\u7684\u7f51\u9875\u754c\u9762\u3002<\/span><\/p>\n<h2><span style=\"font-family: arial, helvetica, sans-serif; font-size: 18pt;\"><strong>\u8fd0\u884c\u672c\u5730 AI <\/strong><strong>\u6a21\u578b<\/strong><\/span><\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5728\u4e0a\u4e00\u6b65\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u7684 <code>ollama<\/code> \u8d44\u6e90\u4ec5\u8fd0\u884c\u4e86 Ollama \u670d\u52a1\u5668\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5411\u5176\u6dfb\u52a0\u4e00\u4e9b\u6a21\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>AddModel<\/code> \u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u8ba9\u6211\u4eec\u4f7f\u7528 <a href=\"https:\/\/ollama.com\/library\/llama3.2\">Llama 3.2 \u6a21\u578b<\/a>\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">var chat = ollama.AddModel(\"chat\", \"llama3.2\");<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5982\u679c\u6211\u4eec\u60f3\u4f7f\u7528\u6a21\u578b\u7684\u67d0\u4e2a\u53d8\u4f53\u6216\u7279\u5b9a\u6807\u7b7e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728 <code>AddModel<\/code> \u65b9\u6cd5\u4e2d\u6307\u5b9a\uff0c\u4f8b\u5982 <code>ollama.AddModel(\"chat\", \"llama3.2:1b\")<\/code> \u7528\u4e8e\u6307\u5b9a Llama 3.2 \u6a21\u578b\u7684 1b \u6807\u7b7e\u3002\u6216\u8005\uff0c\u5982\u679c\u60a8\u6240\u9700\u7684\u6a21\u578b\u4e0d\u5728 Ollama \u5e93\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>AddHuggingFaceModel<\/code> \u65b9\u6cd5\u4ece Hugging Face \u6a21\u578b\u4e2d\u5fc3\u6dfb\u52a0\u6a21\u578b\u3002<\/span><\/p>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u73b0\u5728\u6211\u4eec\u6709\u4e86\u6a21\u578b\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3a\u8d44\u6e90\u6dfb\u52a0\u5230\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u4e2d\u7684\u5176\u4ed6\u670d\u52a1\u4e2d\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">builder.AddProject&lt;Projects.MyApi&gt;(\"api\")\r\n       .WithReference(chat);<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5f53\u6211\u4eec\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u9879\u76ee\u65f6\uff0cOllama \u670d\u52a1\u5668\u5c06\u542f\u52a8\u5e76\u4e0b\u8f7d\u6211\u4eec\u6307\u5b9a\u7684\u6a21\u578b\uff08\u786e\u4fdd\u5728\u4e0b\u8f7d\u5b8c\u6210\u4e4b\u524d\u4e0d\u8981\u505c\u6b62\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\uff09\uff0c\u7136\u540e\u6211\u4eec\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u8be5\u6a21\u578b\u3002\u5982\u679c\u60a8\u5e0c\u671b\u4f9d\u8d56\u8be5\u6a21\u578b\u7684\u8d44\u6e90\u7b49\u5230\u6a21\u578b\u4e0b\u8f7d\u5b8c\u6210\u540e\u518d\u4f7f\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528<code>WaitFor<\/code>\u65b9\u6cd5\u4e0e\u6a21\u578b\u5f15\u7528\u4e00\u8d77\u4f7f\u7528\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">builder.AddProject&lt;Projects.MyApi&gt;(\"api\")\r\n       .WithReference(chat)\r\n       .WaitFor(chat);<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif;\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models.png\"><img decoding=\"async\" class=\"alignnone wp-image-944\" src=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models-300x118.png\" alt=\"Image downloading models\" width=\"752\" height=\"296\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models-300x118.png 300w, https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models-1024x403.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models-768x302.png 768w, https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-content\/uploads\/sites\/75\/2025\/01\/downloading-models.png 1240w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/a><\/span><\/p>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5728\u4e0a\u9762\u7684\u63a7\u5236\u9762\u677f\u622a\u56fe\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u6a21\u578b\u6b63\u5728\u4e0b\u8f7d\u3002Ollama \u670d\u52a1\u5668\u6b63\u5728\u8fd0\u884c\u4f46\u5904\u4e8e\u975e\u6b63\u5e38\u72b6\u6001\uff0c\u56e0\u4e3a\u6a21\u578b\u5c1a\u672a\u4e0b\u8f7d\u5b8c\u6210\u3002<code>api<\/code>\u8d44\u6e90\u4e5f\u5c1a\u672a\u542f\u52a8\uff0c\u56e0\u4e3a\u5b83\u6b63\u5728\u7b49\u5f85\u6a21\u578b\u4e0b\u8f7d\u5b8c\u6210\u540e\u8fdb\u5165\u6b63\u5e38\u72b6\u6001\u3002<\/span><\/p>\n<h2><span style=\"font-family: arial, helvetica, sans-serif; font-size: 18pt;\"><strong>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u6a21\u578b<\/strong><\/span><\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u901a\u8fc7\u5c06 API \u9879\u76ee\u8bbe\u7f6e\u6210\u4f7f\u7528 <code>chat<\/code> \u6a21\u578b\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u4f7f\u7528 <a href=\"https:\/\/github.com\/awaescher\/OllamaSharp\">OllamaSharp<\/a> \u5e93\u8fde\u63a5\u5230 Ollama \u670d\u52a1\u5668\u5e76\u4e0e\u6a21\u578b\u8fdb\u884c\u4ea4\u4e92\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5c06\u4f7f\u7528 .NET Aspire\u793e\u533a\u5de5\u5177\u5305\u4e2d\u7684 <a href=\"https:\/\/www.nuget.org\/packages\/communityToolkit.Aspire.OllamaSharp\">OllamaSharp \u96c6\u6210<\/a>\uff1a\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">dotnet add package CommunityToolkit.Aspire.OllamaSharp<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u8be5\u96c6\u6210\u5141\u8bb8\u6211\u4eec\u5c06 OllamaSharp \u5ba2\u6237\u7aef\u6ce8\u518c\u4e3a\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-microsoft-extensions-ai-preview\/\">Microsoft.Extensions.AI \u5305<\/a>\u4e2d\u7684 <code>IChatClient<\/code> \u6216 <code>IEmbeddingsGenerator<\/code> \u670d\u52a1\uff0c\u8fd9\u79cd\u62bd\u8c61\u673a\u5236\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u5c06\u672c\u5730 Ollama \u670d\u52a1\u5668\u5207\u6362\u4e3a\u4e91\u6258\u7ba1\u9009\u9879\uff08\u4f8b\u5982 Azure OpenAI \u670d\u52a1\uff09\uff0c\u800c\u65e0\u9700\u66f4\u6539\u4f7f\u7528\u8be5\u5ba2\u6237\u7aef\u7684\u4ee3\u7801\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">builder.AddOllamaSharpChatClient(\"chat\");<\/code><\/span><\/pre>\n<p><span style=\"text-decoration: underline; font-family: arial, helvetica, sans-serif;\">\u6ce8\u610f\uff1a\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u5d4c\u5165\u6a21\u578b\u5e76\u60f3\u8981\u6ce8\u518c <code>IEmbeddingsGenerator<\/code> \u670d\u52a1\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>AddOllamaSharpEmbeddingsGenerator<\/code> \u65b9\u6cd5\u3002<\/span><\/p>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u4e3a\u4e86\u5145\u5206\u5229\u7528 Microsoft.Extensions.AI \u7ba1\u9053\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8be5\u670d\u52a1\u63d0\u4f9b\u7ed9 <code>ChatClientBuilder<\/code>\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">builder.AddKeyedOllamaSharpChatClient(\"chat\");\r\nbuilder.Services.AddChatClient(sp =&gt; sp.GetRequiredKeyedService(\"chat\"))\r\n                .UseFunctionInvocation()\r\n                .UseOpenTelemetry(configure: t =&gt; t.EnableSensitiveData = true)\r\n                .UseLogging();<\/code><\/span><\/pre>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06 <code>IChatClient<\/code> \u6ce8\u5165\u5230\u6211\u4eec\u7684\u8def\u7531\u5904\u7406\u7a0b\u5e8f\u4e2d\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">app.MapPost(\"\/chat\", async (IChatClient chatClient, string question) =&gt;\r\n{\r\n    var response = await chatClient.CompleteAsync(question);\r\n    return response.Message;\r\n});<\/code><\/span><\/pre>\n<h2><span style=\"font-family: arial, helvetica, sans-serif; font-size: 18pt;\"><strong>\u4e91\u6258\u7ba1\u6a21\u578b\u652f\u6301<\/strong><\/span><\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u867d\u7136 Ollama \u4f5c\u4e3a\u672c\u5730\u5f00\u53d1\u5de5\u5177\u975e\u5e38\u51fa\u8272\uff0c\u4f46\u5728\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u57fa\u4e8e\u4e91\u7aef\u7684 AI \u670d\u52a1\uff0c\u4f8b\u5982 Azure OpenAI \u670d\u52a1\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u9700\u8981\u66f4\u65b0 API \u9879\u76ee\uff0c\u4ee5\u4fbf\u5728\u4e91\u7aef\u8fd0\u884c\u65f6\u6ce8\u518c <code>IChatClient<\/code> \u670d\u52a1\u7684\u4e0d\u540c\u5b9e\u73b0\uff1a<\/span><\/p>\n<pre class=\"prettyprint language-default\"><span style=\"font-family: arial, helvetica, sans-serif;\"><code class=\"language-default\">if (builder.Environment.IsDevelopment())\r\n{\r\n    builder.AddKeyedOllamaSharpChatClient(\"chat\");\r\n}\r\nelse\r\n{\r\n    builder.AddKeyedAzureOpenAIClient(\"chat\");\r\n}\r\n\r\nbuilder.Services.AddChatClient(sp =&gt; sp.GetRequiredKeyedService(\"chat\"))\r\n                .UseFunctionInvocation()\r\n                .UseOpenTelemetry(configure: t =&gt; t.EnableSensitiveData = true)\r\n                .UseLogging();<\/code><\/span><\/pre>\n<h2><span style=\"font-family: arial, helvetica, sans-serif; font-size: 18pt;\"><strong>\u7ed3\u8bba<\/strong><\/span><\/h2>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u901a\u8fc7\u51e0\u884c\u4ee3\u7801\u6765\u4f7f\u7528 .NET Aspire \u8bbe\u7f6e Ollama \u670d\u52a1\u5668\uff0c\u6307\u5b9a\u6211\u4eec\u8981\u4f7f\u7528\u7684\u6a21\u578b\uff0c\u4e3a\u6211\u4eec\u4e0b\u8f7d\u8be5\u6a21\u578b\uff0c\u7136\u540e\u5c06\u5176\u96c6\u6210\u5230\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u6211\u4eec\u8fd8\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528 Microsoft.Extensions.AI \u7684\u62bd\u8c61\u529f\u80fd\u5728\u672c\u5730\u6a21\u578b\u548c\u4e91\u6258\u7ba1\u6a21\u578b\u4e4b\u95f4\u8f7b\u677e\u5207\u6362\u3002\u8fd9\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u5c06 AI \u6a21\u578b\u90e8\u7f72\u5230\u4e91\u7aef\u4e4b\u524d\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u5bf9\u5176\u8fdb\u884c\u8bd5\u9a8c\u3002<\/span><\/p>\n<p><span style=\"font-family: arial, helvetica, sans-serif; font-size: 12pt;\">\u67e5\u770b\u00a0<a href=\"https:\/\/github.com\/dotnet\/eshop\">eShop \u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f<\/a>\uff0c\u4e86\u89e3\u5982\u4f55\u5c06 Ollama \u4e0e .NET Aspire \u7ed3\u5408\u4f7f\u7528\u7684\u5b8c\u6574\u793a\u4f8b\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81eaAaron Powell\u7684Using Local AI models with .NET Aspire \u4f7f\u7528\u672c\u5730 AI \u6a21\u578b\u662f\u5728\u60a8\u81ea\u5df1\u7684\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5b9e\u9a8c\u7684\u4e00\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\uff0c\u5b83\u65e0\u9700\u5c06\u8d44\u6e90\u90e8\u7f72\u5230\u4e91\u4e2d\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528.NET Aspire \u548c\u00a0Ollama \u5728\u672c\u5730\u8fd0\u884c AI \u6a21\u578b\uff0c\u540c\u65f6\u4f7f\u7528 Microsoft.Extensions.AI \u62bd\u8c61\u4f7f\u5176\u5728\u90e8\u7f72\u65f6\u8fc7\u6e21\u5230\u4e91\u6258\u7ba1\u6a21\u578b\u3002 \u5728 .NET Aspire \u4e2d\u8bbe\u7f6e Ollama \u6211\u4eec\u9700\u8981\u67d0\u79cd\u65b9\u6cd5\u6765\u4ece .NET Aspire \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 Ollama\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528 .NET Aspire \u793e\u533a\u5de5\u5177\u5305\u4e2d\u7684 Ollama \u6258\u7ba1\u96c6\u6210\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7 Visual Studio \u5de5\u5177\u3001VS Code \u5de5\u5177\u6216 .NET CLI \u4ece NuGet \u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u5c06 Ollama \u6258\u7ba1\u96c6\u6210\u5b89\u88c5\u5230\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u9879\u76ee\u4e2d\uff1a dotnet add package CommunityToolkit.Aspire.Hosting.Ollama \u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728 Program.cs [&hellip;]<\/p>\n","protected":false},"author":177361,"featured_media":957,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[59,60,1,68],"tags":[2,57,72,73],"class_list":["post-941","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net","category-net-aspire","category-dotnet-ch","category-ai","tag-net","tag-ai","tag-meai","tag-ollama"],"acf":[],"blog_post_summary":"<p>\u672c\u6587\u7ffb\u8bd1\u81eaAaron Powell\u7684Using Local AI models with .NET Aspire \u4f7f\u7528\u672c\u5730 AI \u6a21\u578b\u662f\u5728\u60a8\u81ea\u5df1\u7684\u8ba1\u7b97\u673a\u4e0a\u8fdb\u884c\u5b9e\u9a8c\u7684\u4e00\u4e2a\u5f88\u597d\u7684\u65b9\u6cd5\uff0c\u5b83\u65e0\u9700\u5c06\u8d44\u6e90\u90e8\u7f72\u5230\u4e91\u4e2d\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528.NET Aspire \u548c\u00a0Ollama \u5728\u672c\u5730\u8fd0\u884c AI \u6a21\u578b\uff0c\u540c\u65f6\u4f7f\u7528 Microsoft.Extensions.AI \u62bd\u8c61\u4f7f\u5176\u5728\u90e8\u7f72\u65f6\u8fc7\u6e21\u5230\u4e91\u6258\u7ba1\u6a21\u578b\u3002 \u5728 .NET Aspire \u4e2d\u8bbe\u7f6e Ollama \u6211\u4eec\u9700\u8981\u67d0\u79cd\u65b9\u6cd5\u6765\u4ece .NET Aspire \u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 Ollama\uff0c\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u5c31\u662f\u4f7f\u7528 .NET Aspire \u793e\u533a\u5de5\u5177\u5305\u4e2d\u7684 Ollama \u6258\u7ba1\u96c6\u6210\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7 Visual Studio \u5de5\u5177\u3001VS Code \u5de5\u5177\u6216 .NET CLI \u4ece NuGet \u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u901a\u8fc7\u547d\u4ee4\u884c\u5c06 Ollama \u6258\u7ba1\u96c6\u6210\u5b89\u88c5\u5230\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u4e3b\u673a\u9879\u76ee\u4e2d\uff1a dotnet add package CommunityToolkit.Aspire.Hosting.Ollama \u5b89\u88c5 Ollama \u6258\u7ba1\u96c6\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u5728 Program.cs [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/177361"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=941"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/941\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/957"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}