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
|
1 Answer
Reset to default 1In 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
AddAzureOpenAIChatCompletion
andAzureOpenAIPromptExecutionSettings
– jbl Commented Mar 11 at 15:41AddAzureOpenAIChatCompletion
? – Peter Bons Commented Mar 12 at 6:59