diff --git a/src/KernelMemory.DashScope/KernelMemory.DashScope.csproj b/src/KernelMemory.DashScope/KernelMemory.DashScope.csproj
index 336a699..6aca2d6 100644
--- a/src/KernelMemory.DashScope/KernelMemory.DashScope.csproj
+++ b/src/KernelMemory.DashScope/KernelMemory.DashScope.csproj
@@ -19,8 +19,8 @@
-
-
+
+
diff --git a/src/SemanticKernel.DashScope/DashScopeChatCompletionService.cs b/src/SemanticKernel.DashScope/DashScopeChatCompletionService.cs
index 91dcefa..f0bf0e7 100644
--- a/src/SemanticKernel.DashScope/DashScopeChatCompletionService.cs
+++ b/src/SemanticKernel.DashScope/DashScopeChatCompletionService.cs
@@ -55,6 +55,7 @@ public async Task> GetChatMessageContentsAsync
var autoInvoke = kernel is not null && chatParameters.ToolCallBehavior?.MaximumAutoInvokeAttempts > 0;
for (var it = 1; ; it++)
{
+ var chatParametersTools = chatParameters.Tools?.ToList();
var response = await _dashScopeClient.GetTextCompletionAsync(
new ModelRequest
{
@@ -83,14 +84,14 @@ public async Task> GetChatMessageContentsAsync
foreach (var call in message.ToolCalls)
{
- if (call.Type is not ToolTypes.Function || call.Function is null)
+ if (call.Type is not ToolTypes.Function)
{
AddResponseMessage(chat, null, "Error: Tool call was not a function call.", call.Id);
continue;
}
// ensure not calling function that was not included in request list.
- if (chatParameters.Tools?.Any(
+ if (chatParametersTools?.Any(
x => string.Equals(x.Function?.Name, call.Function.Name, StringComparison.OrdinalIgnoreCase))
!= true)
{
@@ -133,7 +134,7 @@ public async Task> GetChatMessageContentsAsync
AddResponseMessage(chat, stringResult, null, call.Id);
}
- chatParameters.Tools?.Clear();
+ chatParameters.Tools = [];
chatParameters.ToolCallBehavior?.ConfigureOptions(kernel, chatParameters);
if (it >= chatParameters.ToolCallBehavior!.MaximumAutoInvokeAttempts)
{
@@ -273,7 +274,7 @@ private void LogToolCalls(IReadOnlyCollection? calls)
{
_logger.LogTrace(
"Function call requests: {Requests}",
- string.Join(", ", calls.Select(ftc => $"{ftc.Function?.Name}({ftc.Function?.Arguments})")));
+ string.Join(", ", calls.Select(ftc => $"{ftc.Function.Name}({ftc.Function.Arguments})")));
}
}
diff --git a/src/SemanticKernel.DashScope/DashScopeMapper.cs b/src/SemanticKernel.DashScope/DashScopeMapper.cs
index 6f3d983..90594de 100644
--- a/src/SemanticKernel.DashScope/DashScopeMapper.cs
+++ b/src/SemanticKernel.DashScope/DashScopeMapper.cs
@@ -5,17 +5,17 @@ namespace Cnblogs.SemanticKernel.Connectors.DashScope;
internal static class DashScopeMapper
{
- public static List ToChatMessages(this ChatHistory history)
+ public static List ToChatMessages(this ChatHistory history)
{
return history.Select(
x =>
{
if (x is DashScopeChatMessageContent d)
{
- return new ChatMessage(x.Role.Label, x.Content ?? string.Empty, d.Name, ToolCalls: d.ToolCalls);
+ return new TextChatMessage(x.Role.Label, x.Content ?? string.Empty, d.Name, ToolCalls: d.ToolCalls);
}
- return new ChatMessage(x.Role.Label, x.Content ?? string.Empty);
+ return new TextChatMessage(x.Role.Label, x.Content ?? string.Empty);
}).ToList();
}
diff --git a/src/SemanticKernel.DashScope/DashScopePromptExecutionSettings.cs b/src/SemanticKernel.DashScope/DashScopePromptExecutionSettings.cs
index ae448bd..4b2a6e9 100644
--- a/src/SemanticKernel.DashScope/DashScopePromptExecutionSettings.cs
+++ b/src/SemanticKernel.DashScope/DashScopePromptExecutionSettings.cs
@@ -26,12 +26,18 @@ public class DashScopePromptExecutionSettings : PromptExecutionSettings, ITextGe
///
public string? ResultFormat { get; set; }
+ ///
+ public DashScopeResponseFormat? ResponseFormat { get; }
+
///
public int? MaxTokens { get; set; }
///
public float? RepetitionPenalty { get; set; }
+ ///
+ public float? PresencePenalty { get; }
+
///
public float? Temperature { get; set; }
@@ -42,7 +48,10 @@ public class DashScopePromptExecutionSettings : PromptExecutionSettings, ITextGe
public bool? EnableSearch { get; set; }
///
- public List? Tools { get; internal set; }
+ public ToolChoice? ToolChoice { get; }
+
+ ///
+ public IEnumerable? Tools { get; set; }
///
/// Gets or sets the behavior for how tool calls are handled.
diff --git a/src/SemanticKernel.DashScope/SemanticKernel.DashScope.csproj b/src/SemanticKernel.DashScope/SemanticKernel.DashScope.csproj
index f98ec04..a146af5 100644
--- a/src/SemanticKernel.DashScope/SemanticKernel.DashScope.csproj
+++ b/src/SemanticKernel.DashScope/SemanticKernel.DashScope.csproj
@@ -19,9 +19,9 @@
-
-
-
+
+
+
diff --git a/test/KernelMemory.DashScope.UnitTests/KernelMemory.DashScope.UnitTests.csproj b/test/KernelMemory.DashScope.UnitTests/KernelMemory.DashScope.UnitTests.csproj
index c03cfbe..85dd895 100644
--- a/test/KernelMemory.DashScope.UnitTests/KernelMemory.DashScope.UnitTests.csproj
+++ b/test/KernelMemory.DashScope.UnitTests/KernelMemory.DashScope.UnitTests.csproj
@@ -14,14 +14,14 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/test/SemanticKernel.DashScope.UnitTest/Cases.cs b/test/SemanticKernel.DashScope.UnitTest/Cases.cs
index 93eb1be..51b0771 100644
--- a/test/SemanticKernel.DashScope.UnitTest/Cases.cs
+++ b/test/SemanticKernel.DashScope.UnitTest/Cases.cs
@@ -95,6 +95,7 @@ public static ModelResponse ErrT
(f, i) => new ToolCall(
$"{i}",
toolType,
+ i,
new($"{pluginName}-{f.Name}", paramBody))).ToList())
}
]
@@ -125,6 +126,7 @@ public static ModelResponse
f => new ToolCall(
"0",
"function",
+ 0,
new($"MyPlugin-{f.Name}", "{\"location\": \"LA\"}"))).ToList())
}
]
diff --git a/test/SemanticKernel.DashScope.UnitTest/SemanticKernel.DashScope.UnitTest.csproj b/test/SemanticKernel.DashScope.UnitTest/SemanticKernel.DashScope.UnitTest.csproj
index 933fb1c..5348e5d 100644
--- a/test/SemanticKernel.DashScope.UnitTest/SemanticKernel.DashScope.UnitTest.csproj
+++ b/test/SemanticKernel.DashScope.UnitTest/SemanticKernel.DashScope.UnitTest.csproj
@@ -6,11 +6,11 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+