Skip to content

Commit d3b95b4

Browse files
authored
Merge pull request #81 from cnblogs/upgrade-ms-ai-extension
feat: migrate to ms.extensions.ai 25161.3
2 parents 630119d + c298b14 commit d3b95b4

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

sample/Cnblogs.DashScope.Sample/Cnblogs.DashScope.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25114.11" />
23+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.3.0-preview.1.25161.3" />
2424
</ItemGroup>
2525

2626
</Project>

src/Cnblogs.DashScope.AI/Cnblogs.DashScope.AI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25114.11" />
13+
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.3.0-preview.1.25161.3" />
1414
</ItemGroup>
1515

1616
</Project>

src/Cnblogs.DashScope.AI/DashScopeChatClient.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId)
4343

4444
/// <inheritdoc />
4545
public async Task<ChatResponse> GetResponseAsync(
46-
IList<ChatMessage> chatMessages,
46+
IEnumerable<ChatMessage> chatMessages,
4747
ChatOptions? options = null,
4848
CancellationToken cancellationToken = default)
4949
{
@@ -130,7 +130,7 @@ public async Task<ChatResponse> GetResponseAsync(
130130

131131
/// <inheritdoc />
132132
public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
133-
IList<ChatMessage> chatMessages,
133+
IEnumerable<ChatMessage> chatMessages,
134134
ChatOptions? options = null,
135135
[EnumeratorCancellation] CancellationToken cancellationToken = default)
136136
{
@@ -202,10 +202,10 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
202202
yield return new ChatResponseUpdate()
203203
{
204204
ResponseId = completion.ResponseId,
205-
Role = completion.Message.Role,
205+
Role = completion.Messages[0].Role,
206206
AdditionalProperties = completion.AdditionalProperties,
207-
Contents = completion.Message.Contents,
208-
RawRepresentation = completion.Message.RawRepresentation,
207+
Contents = completion.Messages[0].Contents,
208+
RawRepresentation = completion.Messages[0].RawRepresentation,
209209
CreatedAt = completion.CreatedAt,
210210
FinishReason = completion.FinishReason,
211211
ModelId = completion.ModelId,
@@ -392,11 +392,11 @@ private List<MultimodalMessageContent> ToMultimodalMessageContents(IList<AIConte
392392
var content = aiContent switch
393393
{
394394
TextContent text => MultimodalMessageContent.TextContent(text.Text),
395-
DataContent { Data.Length: > 0 } data when data.MediaTypeStartsWith("image") =>
395+
DataContent { Data.Length: > 0 } data when data.HasTopLevelMediaType("image") =>
396396
MultimodalMessageContent.ImageContent(
397-
data.Data.Value.Span,
397+
data.Data.Span,
398398
data.MediaType ?? throw new InvalidOperationException("image media type should not be null")),
399-
DataContent { Uri: { } uri } data when data.MediaTypeStartsWith("image") =>
399+
DataContent { Uri: { } uri } data when data.HasTopLevelMediaType("image") =>
400400
MultimodalMessageContent.ImageContent(uri),
401401
_ => null
402402
};
@@ -422,7 +422,7 @@ private IEnumerable<TextChatMessage> ToTextChatMessages(
422422
{
423423
yield return new TextChatMessage(
424424
from.Role.Value,
425-
from.Text ?? string.Empty,
425+
from.Text,
426426
from.AuthorName);
427427
}
428428
else if (from.Role == ChatRole.Tool)
@@ -464,7 +464,7 @@ private IEnumerable<TextChatMessage> ToTextChatMessages(
464464
// <400> InternalError.Algo.InvalidParameter: Empty tool_calls is not supported in message
465465
yield return new TextChatMessage(
466466
from.Role.Value,
467-
from.Text ?? string.Empty,
467+
from.Text,
468468
from.AuthorName,
469469
null,
470470
functionCall.Count > 0 ? functionCall : null);

src/Cnblogs.DashScope.AI/DashScopeTextEmbeddingGenerator.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public DashScopeTextEmbeddingGenerator(IDashScopeClient dashScopeClient, string
2929
_dashScopeClient = dashScopeClient;
3030
_modelId = modelId;
3131
_parameters = new TextEmbeddingParameters { Dimension = dimensions };
32-
Metadata = new EmbeddingGeneratorMetadata("dashscope", _dashScopeClient.BaseAddress, modelId, dimensions);
3332
}
3433

3534
/// <inheritdoc />
@@ -88,7 +87,4 @@ public void Dispose()
8887
options.AdditionalProperties?.GetValueOrDefault(nameof(TextEmbeddingParameters.TextType)) as string,
8988
};
9089
}
91-
92-
/// <inheritdoc />
93-
public EmbeddingGeneratorMetadata Metadata { get; }
9490
}

test/Cnblogs.DashScope.Sdk.UnitTests/ChatClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task ChatClient_TextCompletion_SuccessAsync()
4646
Arg.Is<ModelRequest<TextGenerationInput, ITextGenerationParameters>>(
4747
m => m.IsEquivalent(testCase.RequestModel)),
4848
Arg.Any<CancellationToken>());
49-
response.Message.Text.Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content);
49+
response.Messages[0].Text.Should().Be(testCase.ResponseModel.Output.Choices?.First().Message.Content);
5050
}
5151

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

test/Cnblogs.DashScope.Sdk.UnitTests/Utils/Snapshots.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ public static class MultimodalGeneration
781781
MultimodalMessage.User(
782782
[
783783
MultimodalMessageContent.ImageContent(
784-
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
784+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="),
785785
MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答")
786786
])
787787
]
@@ -881,7 +881,7 @@ public static class MultimodalGeneration
881881
MultimodalMessage.User(
882882
[
883883
MultimodalMessageContent.ImageContent(
884-
"https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"),
884+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="),
885885
MultimodalMessageContent.TextContent("这个图片是哪里,请用简短的语言回答")
886886
])
887887
]

0 commit comments

Comments
 (0)