{"id":3341,"date":"2024-09-12T10:58:27","date_gmt":"2024-09-12T17:58:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=3341"},"modified":"2025-04-19T06:56:26","modified_gmt":"2025-04-19T13:56:26","slug":"introducing-new-ollama-connector-for-local-models","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/introducing-new-ollama-connector-for-local-models\/","title":{"rendered":"Introducing new Ollama Connector for Local Models"},"content":{"rendered":"<h3><b><span data-contrast=\"none\">Introducing new Ollama Connector for Local Models<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559738&quot;:480,&quot;335559739&quot;:240,&quot;335559740&quot;:240}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"none\">As a long-awaited feature we are happy to bring a dedicated Ollama Connector. In the core implementation of this connector, we are also using the <\/span><a href=\"https:\/\/github.com\/awaescher\/OllamaSharp\"><span data-contrast=\"none\">Ollama Sharp<\/span><\/a><span data-contrast=\"none\"> library which allows you to manipulate some native Ollama APIs as well as using it with our connector for breaking glass scenarios (provide the Ollama Sharp client directly to the AddOllama(Service) extensions).<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:180,&quot;335559739&quot;:180,&quot;335559740&quot;:279}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">This connector is currently in alpha pre-release and supports <\/span><b><span data-contrast=\"none\">Chat Completion<\/span><\/b><span data-contrast=\"none\">, <\/span><b><span data-contrast=\"none\">Text Embeddings<\/span><\/b><span data-contrast=\"none\"> and <\/span><b><span data-contrast=\"none\">Text Generation<\/span><\/b><span data-contrast=\"none\"> capable models.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:180,&quot;335559739&quot;:180,&quot;335559740&quot;:279}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">The biggest benefit of having a dedicated connector for Ollama is that it allows us to support Semantic Kernel features that targeted for Ollama deployed models.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559738&quot;:180,&quot;335559739&quot;:180,&quot;335559740&quot;:279}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"1\"><b><span data-contrast=\"none\">What is Ollama?<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:480,&quot;335559739&quot;:0,&quot;335559740&quot;:279}\">\u00a0<\/span><\/h3>\n<h3 aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2024\/09\/Picture1.png\"><img decoding=\"async\" class=\"size-full wp-image-3343 alignleft\" src=\"https:\/\/devblogs.microsoft.com\/semantic-kernel\/wp-content\/uploads\/sites\/78\/2024\/09\/Picture1.png\" alt=\"Image Picture1\" width=\"300\" height=\"157\" \/><\/a><\/h3>\n<p>Ollama is an open-source MIT license platform that facilitates the local operation of AI models directly on personal or corporate hardware. It supports a variety of models from different sources, such as Phi-3, Llama-3, Mistral, and many others, allowing users to run these models on their local machines without the need for continuous internet connectivity. This local deployment secures sensitive data and provides complete control over the AI models and their operation.<\/p>\n<p>The platform is quite simple to use and setup and has been largely adopted by the AI community for edge scenarios and local AI inference tasks.<\/p>\n<h3><strong>Get Started<\/strong><\/h3>\n<ol>\n<li>Deploy a model like <a href=\"https:\/\/ollama.com\/library\/phi3\">Phi-3<\/a>. For more details, see the <a href=\"https:\/\/ollama.com\/library\">Ollama AI Models library<\/a>.<\/li>\n<li>Install the <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.SemanticKernel.Connectors.Ollama\">Connectors.Ollama<\/a> pre-release package in your existing project from NuGet.<\/li>\n<\/ol>\n<p>Add the following code to your application to start making requests to your local AI model. Make sure to provide the correct model Id (phi3, llama3.1, etc.) and the endpoint if different from the default \u201chttp:\/\/localhost:11434\u201d.<\/p>\n<pre><code class=\"code-line language-csharp\" dir=\"auto\" data-line=\"0\"><span class=\"hljs-keyword\">using<\/span> <span class=\"hljs-keyword\">var<\/span> ollamaClient = <span class=\"hljs-keyword\">new<\/span> OllamaApiClient(\r\n            uriString: \"http:\/\/localhost:11434\",\r\n            defaultModel: \"phi3\");\r\n\r\n<span class=\"hljs-keyword\">var<\/span> chatService = ollamaClient.AsChatCompletionService();\r\n\r\n<span class=\"hljs-keyword\">var<\/span> chatHistory = <span class=\"hljs-keyword\">new<\/span> ChatHistory(<span class=\"hljs-string\">\"You are a helpful assistant that knows about AI.\"<\/span>); \r\n\r\nchatHistory.AddUserMessage(<span class=\"hljs-string\">\"Hi, I'm looking for book suggestions\"<\/span>);\r\n\r\n<span class=\"hljs-keyword\">var<\/span> reply = <span class=\"hljs-keyword\">await<\/span> chatService.GetChatMessageContentAsync(chatHistory);<\/code><\/pre>\n<p>For more scenarios, see the samples below:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/ChatCompletion\/Ollama_ChatCompletion.cs\">Chat Completion<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/ChatCompletion\/Ollama_ChatCompletionStreaming.cs\">Streaming Chat Completion<\/a>.<\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/TextGeneration\/Ollama_TextGeneration.cs\">Text Generation<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/TextGeneration\/Ollama_TextGenerationStreaming.cs\">Streaming Text Generation<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/blob\/main\/dotnet\/samples\/Concepts\/Memory\/Ollama_EmbeddingGeneration.cs\" target=\"_blank\" rel=\"noopener\">Text Embeddings<\/a><\/li>\n<\/ul>\n<h3><strong>Conclusion<\/strong><\/h3>\n<p>We&#8217;re excited to see what you build! Try out the new Ollama Connector and give us your feedback. Please reach out if you have any questions or feedback through our\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\/categories\/general\" target=\"_blank\" rel=\"noopener\">Semantic Kernel GitHub Discussion Channel<\/a>. We look forward to hearing from you!\u00a0We would also love your support, if you\u2019ve enjoyed using Semantic Kernel, give us a star on\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introducing new Ollama Connector for Local Models\u00a0 As a long-awaited feature we are happy to bring a dedicated Ollama Connector. In the core implementation of this connector, we are also using the Ollama Sharp library which allows you to manipulate some native Ollama APIs as well as using it with our connector for breaking glass [&hellip;]<\/p>\n","protected":false},"author":149071,"featured_media":2364,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[47],"tags":[48,63,9],"class_list":["post-3341","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","tag-ai","tag-microsoft-semantic-kernel","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>Introducing new Ollama Connector for Local Models\u00a0 As a long-awaited feature we are happy to bring a dedicated Ollama Connector. In the core implementation of this connector, we are also using the Ollama Sharp library which allows you to manipulate some native Ollama APIs as well as using it with our connector for breaking glass [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/3341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/149071"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=3341"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/3341\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2364"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=3341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=3341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=3341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}