* Sends a chat message and receives the response as a * GenerateContentStreamResult containing an iterable stream * and a response promise. * * Fields set in the optional SingleRequestOptions parameter will * take precedence over the RequestOptions values provi
(request3, requestOptions = {})
| 79526 | * Sends a chat message and receives the response as a |
| 79527 | * {@link GenerateContentStreamResult} containing an iterable stream |
| 79528 | * and a response promise. |
| 79529 | * |
| 79530 | * Fields set in the optional {@link SingleRequestOptions} parameter will |
| 79531 | * take precedence over the {@link RequestOptions} values provided to |
| 79532 | * {@link GoogleGenerativeAI.getGenerativeModel }. |
| 79533 | */ |
| 79534 | async sendMessageStream(request3, requestOptions = {}) { |
| 79535 | var _a5, _b2, _c2, _d2, _e2, _f; |
| 79536 | await this._sendPromise; |
| 79537 | const newContent = formatNewContent(request3); |
| 79538 | const generateContentRequest = { |
| 79539 | safetySettings: (_a5 = this.params) === null || _a5 === void 0 ? void 0 : _a5.safetySettings, |
| 79540 | generationConfig: (_b2 = this.params) === null || _b2 === void 0 ? void 0 : _b2.generationConfig, |
| 79541 | tools: (_c2 = this.params) === null || _c2 === void 0 ? void 0 : _c2.tools, |
| 79542 | toolConfig: (_d2 = this.params) === null || _d2 === void 0 ? void 0 : _d2.toolConfig, |
| 79543 | systemInstruction: (_e2 = this.params) === null || _e2 === void 0 ? void 0 : _e2.systemInstruction, |
| 79544 | cachedContent: (_f = this.params) === null || _f === void 0 ? void 0 : _f.cachedContent, |
| 79545 | contents: [...this._history, newContent] |
| 79546 | }; |
| 79547 | const chatSessionRequestOptions = Object.assign(Object.assign({}, this._requestOptions), requestOptions); |
| 79548 | const streamPromise = generateContentStream(this._apiKey, this.model, generateContentRequest, chatSessionRequestOptions); |
| 79549 | this._sendPromise = this._sendPromise.then(() => streamPromise).catch((_ignored) => { |
| 79550 | throw new Error(SILENT_ERROR); |
| 79551 | }).then((streamResult) => streamResult.response).then((response) => { |
| 79552 | if (isValidResponse(response)) { |
| 79553 | this._history.push(newContent); |
| 79554 | const responseContent = Object.assign({}, response.candidates[0].content); |
| 79555 | if (!responseContent.role) { |
| 79556 | responseContent.role = "model"; |
| 79557 | } |
| 79558 | this._history.push(responseContent); |
| 79559 | } else { |
| 79560 | const blockErrorMessage = formatBlockErrorMessage(response); |
| 79561 | if (blockErrorMessage) { |
| 79562 | console.warn(`sendMessageStream() was unsuccessful. ${blockErrorMessage}. Inspect response object for details.`); |
| 79563 | } |
| 79564 | } |
| 79565 | }).catch((e3) => { |
| 79566 | if (e3.message !== SILENT_ERROR) { |
| 79567 | console.error(e3); |
| 79568 | } |
nothing calls this directly
no test coverage detected