From bef61c1621244e0c4f1dea2450bcad0a57ad6f12 Mon Sep 17 00:00:00 2001 From: Oleksii Oleniuk Date: Tue, 1 Oct 2024 19:58:41 +0300 Subject: [PATCH 1/2] add content cache to chat session --- .gitignore | 2 ++ package.json | 1 - src/functions/post_request.ts | 2 ++ src/models/chat_session.ts | 7 +++++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f3a3bf52..7a492181 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ docs/ # Ignore files generated automatically. test/spec/sponge_log.xml + +.idea/ diff --git a/package.json b/package.json index af4480e3..3d4f9d88 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "lint": "gts lint", "clean-js-files": "find . -type f -name \"*.js\" -exec rm -f {} +", "clean-js-map-files": "find . -type f -name \"*.js.map\" -exec rm -f {} +", - "postpack": "if [ \"${CLEAN}\" ]; then npm run clean-after-pack; fi", "cover": "npm run cover:unit && npm run cover:integration && npm run cover:report", "cover:unit": "nyc npm run test", "cover:integration": "nyc --no-clean npm run test:system", diff --git a/src/functions/post_request.ts b/src/functions/post_request.ts index aabf3e32..6c25c563 100644 --- a/src/functions/post_request.ts +++ b/src/functions/post_request.ts @@ -73,6 +73,8 @@ export async function postRequest({ necessaryHeaders, requestOptions ); + console.log('vertexEndpoint', vertexEndpoint); + console.log('json.stringify vertexai data', JSON.stringify(data)); return fetch(vertexEndpoint, { ...getFetchOptions(requestOptions), method: 'POST', diff --git a/src/models/chat_session.ts b/src/models/chat_session.ts index 0c015024..ceec37db 100644 --- a/src/models/chat_session.ts +++ b/src/models/chat_session.ts @@ -271,6 +271,7 @@ export class ChatSessionPreview { private readonly toolConfig?: ToolConfig; private readonly apiEndpoint?: string; private readonly systemInstruction?: Content; + private readonly cachedContent?: string; async getHistory(): Promise { return Promise.resolve(this.historyInternal); @@ -295,6 +296,7 @@ export class ChatSessionPreview { this.toolConfig = request.toolConfig; this.apiEndpoint = request.apiEndpoint; this.requestOptions = requestOptions ?? {}; + this.cachedContent = request.cachedContent; if (request.systemInstruction) { this.systemInstruction = formulateSystemInstructionIntoContent( request.systemInstruction @@ -423,20 +425,21 @@ export class ChatSessionPreview { ): Promise { const newContent: Content[] = formulateNewContentFromSendMessageRequest(request); - const generateContentrequest: GenerateContentRequest = { + const generateContentRequest: GenerateContentRequest = { contents: this.historyInternal.concat(newContent), safetySettings: this.safetySettings, generationConfig: this.generationConfig, tools: this.tools, toolConfig: this.toolConfig, systemInstruction: this.systemInstruction, + cachedContent: this.cachedContent, }; const streamGenerateContentResultPromise = generateContentStream( this.location, this.resourcePath, this.fetchToken(), - generateContentrequest, + generateContentRequest, this.apiEndpoint, this.generationConfig, this.safetySettings, From 0313b2e8b9b7b56b41da4ef7599fcee1f995e2b7 Mon Sep 17 00:00:00 2001 From: Oleksii Oleniuk Date: Wed, 2 Oct 2024 11:22:05 +0300 Subject: [PATCH 2/2] remove logs, add gitignore --- .gitignore | 1 + package.json | 1 + src/functions/post_request.ts | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7a492181..9b49304f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ docs/ # Ignore files generated automatically. test/spec/sponge_log.xml +# Ignore JetBrains IDE files .idea/ diff --git a/package.json b/package.json index 3d4f9d88..af4480e3 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "lint": "gts lint", "clean-js-files": "find . -type f -name \"*.js\" -exec rm -f {} +", "clean-js-map-files": "find . -type f -name \"*.js.map\" -exec rm -f {} +", + "postpack": "if [ \"${CLEAN}\" ]; then npm run clean-after-pack; fi", "cover": "npm run cover:unit && npm run cover:integration && npm run cover:report", "cover:unit": "nyc npm run test", "cover:integration": "nyc --no-clean npm run test:system", diff --git a/src/functions/post_request.ts b/src/functions/post_request.ts index 6c25c563..aabf3e32 100644 --- a/src/functions/post_request.ts +++ b/src/functions/post_request.ts @@ -73,8 +73,6 @@ export async function postRequest({ necessaryHeaders, requestOptions ); - console.log('vertexEndpoint', vertexEndpoint); - console.log('json.stringify vertexai data', JSON.stringify(data)); return fetch(vertexEndpoint, { ...getFetchOptions(requestOptions), method: 'POST',