Skip to content

feat: migrate to ms.extensions.ai 25161.3 #81

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
Mar 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions src/Cnblogs.DashScope.AI/DashScopeChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId)

/// <inheritdoc />
public async Task<ChatResponse> GetResponseAsync(
IList<ChatMessage> chatMessages,
IEnumerable<ChatMessage> chatMessages,
ChatOptions? options = null,
CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task<ChatResponse> GetResponseAsync(

/// <inheritdoc />
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
IList<ChatMessage> chatMessages,
IEnumerable<ChatMessage> chatMessages,
ChatOptions? options = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -202,10 +202,10 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
yield return new ChatResponseUpdate()
{
ResponseId = completion.ResponseId,
Role = completion.Message.Role,
Role = completion.Messages[0].Role,
AdditionalProperties = completion.AdditionalProperties,
Contents = completion.Message.Contents,
RawRepresentation = completion.Message.RawRepresentation,
Contents = completion.Messages[0].Contents,
RawRepresentation = completion.Messages[0].RawRepresentation,
CreatedAt = completion.CreatedAt,
FinishReason = completion.FinishReason,
ModelId = completion.ModelId,
Expand Down Expand Up @@ -392,11 +392,11 @@ private List<MultimodalMessageContent> ToMultimodalMessageContents(IList<AIConte
var content = aiContent switch
{
TextContent text => MultimodalMessageContent.TextContent(text.Text),
DataContent { Data.Length: > 0 } data when data.MediaTypeStartsWith("image") =>
DataContent { Data.Length: > 0 } data when data.HasTopLevelMediaType("image") =>
MultimodalMessageContent.ImageContent(
data.Data.Value.Span,
data.Data.Span,
data.MediaType ?? throw new InvalidOperationException("image media type should not be null")),
DataContent { Uri: { } uri } data when data.MediaTypeStartsWith("image") =>
DataContent { Uri: { } uri } data when data.HasTopLevelMediaType("image") =>
MultimodalMessageContent.ImageContent(uri),
_ => null
};
Expand All @@ -422,7 +422,7 @@ private IEnumerable<TextChatMessage> ToTextChatMessages(
{
yield return new TextChatMessage(
from.Role.Value,
from.Text ?? string.Empty,
from.Text,
from.AuthorName);
}
else if (from.Role == ChatRole.Tool)
Expand Down Expand Up @@ -464,7 +464,7 @@ private IEnumerable<TextChatMessage> ToTextChatMessages(
// <400> InternalError.Algo.InvalidParameter: Empty tool_calls is not supported in message
yield return new TextChatMessage(
from.Role.Value,
from.Text ?? string.Empty,
from.Text,
from.AuthorName,
null,
functionCall.Count > 0 ? functionCall : null);
Expand Down
4 changes: 0 additions & 4 deletions src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public DashScopeTextEmbeddingGenerator(IDashScopeClient dashScopeClient, string
_dashScopeClient = dashScopeClient;
_modelId = modelId;
_parameters = new TextEmbeddingParameters { Dimension = dimensions };
Metadata = new EmbeddingGeneratorMetadata("dashscope", _dashScopeClient.BaseAddress, modelId, dimensions);
}

/// <inheritdoc />
Expand Down Expand Up @@ -88,7 +87,4 @@ public void Dispose()
options.AdditionalProperties?.GetValueOrDefault(nameof(TextEmbeddingParameters.TextType)) as string,
};
}

/// <inheritdoc />
public EmbeddingGeneratorMetadata Metadata { get; }
}
4 changes: 2 additions & 2 deletions test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task ChatClient_TextCompletion_SuccessAsync()
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
m => m.IsEquivalent(testCase.RequestModel)),
Arg.Any<CancellationToken>());
response.Message.Text.Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content);
response.Messages[0].Text.Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content);
}

[Fact]
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task ChatClient_ImageRecognition_SuccessAsync()
await dashScopeClient.Received().GetMultimodalGenerationAsync(
Arg.Is<ModelRequest<MultimodalInput, IMultimodalParameters>>(m => m.IsEquivalent(testCase.RequestModel)),
Arg.Any<CancellationToken>());
response.Choices[0].Text.Should()
response.Messages[0].Text.Should()
.BeEquivalentTo(testCase.ResponseModel.Output.Choices[0].Message.Content[0].Text);
}

Expand Down
4 changes: 2 additions & 2 deletions test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ public static class MultimodalGeneration
MultimodalMessage.User(
[
MultimodalMessageContent.ImageContent(
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="),
MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答")
])
]
Expand Down Expand Up @@ -881,7 +881,7 @@ public static class MultimodalGeneration
MultimodalMessage.User(
[
MultimodalMessageContent.ImageContent(
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="),
MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答")
])
]
Expand Down