@@ -34,7 +34,6 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId)
3434
3535 _dashScopeClient = dashScopeClient ;
3636 _modelId = modelId ;
37- Metadata = new ChatClientMetadata ( "dashscope" , _dashScopeClient . BaseAddress , _modelId ) ;
3837 }
3938
4039 /// <summary>
@@ -43,7 +42,7 @@ public DashScopeChatClient(IDashScopeClient dashScopeClient, string modelId)
4342 public JsonSerializerOptions ToolCallJsonSerializerOptions { get ; set ; } = new ( JsonSerializerDefaults . Web ) ;
4443
4544 /// <inheritdoc />
46- public async Task < ChatCompletion > CompleteAsync (
45+ public async Task < ChatResponse > GetResponseAsync (
4746 IList < ChatMessage > chatMessages ,
4847 ChatOptions ? options = null ,
4948 CancellationToken cancellationToken = default )
@@ -52,7 +51,6 @@ public async Task<ChatCompletion> CompleteAsync(
5251 var useVlRaw = options ? . AdditionalProperties ? . GetValueOrDefault ( "useVl" ) ? . ToString ( ) ;
5352 var useVl = string . IsNullOrEmpty ( useVlRaw )
5453 ? modelId . Contains ( "qwen-vl" , StringComparison . OrdinalIgnoreCase )
55- || chatMessages . Any ( c => c . Contents . Any ( m => m is ImageContent ) )
5654 : string . Equals ( useVlRaw , "true" , StringComparison . OrdinalIgnoreCase ) ;
5755 if ( useVl )
5856 {
@@ -71,10 +69,10 @@ public async Task<ChatCompletion> CompleteAsync(
7169 } ;
7270
7371 returnMessage . Contents . Add ( new TextContent ( response . Output . Choices [ 0 ] . Message . Content [ 0 ] . Text ) ) ;
74- var completion = new ChatCompletion ( returnMessage )
72+ var completion = new ChatResponse ( returnMessage )
7573 {
7674 RawRepresentation = response ,
77- CompletionId = response . RequestId ,
75+ ResponseId = response . RequestId ,
7876 CreatedAt = DateTimeOffset . Now ,
7977 ModelId = modelId ,
8078 FinishReason = ToFinishReason ( response . Output . Choices [ 0 ] . FinishReason ) ,
@@ -107,10 +105,10 @@ public async Task<ChatCompletion> CompleteAsync(
107105 } ,
108106 cancellationToken ) ;
109107 var returnMessage = ToChatMessage ( response . Output . Choices ! [ 0 ] . Message ) ;
110- var completion = new ChatCompletion ( returnMessage )
108+ var completion = new ChatResponse ( returnMessage )
111109 {
112110 RawRepresentation = response ,
113- CompletionId = response . RequestId ,
111+ ResponseId = response . RequestId ,
114112 CreatedAt = DateTimeOffset . Now ,
115113 ModelId = modelId ,
116114 FinishReason = ToFinishReason ( response . Output . Choices [ 0 ] . FinishReason ) ,
@@ -131,15 +129,14 @@ public async Task<ChatCompletion> CompleteAsync(
131129 }
132130
133131 /// <inheritdoc />
134- public async IAsyncEnumerable < StreamingChatCompletionUpdate > CompleteStreamingAsync (
132+ public async IAsyncEnumerable < ChatResponseUpdate > GetStreamingResponseAsync (
135133 IList < ChatMessage > chatMessages ,
136134 ChatOptions ? options = null ,
137135 [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
138136 {
139137 var useVlRaw = options ? . AdditionalProperties ? . GetValueOrDefault ( "useVl" ) ? . ToString ( ) ;
140- var useVl = string . IsNullOrEmpty ( useVlRaw )
141- ? chatMessages . Any ( c => c . Contents . Any ( m => m is ImageContent ) )
142- : string . Equals ( useVlRaw , "true" , StringComparison . OrdinalIgnoreCase ) ;
138+ var useVl = string . Equals ( useVlRaw , "true" , StringComparison . OrdinalIgnoreCase )
139+ || ( options ? . ModelId ? . Contains ( "qwen-vl" ) ?? false ) ;
143140 var modelId = options ? . ModelId ?? _modelId ;
144141
145142 ChatRole ? streamedRole = null ;
@@ -167,9 +164,9 @@ public async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAs
167164 : ToFinishReason ( response . Output . Choices [ 0 ] . FinishReason ) ;
168165 completionId ??= response . RequestId ;
169166
170- var update = new StreamingChatCompletionUpdate ( )
167+ var update = new ChatResponseUpdate ( )
171168 {
172- CompletionId = completionId ,
169+ ResponseId = completionId ,
173170 CreatedAt = DateTimeOffset . Now ,
174171 FinishReason = finishReason ,
175172 ModelId = modelId ,
@@ -201,10 +198,10 @@ public async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAs
201198 if ( options ? . Tools is { Count : > 0 } )
202199 {
203200 // qwen does not support streaming with function call, fallback to non-streaming
204- var completion = await CompleteAsync ( chatMessages , options , cancellationToken ) ;
205- yield return new StreamingChatCompletionUpdate ( )
201+ var completion = await GetResponseAsync ( chatMessages , options , cancellationToken ) ;
202+ yield return new ChatResponseUpdate ( )
206203 {
207- CompletionId = completion . CompletionId ,
204+ ResponseId = completion . ResponseId ,
208205 Role = completion . Message . Role ,
209206 AdditionalProperties = completion . AdditionalProperties ,
210207 Contents = completion . Message . Contents ,
@@ -241,9 +238,9 @@ public async IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAs
241238 : ToFinishReason ( response . Output . Choices [ 0 ] . FinishReason ) ;
242239 completionId ??= response . RequestId ;
243240
244- var update = new StreamingChatCompletionUpdate ( )
241+ var update = new ChatResponseUpdate ( )
245242 {
246- CompletionId = completionId ,
243+ ResponseId = completionId ,
247244 CreatedAt = DateTimeOffset . Now ,
248245 FinishReason = finishReason ,
249246 ModelId = modelId ,
@@ -289,9 +286,6 @@ public void Dispose()
289286 // nothing to dispose.
290287 }
291288
292- /// <inheritdoc />
293- public ChatClientMetadata Metadata { get ; }
294-
295289 private static ChatFinishReason ? ToFinishReason ( string ? finishReason )
296290 => string . IsNullOrEmpty ( finishReason )
297291 ? null
@@ -398,10 +392,12 @@ private List<MultimodalMessageContent> ToMultimodalMessageContents(IList<AIConte
398392 var content = aiContent switch
399393 {
400394 TextContent text => MultimodalMessageContent . TextContent ( text . Text ) ,
401- ImageContent { Data . Length : > 0 } image => MultimodalMessageContent . ImageContent (
402- image . Data . Value . Span ,
403- image . MediaType ?? throw new InvalidOperationException ( "image media type should not be null" ) ) ,
404- ImageContent { Uri : { } uri } => MultimodalMessageContent . ImageContent ( uri ) ,
395+ DataContent { Data . Length : > 0 } data when data . MediaTypeStartsWith ( "image" ) =>
396+ MultimodalMessageContent . ImageContent (
397+ data . Data . Value . Span ,
398+ data . MediaType ?? throw new InvalidOperationException ( "image media type should not be null" ) ) ,
399+ DataContent { Uri : { } uri } data when data . MediaTypeStartsWith ( "image" ) =>
400+ MultimodalMessageContent . ImageContent ( uri ) ,
405401 _ => null
406402 } ;
407403 if ( content is not null )
@@ -513,15 +509,13 @@ RequiredChatToolMode required when string.IsNullOrEmpty(required.RequiredFunctio
513509 f => new ToolDefinition (
514510 "function" ,
515511 new FunctionDefinition (
516- f . Metadata . Name ,
517- f . Metadata . Description ,
518- GetParameterSchema ( f . Metadata . Parameters ) ) ) ) ;
512+ f . Name ,
513+ f . Description ,
514+ GetParameterSchema ( f . JsonSchema ) ) ) ) ;
519515 }
520516
521- private static JsonSchema GetParameterSchema ( IEnumerable < AIFunctionParameterMetadata > metadata )
517+ private static JsonSchema GetParameterSchema ( JsonElement metadata )
522518 {
523- return new JsonSchemaBuilder ( )
524- . Properties ( metadata . Select ( c => ( c . Name , Schema : c . Schema as JsonSchema ?? EmptyObjectSchema ) ) . ToArray ( ) )
525- . Build ( ) ;
519+ return metadata . Deserialize < JsonSchema > ( ) ?? EmptyObjectSchema ;
526520 }
527521}
0 commit comments