Skip to content

feat: update sk version #31

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 2 commits into from
May 24, 2025
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
7 changes: 5 additions & 2 deletions src/KernelMemory.DashScope/DashScopeTextGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using Cnblogs.DashScope.Core;
using Microsoft.Extensions.Logging;
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.AI;
using Microsoft.KernelMemory.Diagnostics;

Expand Down Expand Up @@ -38,7 +39,7 @@ public IReadOnlyList<string> GetTokens(string text)
}

/// <inheritdoc />
public async IAsyncEnumerable<string> GenerateTextAsync(
public async IAsyncEnumerable<GeneratedTextContent> GenerateTextAsync(
string prompt,
TextGenerationOptions options,
[EnumeratorCancellation] CancellationToken cancellationToken = new())
Expand Down Expand Up @@ -71,7 +72,9 @@ public async IAsyncEnumerable<string> GenerateTextAsync(
var tokens = dashScopeClient.GetTextCompletionStreamAsync(request, cancellationToken);
await foreach (var token in tokens)
{
yield return token.Output.Text!;
yield return new GeneratedTextContent(
token.Output.Text ?? string.Empty,
token.Usage.ToKernelMemoryTokenUsage(modelId));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/KernelMemory.DashScope/KernelMemory.DashScope.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.KernelMemory.Abstractions" Version="0.95.241216.2" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.5.2" />
<PackageReference Include="Microsoft.KernelMemory.Abstractions" Version="0.98.250508.3" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.7.3" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions src/KernelMemory.DashScope/TokenUsageMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Cnblogs.DashScope.Core;
using Microsoft.KernelMemory;

namespace Cnblogs.KernelMemory.AI.DashScope;

internal static class TokenUsageMapper
{
public static TokenUsage? ToKernelMemoryTokenUsage(this TextGenerationTokenUsage? usage, string? modelId)
{
if (usage == null)
{
return null;
}

return new TokenUsage()
{
ServiceTokensIn = usage.InputTokens,
ServiceTokensOut = usage.OutputTokens,
ModelName = modelId
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class DashScopePromptExecutionSettings : PromptExecutionSettings, ITextGe
/// <inheritdoc />
public ToolChoice? ToolChoice { get; }

/// <inheritdoc />
public bool? ParallelToolCalls { get; set; }

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

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.5.2" />
<PackageReference Include="JsonSchema.Net.Generation" Version="4.6.0" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.32.0" />
<PackageReference Include="Cnblogs.DashScope.Core" Version="0.7.3" />
<PackageReference Include="JsonSchema.Net.Generation" Version="5.0.2" />
<PackageReference Include="Microsoft.SemanticKernel.Core" Version="1.54.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task TextGenerator_GenerateText_IncrementalGenerateAsync()
var response = await generator.GenerateTextAsync(Cases.Text, Cases.TextGenerationOptions).ToListAsync();

// Assert
response[0].Should().BeSameAs(
response[0].Text.Should().BeSameAs(
Cases.TextGenerationResponse.Output.Text,
"generated text should mapped from output.text");
captured.Should().BeEquivalentTo(
Expand All @@ -51,7 +51,7 @@ public async Task TextGenerator_DefaultsToZero_MapZeroToNullAsync()
var response = await generator.GenerateTextAsync(Cases.Text, Cases.TextGenerationOptions).ToListAsync();

// Assert
response[0].Should().BeSameAs(
response[0].Text.Should().BeSameAs(
Cases.TextGenerationResponse.Output.Text,
"generated text should mapped from output.text");
captured.Should().BeEquivalentTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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="3.0.0">
<PackageReference Include="Microsoft.KernelMemory.Core" Version="0.98.250508.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="FluentAssertions" Version="7.0.0" />
<PackageReference Update="FluentAssertions" Version="8.2.0" />
<PackageReference Update="NSubstitute" Version="5.3.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="FluentAssertions" Version="7.0.0" />
<PackageReference Update="FluentAssertions" Version="8.2.0" />
<PackageReference Update="NSubstitute" Version="5.3.0" />
</ItemGroup>
<ItemGroup>
Expand Down