Skip to content

Commit 3f62f8a

Browse files
committed
Implement thoughtSummary() method, add docs, changeset
1 parent e8df63d commit 3f62f8a

15 files changed

+191
-84
lines changed

.changeset/brave-llamas-impress.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/ai': minor
3+
'firebase': minor
4+
---
5+
6+
Add `thoughtSummary()` convenience method to `EnhancedGenerateContentResponse`.

common/api-review/ai.api.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,9 @@ export { Date_2 as Date }
204204

205205
// @public
206206
export interface EnhancedGenerateContentResponse extends GenerateContentResponse {
207-
// (undocumented)
208207
functionCalls: () => FunctionCall[] | undefined;
209208
inlineDataParts: () => InlineDataPart[] | undefined;
210209
text: () => string;
211-
// (undocumented)
212210
thoughtSummary: () => string | undefined;
213211
}
214212

@@ -244,8 +242,6 @@ export interface FileDataPart {
244242
text?: never;
245243
// (undocumented)
246244
thought?: boolean;
247-
// (undocumented)
248-
thoughtSignature?: string;
249245
}
250246

251247
// @public
@@ -302,8 +298,6 @@ export interface FunctionCallPart {
302298
text?: never;
303299
// (undocumented)
304300
thought?: boolean;
305-
// (undocumented)
306-
thoughtSignature?: string;
307301
}
308302

309303
// @public
@@ -338,8 +332,6 @@ export interface FunctionResponsePart {
338332
text?: never;
339333
// (undocumented)
340334
thought?: boolean;
341-
// (undocumented)
342-
thoughtSignature?: string;
343335
}
344336

345337
// @public
@@ -707,8 +699,6 @@ export interface InlineDataPart {
707699
text?: never;
708700
// (undocumented)
709701
thought?: boolean;
710-
// (undocumented)
711-
thoughtSignature?: string;
712702
videoMetadata?: VideoMetadata;
713703
}
714704

@@ -977,8 +967,6 @@ export interface TextPart {
977967
text: string;
978968
// (undocumented)
979969
thought?: boolean;
980-
// (undocumented)
981-
thoughtSignature?: string;
982970
}
983971

984972
// @public

