* Sends a chat message and receives a non-streaming * GenerateContentResult. * * Fields set in the optional SingleRequestOptions parameter will * take precedence over the RequestOptions values provided to * GoogleGenerativeAI.getGenerativeModel .
(request3, requestOptions = {})
| 79478 | /** |
| 79479 | * Sends a chat message and receives a non-streaming |
| 79480 | * {@link GenerateContentResult}. |
| 79481 | * |
| 79482 | * Fields set in the optional {@link SingleRequestOptions} parameter will |
| 79483 | * take precedence over the {@link RequestOptions} values provided to |
| 79484 | * {@link GoogleGenerativeAI.getGenerativeModel }. |
| 79485 | */ |
| 79486 | async sendMessage(request3, requestOptions = {}) { |
| 79487 | var _a5, _b2, _c2, _d2, _e2, _f; |
| 79488 | await this._sendPromise; |
| 79489 | const newContent = formatNewContent(request3); |
| 79490 | const generateContentRequest = { |
| 79491 | safetySettings: (_a5 = this.params) === null || _a5 === void 0 ? void 0 : _a5.safetySettings, |
| 79492 | generationConfig: (_b2 = this.params) === null || _b2 === void 0 ? void 0 : _b2.generationConfig, |
| 79493 | tools: (_c2 = this.params) === null || _c2 === void 0 ? void 0 : _c2.tools, |
| 79494 | toolConfig: (_d2 = this.params) === null || _d2 === void 0 ? void 0 : _d2.toolConfig, |
| 79495 | systemInstruction: (_e2 = this.params) === null || _e2 === void 0 ? void 0 : _e2.systemInstruction, |
| 79496 | cachedContent: (_f = this.params) === null || _f === void 0 ? void 0 : _f.cachedContent, |
| 79497 | contents: [...this._history, newContent] |
| 79498 | }; |
| 79499 | const chatSessionRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions); |
| 79500 | let finalResult; |
| 79501 | this._sendPromise = this._sendPromise.then(() => generateContent(this._apiKey, this.model, generateContentRequest, chatSessionRequestOptions)).then((result) => { |
| 79502 | var _a6; |
| 79503 | if (isValidResponse(result.response)) { |
| 79504 | this._history.push(newContent); |
| 79505 | const responseContent = Object.assign({ |
| 79506 | parts: [], |
| 79507 | // Response seems to come back without a role set. |
| 79508 | role: "model" |
| 79509 | }, (_a6 = result.response.candidates) === null || _a6 === void 0 ? void 0 : _a6[0].content); |
| 79510 | this._history.push(responseContent); |
| 79511 | } else { |
| 79512 | const blockErrorMessage = formatBlockErrorMessage(result.response); |
| 79513 | if (blockErrorMessage) { |
| 79514 | console.warn(`sendMessage() was unsuccessful. ${blockErrorMessage}. Inspect response object for details.`); |
| 79515 | } |
| 79516 | } |
| 79517 | finalResult = result; |
| 79518 | }).catch((e3) => { |
| 79519 | this._sendPromise = Promise.resolve(); |
| 79520 | throw e3; |
| 79521 | }); |
nothing calls this directly
no test coverage detected