File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
src/OllamaSharp/MicrosoftAi Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -321,6 +321,18 @@ private static Microsoft.Extensions.AI.ChatRole ToAbstractionRole(ChatRole? role
321
321
/// <returns>A <see cref="ChatResponseUpdate"/> object containing the latest chat completion chunk.</returns>
322
322
public static ChatResponseUpdate ToChatResponseUpdate ( ChatResponseStream ? response , string responseId )
323
323
{
324
+ if ( response is ChatDoneResponseStream done )
325
+ {
326
+ return new ChatResponseUpdate ( ToAbstractionRole ( done . Message . Role ) , [ new UsageContent ( ParseOllamaChatResponseUsage ( done ) ) ] )
327
+ {
328
+ CreatedAt = done . CreatedAt ,
329
+ FinishReason = done . DoneReason is null ? null : new ChatFinishReason ( done . DoneReason ) ,
330
+ RawRepresentation = response ,
331
+ ResponseId = responseId ,
332
+ ModelId = done . Model
333
+ } ;
334
+ }
335
+
324
336
var contents = response ? . Message is null ? [ new TextContent ( string . Empty ) ] : GetAIContentsFromMessage ( response . Message ) ;
325
337
326
338
return new ChatResponseUpdate ( ToAbstractionRole ( response ? . Message . Role ) , contents )
@@ -426,6 +438,9 @@ private static AdditionalPropertiesDictionary ParseOllamaEmbedResponseProps(Embe
426
438
/// </summary>
427
439
/// <param name="response">The response to parse.</param>
428
440
/// <returns>A <see cref="UsageDetails"/> object containing the parsed usage details.</returns>
441
+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
442
+ [ return : System . Diagnostics . CodeAnalysis . NotNullIfNotNull ( "response" ) ]
443
+ #endif
429
444
private static UsageDetails ? ParseOllamaChatResponseUsage ( ChatDoneResponseStream ? response )
430
445
{
431
446
if ( response is not null )
You can’t perform that action at this time.
0 commit comments