From 04239d304421133d801061d276255caccb9616c2 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 21 Jun 2024 10:26:42 -0400 Subject: [PATCH 1/3] added cached content count to usagemetadata --- common/api-review/generative-ai.api.md | 1 + ...tive-ai.usagemetadata.cachedcontenttokencount.md | 13 +++++++++++++ docs/reference/main/generative-ai.usagemetadata.md | 1 + packages/main/types/responses.ts | 2 ++ 4 files changed, 17 insertions(+) create mode 100644 docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 2e4edbbd..b09fadf5 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -638,6 +638,7 @@ export interface ToolConfig { // @public export interface UsageMetadata { + cachedContentTokenCount: number; candidatesTokenCount: number; promptTokenCount: number; totalTokenCount: number; diff --git a/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md b/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md new file mode 100644 index 00000000..707ba1f6 --- /dev/null +++ b/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@google/generative-ai](./generative-ai.md) > [UsageMetadata](./generative-ai.usagemetadata.md) > [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; +``` diff --git a/docs/reference/main/generative-ai.usagemetadata.md b/docs/reference/main/generative-ai.usagemetadata.md index 16435412..2905481d 100644 --- a/docs/reference/main/generative-ai.usagemetadata.md +++ b/docs/reference/main/generative-ai.usagemetadata.md @@ -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). | diff --git a/packages/main/types/responses.ts b/packages/main/types/responses.ts index 56933875..c7ee0c25 100644 --- a/packages/main/types/responses.ts +++ b/packages/main/types/responses.ts @@ -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; } /** From 99d27d7a7ac31ee0538a163db6624de93bc576d7 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 21 Jun 2024 10:33:44 -0400 Subject: [PATCH 2/3] changeset --- .changeset/angry-hotels-learn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/angry-hotels-learn.md diff --git a/.changeset/angry-hotels-learn.md b/.changeset/angry-hotels-learn.md new file mode 100644 index 00000000..1998b22c --- /dev/null +++ b/.changeset/angry-hotels-learn.md @@ -0,0 +1,5 @@ +--- +"@google/generative-ai": minor +--- + +Add a `cachedContentTokenCount` field to the `UsageMetadata` interface returned by `generateContent` responses. From 6e19788bea87cc27479e19f947941f044527001b Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Fri, 21 Jun 2024 17:44:12 -0400 Subject: [PATCH 3/3] cachedContentTokenCount is now optional --- common/api-review/generative-ai.api.md | 2 +- .../main/generative-ai.usagemetadata.cachedcontenttokencount.md | 2 +- docs/reference/main/generative-ai.usagemetadata.md | 2 +- packages/main/types/responses.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index b09fadf5..6124510f 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -638,7 +638,7 @@ export interface ToolConfig { // @public export interface UsageMetadata { - cachedContentTokenCount: number; + cachedContentTokenCount?: number; candidatesTokenCount: number; promptTokenCount: number; totalTokenCount: number; diff --git a/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md b/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md index 707ba1f6..138a48e5 100644 --- a/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md +++ b/docs/reference/main/generative-ai.usagemetadata.cachedcontenttokencount.md @@ -9,5 +9,5 @@ Total token count in the cached part of the prompt, i.e. in the cached content. **Signature:** ```typescript -cachedContentTokenCount: number; +cachedContentTokenCount?: number; ``` diff --git a/docs/reference/main/generative-ai.usagemetadata.md b/docs/reference/main/generative-ai.usagemetadata.md index 2905481d..99fdb364 100644 --- a/docs/reference/main/generative-ai.usagemetadata.md +++ b/docs/reference/main/generative-ai.usagemetadata.md @@ -16,7 +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. | +| [cachedContentTokenCount?](./generative-ai.usagemetadata.cachedcontenttokencount.md) | | number | _(Optional)_ 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). | diff --git a/packages/main/types/responses.ts b/packages/main/types/responses.ts index c7ee0c25..2acf2108 100644 --- a/packages/main/types/responses.ts +++ b/packages/main/types/responses.ts @@ -99,7 +99,7 @@ export interface UsageMetadata { /** 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; + cachedContentTokenCount?: number; } /**