(
contents: Content[],
generationConfig: GenerateContentConfig,
abortSignal: AbortSignal,
model?: string,
)
| 669 | } |
| 670 | |
| 671 | async generateContent( |
| 672 | contents: Content[], |
| 673 | generationConfig: GenerateContentConfig, |
| 674 | abortSignal: AbortSignal, |
| 675 | model?: string, |
| 676 | ): Promise<GenerateContentResponse> { |
| 677 | const modelToUse = model ?? this.config.getModel(); |
| 678 | const configToUse: GenerateContentConfig = { |
| 679 | ...this.generateContentConfig, |
| 680 | ...generationConfig, |
| 681 | }; |
| 682 | |
| 683 | try { |
| 684 | const userMemory = this.config.getUserMemory(); |
| 685 | const systemInstruction = getCoreSystemPrompt(userMemory); |
| 686 | |
| 687 | const requestConfig: GenerateContentConfig = { |
| 688 | abortSignal, |
| 689 | ...configToUse, |
| 690 | systemInstruction, |
| 691 | }; |
| 692 | |
| 693 | const apiCall = () => |
| 694 | this.getContentGenerator().generateContent( |
| 695 | { |
| 696 | model: modelToUse, |
| 697 | config: requestConfig, |
| 698 | contents, |
| 699 | }, |
| 700 | this.lastPromptId, |
| 701 | ); |
| 702 | |
| 703 | const result = await retryWithBackoff(apiCall, { |
| 704 | onPersistent429: async (authType?: string, error?: unknown) => |
| 705 | await this.handleFlashFallback(authType, error), |
| 706 | authType: this.config.getContentGeneratorConfig()?.authType, |
| 707 | }); |
| 708 | return result; |
| 709 | } catch (error: unknown) { |
| 710 | if (abortSignal.aborted) { |
| 711 | throw error; |
| 712 | } |
| 713 | |
| 714 | await reportError( |
| 715 | error, |
| 716 | `Error generating content via API with model ${modelToUse}.`, |
| 717 | { |
| 718 | requestContents: contents, |
| 719 | requestConfig: configToUse, |
| 720 | }, |
| 721 | 'generateContent-api', |
| 722 | ); |
| 723 | throw new Error( |
| 724 | `Failed to generate content with model ${modelToUse}: ${getErrorMessage(error)}`, |
| 725 | ); |
| 726 | } |
| 727 | } |
| 728 |
nothing calls this directly
no test coverage detected