docs-devsite/ai.enhancedgeneratecontentresponse.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ export interface EnhancedGenerateContentResponse extends GenerateContentResponse
2323
2424
| Property | Type | Description |
2525
| --- | --- | --- |
26-
| [functionCalls](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsefunctioncalls) | () =&gt; [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->\[\] \| undefined | |
26+
| [functionCalls](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsefunctioncalls) | () =&gt; [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->\[\] \| undefined | Aggregates and returns all [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->s from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->'s first candidate. |
2727
| [inlineDataParts](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponseinlinedataparts) | () =&gt; [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface)<!-- -->\[\] \| undefined | Aggregates and returns all [InlineDataPart](./ai.inlinedatapart.md#inlinedatapart_interface)<!-- -->s from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->'s first candidate. |
2828
| [text](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsetext) | () =&gt; string | Returns the text string from the response, if available. Throws if the prompt or candidate was blocked. |
29+
| [thoughtSummary](./ai.enhancedgeneratecontentresponse.md#enhancedgeneratecontentresponsethoughtsummary) | () =&gt; string \| undefined | Aggregates and returns all [TextPart](./ai.textpart.md#textpart_interface)<!-- -->s with their <code>thought</code> property set to <code>true</code> from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->'s first candidate. |
2930
3031
## EnhancedGenerateContentResponse.functionCalls
3132
33+
Aggregates and returns all [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->s from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->'s first candidate.
34+
3235
<b>Signature:</b>
3336
3437
```typescript
@@ -54,3 +57,17 @@ Returns the text string from the response, if available. Throws if the prompt or
5457
```typescript
5558
text: () => string;
5659
```
60+
61+
## EnhancedGenerateContentResponse.thoughtSummary
62+
63+
Aggregates and returns all [TextPart](./ai.textpart.md#textpart_interface)<!-- -->s with their `thought` property set to `true` from the [GenerateContentResponse](./ai.generatecontentresponse.md#generatecontentresponse_interface)<!-- -->'s first candidate.
64+
65+
Thought summaries provide a brief overview of the model's internal thinking process, offering insight into how it arrived at the final answer. This can be useful for debugging, understanding the model's reasoning, and verifying its accuracy.
66+
67+
Thoughts will only be included if [ThinkingConfig.includeThoughts](./ai.thinkingconfig.md#thinkingconfigincludethoughts) is set to `true`<!-- -->.
68+
69+
<b>Signature:</b>
70+
71+
```typescript
72+
thoughtSummary: () => string | undefined;
73+
```

docs-devsite/ai.filedatapart.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface FileDataPart
2727
| [functionResponse](./ai.filedatapart.md#filedatapartfunctionresponse) | never | |
2828
| [inlineData](./ai.filedatapart.md#filedatapartinlinedata) | never | |
2929
| [text](./ai.filedatapart.md#filedataparttext) | never | |
30+
| [thought](./ai.filedatapart.md#filedatapartthought) | boolean | |
3031

3132
## FileDataPart.fileData
3233

@@ -67,3 +68,11 @@ inlineData?: never;
6768
```typescript
6869
text?: never;
6970
```
71+
72+
## FileDataPart.thought
73+
74+
<b>Signature:</b>
75+
76+
```typescript
77+
thought?: boolean;
78+
```

docs-devsite/ai.functioncallpart.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface FunctionCallPart
2626
| [functionResponse](./ai.functioncallpart.md#functioncallpartfunctionresponse) | never | |
2727
| [inlineData](./ai.functioncallpart.md#functioncallpartinlinedata) | never | |
2828
| [text](./ai.functioncallpart.md#functioncallparttext) | never | |
29+
| [thought](./ai.functioncallpart.md#functioncallpartthought) | boolean | |
2930

3031
## FunctionCallPart.functionCall
3132

@@ -58,3 +59,11 @@ inlineData?: never;
5859
```typescript
5960
text?: never;
6061
```
62+
63+
## FunctionCallPart.thought
64+
65+
<b>Signature:</b>
66+
67+
```typescript
68+
thought?: boolean;
69+
```

docs-devsite/ai.functionresponsepart.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface FunctionResponsePart
2626
| [functionResponse](./ai.functionresponsepart.md#functionresponsepartfunctionresponse) | [FunctionResponse](./ai.functionresponse.md#functionresponse_interface) | |
2727
| [inlineData](./ai.functionresponsepart.md#functionresponsepartinlinedata) | never | |
2828
| [text](./ai.functionresponsepart.md#functionresponseparttext) | never | |
29+
| [thought](./ai.functionresponsepart.md#functionresponsepartthought) | boolean | |
2930

3031
## FunctionResponsePart.functionCall
3132

@@ -58,3 +59,11 @@ inlineData?: never;
5859
```typescript
5960
text?: never;
6061
```
62+
63+
## FunctionResponsePart.thought
64+
65+
<b>Signature:</b>
66+
67+
```typescript
68+
thought?: boolean;
69+
```

docs-devsite/ai.inlinedatapart.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface InlineDataPart
2626
| [functionResponse](./ai.inlinedatapart.md#inlinedatapartfunctionresponse) | never | |
2727
| [inlineData](./ai.inlinedatapart.md#inlinedatapartinlinedata) | [GenerativeContentBlob](./ai.generativecontentblob.md#generativecontentblob_interface) | |
2828
| [text](./ai.inlinedatapart.md#inlinedataparttext) | never | |
29+
| [thought](./ai.inlinedatapart.md#inlinedatapartthought) | boolean | |
2930
| [videoMetadata](./ai.inlinedatapart.md#inlinedatapartvideometadata) | [VideoMetadata](./ai.videometadata.md#videometadata_interface) | Applicable if <code>inlineData</code> is a video. |
3031

3132
## InlineDataPart.functionCall
@@ -60,6 +61,14 @@ inlineData: GenerativeContentBlob;
6061
text?: never;
6162
```
6263

64+
## InlineDataPart.thought
65+
66+
<b>Signature:</b>
67+
68+
```typescript
69+
thought?: boolean;
70+
```
71+
6372
## InlineDataPart.videoMetadata
6473

6574
Applicable if `inlineData` is a video.

docs-devsite/ai.textpart.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface TextPart
2626
| [functionResponse](./ai.textpart.md#textpartfunctionresponse) | never | |
2727
| [inlineData](./ai.textpart.md#textpartinlinedata) | never | |
2828
| [text](./ai.textpart.md#textparttext) | string | |
29+
| [thought](./ai.textpart.md#textpartthought) | boolean | |
2930

3031
## TextPart.functionCall
3132

@@ -58,3 +59,11 @@ inlineData?: never;
5859
```typescript
5960
text: string;
6061
```
62+
63+
## TextPart.thought
64+
65+
<b>Signature:</b>
66+
67+
```typescript
68+
thought?: boolean;
69+
```

docs-devsite/ai.thinkingconfig.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@ export interface ThinkingConfig
2424

2525
| Property | Type | Description |
2626
| --- | --- | --- |
27+
| [includeThoughts](./ai.thinkingconfig.md#thinkingconfigincludethoughts) | boolean | Whether to include "thought summaries" in the model's response. |
2728
| [thinkingBudget](./ai.thinkingconfig.md#thinkingconfigthinkingbudget) | number | The thinking budget, in tokens.<!-- -->This parameter sets an upper limit on the number of tokens the model can use for its internal "thinking" process. A higher budget may result in higher quality responses for complex tasks but can also increase latency and cost.<!-- -->If you don't specify a budget, the model will determine the appropriate amount of thinking based on the complexity of the prompt.<!-- -->An error will be thrown if you set a thinking budget for a model that does not support this feature or if the specified budget is not within the model's supported range. |
2829

30+
## ThinkingConfig.includeThoughts
31+
32+
Whether to include "thought summaries" in the model's response.
33+
34+
Thought summaries provide a brief overview of the model's internal thinking process, offering insight into how it arrived at the final answer. This can be useful for debugging, understanding the model's reasoning, and verifying its accuracy.
35+
36+
<b>Signature:</b>
37+
38+
```typescript
39+
includeThoughts?: boolean;
40+
```
41+
2942
## ThinkingConfig.thinkingBudget
3043

3144
The thinking budget, in tokens.

packages/ai/src/methods/chat-session-helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export function validateChatHistory(history: Content[]): void {
8080
text: 0,
8181
inlineData: 0,
8282
functionCall: 0,
83-
functionResponse: 0
83+
functionResponse: 0,
84+
thought: 0
8485
};
8586

8687
for (const part of parts) {

0 commit comments

Comments
 (0)