Skip to content
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
1 change: 1 addition & 0 deletions src/xAI.Tests/SanityChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void AssertIntegrationTest(ChatResponse response, Func<int> getDateCalls)
Assert.NotNull(response);
Assert.NotNull(response.ModelId);
Assert.NotEmpty(response.Messages);
Assert.NotNull(response.Usage);

// Verify client-side tool was invoked
Assert.True(getDateCalls() >= 1);
Expand Down
8 changes: 6 additions & 2 deletions src/xAI/GrokChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ async IAsyncEnumerable<ChatResponseUpdate> CompleteChatStreamingCore(IEnumerable

((List<AIContent>)update.Contents).AddRange(output.Delta.ToolCalls.AsContents(text, citations));

if (update.Contents.Any())
yield return update;
if (MapToUsage(chunk.Usage) is { } usage)
update.Contents.Add(new UsageContent(usage) { RawRepresentation = chunk.Usage });

yield return update;
}
}
}
Expand Down Expand Up @@ -277,6 +279,8 @@ codeResult.RawRepresentation is ToolCall codeToolCall &&
{
InputTokenCount = usage.PromptTokens,
OutputTokenCount = usage.CompletionTokens,
CachedInputTokenCount = usage.CachedPromptTextTokens,
ReasoningTokenCount = usage.ReasoningTokens,
TotalTokenCount = usage.TotalTokens
};

Expand Down