Skip to content

feat: upgrade packages #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/KernelMemory.DashScope/KernelMemory.DashScope.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
<PackageReference Include="Microsoft.KernelMemory.Abstractions" Version="0.93.241118.1" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.4.0" />
<PackageReference Include="Microsoft.KernelMemory.Abstractions" Version="0.95.241216.2" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> 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<TextGenerationInput, ITextGenerationParameters>
{
Expand Down Expand Up @@ -83,14 +84,14 @@ public async Task<IReadOnlyList<ChatMessageContent>> 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)
{
Expand Down Expand Up @@ -133,7 +134,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
AddResponseMessage(chat, stringResult, null, call.Id);
}

chatParameters.Tools?.Clear();
chatParameters.Tools = [];
chatParameters.ToolCallBehavior?.ConfigureOptions(kernel, chatParameters);
if (it >= chatParameters.ToolCallBehavior!.MaximumAutoInvokeAttempts)
{
Expand Down Expand Up @@ -273,7 +274,7 @@ private void LogToolCalls(IReadOnlyCollection<ToolCall>? 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})")));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/SemanticKernel.DashScope/DashScopeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Cnblogs.SemanticKernel.Connectors.DashScope;

internal static class DashScopeMapper
{
public static List<ChatMessage> ToChatMessages(this ChatHistory history)
public static List<TextChatMessage> 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();
}

Expand Down
11 changes: 10 additions & 1 deletion src/SemanticKernel.DashScope/DashScopePromptExecutionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ public class DashScopePromptExecutionSettings : PromptExecutionSettings, ITextGe
/// <inheritdoc />
public string? ResultFormat { get; set; }

/// <inheritdoc />
public DashScopeResponseFormat? ResponseFormat { get; }

/// <inheritdoc />
public int? MaxTokens { get; set; }

/// <inheritdoc />
public float? RepetitionPenalty { get; set; }

/// <inheritdoc />
public float? PresencePenalty { get; }

/// <inheritdoc />
public float? Temperature { get; set; }

Expand All @@ -42,7 +48,10 @@ public class DashScopePromptExecutionSettings : PromptExecutionSettings, ITextGe
public bool? EnableSearch { get; set; }

/// <inheritdoc />
public List<ToolDefinition>? Tools { get; internal set; }
public ToolChoice? ToolChoice { get; }

/// <inheritdoc />
public IEnumerable<ToolDefinition>? Tools { get; set; }

/// <summary>
/// Gets or sets the behavior for how tool calls are handled.
Expand Down
6 changes: 3 additions & 3 deletions src/SemanticKernel.DashScope/SemanticKernel.DashScope.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.4.0" />
<PackageReference Include="JsonSchema.Net.Generation" Version="4.5.1" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.30.0" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.5.1" />
<PackageReference Include="JsonSchema.Net.Generation" Version="4.6.0" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.32.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.93.241118.1" />
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.95.241216.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="FluentAssertions" Version="6.12.2" />
<PackageReference Update="FluentAssertions" Version="7.0.0" />
<PackageReference Update="NSubstitute" Version="5.3.0" />
</ItemGroup>

Expand Down
2 changes: 2 additions & 0 deletions test/SemanticKernel.DashScope.UnitTest/Cases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static ModelResponse<TextGenerationOutput, TextGenerationTokenUsage> ErrT
(f, i) => new ToolCall(
$"{i}",
toolType,
i,
new($"{pluginName}-{f.Name}", paramBody))).ToList())
}
]
Expand Down Expand Up @@ -125,6 +126,7 @@ public static ModelResponse<TextGenerationOutput, TextGenerationTokenUsage>
f => new ToolCall(
"0",
"function",
0,
new($"MyPlugin-{f.Name}", "{\"location\": \"LA\"}"))).ToList())
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="FluentAssertions" Version="6.12.2" />
<PackageReference Update="FluentAssertions" Version="7.0.0" />
<PackageReference Update="NSubstitute" Version="5.3.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading