Skip to content

Commit

Permalink
add content cache to chat session
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksii-oleniuk committed Oct 2, 2024
1 parent 4807338 commit bef61c1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ docs/

# Ignore files generated automatically.
test/spec/sponge_log.xml

.idea/
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/functions/post_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions src/models/chat_session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Content[]> {
return Promise.resolve(this.historyInternal);
Expand All @@ -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
Expand Down Expand Up @@ -423,20 +425,21 @@ export class ChatSessionPreview {
): Promise<StreamGenerateContentResult> {
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,
Expand Down

0 comments on commit bef61c1

Please sign in to comment.