c# - Unable to use SemanticKernel plugins with DeepSeek-R1 on Azure AI Foundry - Stack Overflow

I am trying to use Semantic Kernel plugins through OpenAI connector with DeepSeek-R1 deployed on Azure

I am trying to use Semantic Kernel plugins through OpenAI connector with DeepSeek-R1 deployed on Azure Foundry. I can connect to the LLM and get responses.

But I can't leverage Semantic Kernel plugins. The plugins seem to be ignored. For example, in the code below, I have declared a DatePlugin with its GetCurrentDate function, but asking:

What is the current date ?

returns

Hi there! I suggest getting online to get real-time information. If you have any other questions, please don't hesitate to let me know!

I have tried with several other types of functions, with no more luck. Do you know how to proceed ? Is it even possible to achieve this ?

namespace DeepSeekR1Test
{
    using System.ComponentModel;

    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    using Microsoft.SemanticKernel;
    using Microsoft.SemanticKernel.Agents;
    using Microsoft.SemanticKernel.ChatCompletion;
    using Microsoft.SemanticKernel.Connectors.OpenAI;

    internal class Program
    {
        static async Task Main(string[] args)
        {
            var builder = Kernel.CreateBuilder();

#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
            builder.AddOpenAIChatCompletion(
                modelId: "DeepSeek-R1",
                new Uri(MY_AZURE_OPENAI_ENDPOINT),
                MY_API_KEY
                );
            builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Trace));
            builder.Plugins.AddFromType<DatePlugin>();
            var kernel = builder.Build();

            var chatAgent = new ChatCompletionAgent
            {
                Kernel = kernel,
                LoggerFactory = kernel.LoggerFactory,
                Arguments = new KernelArguments(
                                new OpenAIPromptExecutionSettings()
                                {
                                    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
                                }),
            };

            var history = new ChatHistory();
            history.AddUserMessage("What is the current date ?");

            await foreach (var t in chatAgent.InvokeAsync(history))
            {
                Console.WriteLine(t.Content);
            }
        }

        public class DatePlugin
        {
            [KernelFunction()]
            [Description("Returns the current date.")]
            [return: Description("Current date.")]
            public string GetCurrentDate() => DateOnly.FromDateTime(DateTime.UtcNow).ToString("D");
        }
    }
}

My csproj :

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
    <PackageReference Include="Microsoft.SemanticKernel.Agents.Core" Version="1.40.1-preview" />
    <PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.40.1" />
  </ItemGroup>
</Project>

I am trying to use Semantic Kernel plugins through OpenAI connector with DeepSeek-R1 deployed on Azure Foundry. I can connect to the LLM and get responses.

But I can't leverage Semantic Kernel plugins. The plugins seem to be ignored. For example, in the code below, I have declared a DatePlugin with its GetCurrentDate function, but asking:

What is the current date ?

returns

Hi there! I suggest getting online to get real-time information. If you have any other questions, please don't hesitate to let me know!

I have tried with several other types of functions, with no more luck. Do you know how to proceed ? Is it even possible to achieve this ?

namespace DeepSeekR1Test
{
    using System.ComponentModel;

    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    using Microsoft.SemanticKernel;
    using Microsoft.SemanticKernel.Agents;
    using Microsoft.SemanticKernel.ChatCompletion;
    using Microsoft.SemanticKernel.Connectors.OpenAI;

    internal class Program
    {
        static async Task Main(string[] args)
        {
            var builder = Kernel.CreateBuilder();

#pragma warning disable SKEXP0010 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
            builder.AddOpenAIChatCompletion(
                modelId: "DeepSeek-R1",
                new Uri(MY_AZURE_OPENAI_ENDPOINT),
                MY_API_KEY
                );
            builder.Services.AddLogging(c => c.AddConsole().SetMinimumLevel(LogLevel.Trace));
            builder.Plugins.AddFromType<DatePlugin>();
            var kernel = builder.Build();

            var chatAgent = new ChatCompletionAgent
            {
                Kernel = kernel,
                LoggerFactory = kernel.LoggerFactory,
                Arguments = new KernelArguments(
                                new OpenAIPromptExecutionSettings()
                                {
                                    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
                                }),
            };

            var history = new ChatHistory();
            history.AddUserMessage("What is the current date ?");

            await foreach (var t in chatAgent.InvokeAsync(history))
            {
                Console.WriteLine(t.Content);
            }
        }

        public class DatePlugin
        {
            [KernelFunction()]
            [Description("Returns the current date.")]
            [return: Description("Current date.")]
            public string GetCurrentDate() => DateOnly.FromDateTime(DateTime.UtcNow).ToString("D");
        }
    }
}

My csproj :

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>


  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
    <PackageReference Include="Microsoft.SemanticKernel.Agents.Core" Version="1.40.1-preview" />
    <PackageReference Include="Microsoft.SemanticKernel.Connectors.OpenAI" Version="1.40.1" />
  </ItemGroup>
</Project>
Share Improve this question edited Mar 11 at 15:47 jbl asked Mar 11 at 14:34 jbljbl 15.4k3 gold badges36 silver badges102 bronze badges 4
  • Does the code work correctly when using another model that supports function calling? – Peter Bons Commented Mar 11 at 14:57
  • @PeterBons yes it works with a gpt-4o deployment. Only difference is that I then use AddAzureOpenAIChatCompletion and AzureOpenAIPromptExecutionSettings – jbl Commented Mar 11 at 15:41
  • And does deepseek work with the same code using AddAzureOpenAIChatCompletion? – Peter Bons Commented Mar 12 at 6:59
  • @PeterBons unable to tell. I could not succeed connecting using AzureOpenAI feature – jbl Commented Mar 12 at 13:28
Add a comment  | 

1 Answer 1

Reset to default 1

In fact, DeepSeek-R1 does not support function calling yet.

As of now, DeepSeek R1 does not natively support function calling or structured outputs.

While we don’t have a specific release date yet, we aim to roll out these features in the next major update.

Issue Function calling #9

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788022a4593743.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信