{"id":4044,"date":"2025-01-29T13:15:24","date_gmt":"2025-01-29T21:15:24","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=4044"},"modified":"2025-02-19T07:57:13","modified_gmt":"2025-02-19T15:57:13","slug":"using-deepseek-models-in-semantic-kernel","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/using-deepseek-models-in-semantic-kernel\/","title":{"rendered":"Using DeepSeek models in Microsoft Semantic Kernel"},"content":{"rendered":"<p><a href=\"https:\/\/www.deepseek.com\/\">DeepSeek<\/a> recently awed the AI community by open sourcing two new state-of-the-art models, the DeepSeek-V3 and a reasoning model, the DeepSeek-R1, that not only claim to be op-par with the most capable models from OpenAI but are also extremely cost-effective. We&#8217;d like to highlight the recent announcement from the Azure AI Foundry team highlighting <a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/deepseek-r1-is-now-available-on-azure-ai-foundry-and-github\/?msockid=36fead99b61a6c2133cbbf4fb7a06d94\">DeepSeek R1 is now available on Azure AI Foundry and GitHub<\/a>. DeepSeek is also available for use in Semantic Kernel, Azure AI Foundry and can be called via our <span data-teams=\"true\">inferencing <\/span>connector as well.<\/p>\n<ul>\n<li>To learn more about the performance and technical details of DeepSeek-V3, please refer to this paper: <a href=\"https:\/\/arxiv.org\/pdf\/2412.19437\">DeepSeek-V3 Technical Report<\/a><\/li>\n<li>To learn more about the performance and technical details of DeepSeek-R1, please refer to this paper: <a href=\"https:\/\/arxiv.org\/pdf\/2501.12948\">DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning<\/a><\/li>\n<li>To view the inference cost of the DeepSeek models, please visit: <a href=\"https:\/\/api-docs.deepseek.com\/quick_start\/pricing\">Models &amp; Pricing | DeepSeek API Docs<\/a><\/li>\n<\/ul>\n<p>Semantic Kernel is thrilled to see such exciting development in the opensource AI community, and we think most developers are too. Thus, in this blog post, we will share with you how to use the DeepSeek service in Semantic Kernel so that you can experiment with these new models in your new or existing workflows.<\/p>\n<h4>Prerequisites<\/h4>\n<ol>\n<li>Create a DeepSeek account <a href=\"https:\/\/platform.deepseek.com\/\">here<\/a>.<\/li>\n<li>Top up the account <a href=\"https:\/\/platform.deepseek.com\/top_up\">here<\/a>.<\/li>\n<li>Create an API key <a href=\"https:\/\/platform.deepseek.com\/api_key\">here<\/a> (Copy the API key somewhere for later use as you can only see it once).<\/li>\n<\/ol>\n<p>DeepSeek API is compatible with the OpenAI chat completion API format, so we are going to use the OpenAI connector.<\/p>\n<h4>In .Net<\/h4>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">var DEEPSEEK_API_KEY = \"...\";\r\n\r\nOpenAIChatCompletionService chatCompletionService = new(\r\n    \"deepseek-chat\",    \/\/ or \"deepseek-reasoner\"\r\n    new Uri(\"https:\/\/api.deepseek.com\"),\r\n    DEEPSEEK_API_KEY,\r\n);\r\n\r\nvar chatHistory = new ChatHistory(); \r\nchatHistory.AddUserMessage(\"Hello, how are you?\");\r\n\r\nvar reply = await chatCompletionService.GetChatMessageContentAsync(chatHistory);\r\nConsole.WriteLine(reply);<\/code><\/pre>\n<h4>In Python<\/h4>\n<pre class=\"prettyprint language-py\"><code class=\"language-py\">import asyncio\r\n\r\nfrom openai import AsyncOpenAI\r\n\r\nfrom semantic_kernel.contents import ChatHistory\r\nfrom semantic_kernel.connectors.ai.open_ai import (\r\n    OpenAIChatCompletion,\r\n    OpenAIChatPromptExecutionSettings,\r\n)\r\n\r\nDEEPSEEK_API_KEY = \"...\"\r\n\r\nasync def main():\r\n    chat_service = OpenAIChatCompletion(\r\n        ai_model_id=\"deepseek-chat\",    # or \"deepseek-reasoner\"\r\n        async_client=AsyncOpenAI(\r\n            api_key=DEEPSEEK_API_KEY,\r\n            base_url=\"https:\/\/api.deepseek.com\",\r\n        ),\r\n    )\r\n\r\n    chat_history = ChatHistory()\r\n    chat_history.add_user_message(\"Hello, how are you?\")\r\n\r\n    response = await chat_service.get_chat_message_content(chat_history, OpenAIChatPromptExecutionSettings())\r\n    print(response)\r\n\r\nif __name__ == \"__main__\":\r\n    asyncio.run(main())<\/code><\/pre>\n<p>Just like that, whether you are new to or you have built solutions with Semantic Kernel, you will be able to experiment with the DeepSeek models with only a few lines of code.<\/p>\n<p>We have also created a sample within Semantic Kernel using DeepSeek here: <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/pull\/10306\">Add Deepseek service to concept samples<\/a>.<\/p>\n<article id=\"post-3755\" class=\"middle-column pe-xl-198\" data-clarity-region=\"article\">\n<div class=\"entry-content sharepostcontent \" data-bi-area=\"body_article\" data-bi-id=\"post_page_body_article\">\n<p><em>The Semantic Kernel team is dedicated to empowering developers by providing access to the latest advancements in the industry. We encourage you to leverage your creativity and build remarkable solutions with SK! 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>.<\/em><\/p>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>DeepSeek recently awed the AI community by open sourcing two new state-of-the-art models, the DeepSeek-V3 and a reasoning model, the DeepSeek-R1, that not only claim to be op-par with the most capable models from OpenAI but are also extremely cost-effective. We&#8217;d like to highlight the recent announcement from the Azure AI Foundry team highlighting DeepSeek [&hellip;]<\/p>\n","protected":false},"author":165150,"featured_media":2365,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[79,48,114,63,53,9],"class_list":["post-4044","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-semantic-kernel","tag-net","tag-ai","tag-deepseek","tag-microsoft-semantic-kernel","tag-python","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>DeepSeek recently awed the AI community by open sourcing two new state-of-the-art models, the DeepSeek-V3 and a reasoning model, the DeepSeek-R1, that not only claim to be op-par with the most capable models from OpenAI but are also extremely cost-effective. We&#8217;d like to highlight the recent announcement from the Azure AI Foundry team highlighting DeepSeek [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4044","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\/165150"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=4044"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4044\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2365"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=4044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=4044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=4044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}