@@ -18,7 +18,8 @@ public sealed class DashScopeChatClient : IChatClient
1818 private static readonly JsonSchema EmptyObjectSchema =
1919 JsonSchema . FromText ( """{"type":"object","required":[],"properties":{}}""" ) ;
2020
21- private static readonly TextGenerationParameters DefaultTextGenerationParameter = new ( ) { ResultFormat = "message" } ;
21+ private static readonly TextGenerationParameters
22+ DefaultTextGenerationParameter = new ( ) { ResultFormat = "message" } ;
2223
2324 /// <summary>
2425 /// Initialize a new instance of the
@@ -57,7 +58,7 @@ public async Task<ChatCompletion> CompleteAsync(
5758 }
5859 else
5960 {
60- var parameters = options
61+ var parameters = ToTextGenerationParameters ( options ) ?? DefaultTextGenerationParameter ;
6162 var response = await _dashScopeClient . GetTextCompletionAsync (
6263 new ModelRequest < TextGenerationInput , ITextGenerationParameters > ( )
6364 {
@@ -67,8 +68,10 @@ public async Task<ChatCompletion> CompleteAsync(
6768 Tools = ToToolDefinitions ( options ? . Tools )
6869 } ,
6970 Model = _modelId ,
70- Parameters =
71- } )
71+ Parameters = parameters
72+ } ,
73+ cancellationToken ) ;
74+
7275 }
7376 }
7477
@@ -156,19 +159,25 @@ public void Dispose()
156159 format = "json_object" ;
157160 }
158161
159-
160- var parameter = new TextGenerationParameters ( )
162+ return new TextGenerationParameters ( )
161163 {
162164 ResultFormat = format ,
163165 Temperature = options . Temperature ,
164166 MaxTokens = options . MaxOutputTokens ,
165167 TopP = options . TopP ,
166168 TopK = options . TopK ,
167169 RepetitionPenalty = options . FrequencyPenalty ,
170+ PresencePenalty = options . PresencePenalty ,
168171 Seed = options . Seed == null ? null : ( ulong ) options . Seed . Value ,
169172 Stop = options . StopSequences == null ? null : new TextGenerationStop ( options . StopSequences ) ,
170173 Tools = options . Tools == null ? null : ToToolDefinitions ( options . Tools ) ,
171- ToolChoice = options . ToolMode
174+ ToolChoice = options . ToolMode switch
175+ {
176+ AutoChatToolMode => ToolChoice . AutoChoice ,
177+ RequiredChatToolMode required when string . IsNullOrEmpty ( required . RequiredFunctionName ) == false =>
178+ ToolChoice . FunctionChoice ( required . RequiredFunctionName ) ,
179+ _ => ToolChoice . AutoChoice
180+ }
172181 } ;
173182 }
174183
0 commit comments