Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsageMetadata - add cachedContentTokenCount field #178

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/angry-hotels-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@google/generative-ai": minor
---

Add a `cachedContentTokenCount` field to the `UsageMetadata` interface returned by `generateContent` responses.
1 change: 1 addition & 0 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ export interface ToolConfig {

// @public
export interface UsageMetadata {
cachedContentTokenCount: number;
candidatesTokenCount: number;
promptTokenCount: number;
totalTokenCount: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@google/generative-ai](./generative-ai.md) &gt; [UsageMetadata](./generative-ai.usagemetadata.md) &gt; [cachedContentTokenCount](./generative-ai.usagemetadata.cachedcontenttokencount.md)

## UsageMetadata.cachedContentTokenCount property

Total token count in the cached part of the prompt, i.e. in the cached content.

**Signature:**

```typescript
cachedContentTokenCount: number;
```
1 change: 1 addition & 0 deletions docs/reference/main/generative-ai.usagemetadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface UsageMetadata

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [cachedContentTokenCount](./generative-ai.usagemetadata.cachedcontenttokencount.md) | | number | Total token count in the cached part of the prompt, i.e. in the cached content. |
| [candidatesTokenCount](./generative-ai.usagemetadata.candidatestokencount.md) | | number | Total number of tokens across the generated candidates. |
| [promptTokenCount](./generative-ai.usagemetadata.prompttokencount.md) | | number | Number of tokens in the prompt. |
| [totalTokenCount](./generative-ai.usagemetadata.totaltokencount.md) | | number | Total token count for the generation request (prompt + candidates). |
Expand Down
2 changes: 2 additions & 0 deletions packages/main/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface UsageMetadata {
candidatesTokenCount: number;
/** Total token count for the generation request (prompt + candidates). */
totalTokenCount: number;
/** Total token count in the cached part of the prompt, i.e. in the cached content. */
cachedContentTokenCount: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing just occurred to me, are these in fact always populated? (I'm not even sure about the previously existing fields here.) I know the proto doesn't list any of these as optional but it doesn't seem like these would always be populated in actual practice. If not we should probably make it optional. I did a quick test against autopush not using cached content and I got back the 3 other properties but not this one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not always populated. I figured if this was a problem then the non-cached-content integration tests would have failed.

I can make it optional.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}

/**
Expand Down
Loading