Skip to content

Commit

Permalink
fix: setDb: don't use forEach
Browse files Browse the repository at this point in the history
fix: futago_test: close database in test
  • Loading branch information
yukimemi committed Mar 2, 2024
1 parent 22f499f commit c8ccaf1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions denops/futago/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// =============================================================================
// File : db.ts
// Author : yukimemi
// Last Change : 2024/03/02 14:31:30.
// Last Change : 2024/03/02 15:55:44.
// =============================================================================

import { z } from "https://deno.land/x/zod@v3.22.4/mod.ts";
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function setDb(db: Deno.Kv, key: string, record: Record): Promise<v
humanPrompt: record.humanPrompt,
aiPrompt: record.aiPrompt,
});
record.history.forEach(async (inputContent, index) => {
for (const [index, inputContent] of record.history.entries()) {
await db.set([key, "history", index], inputContent);
});
}
}
2 changes: 1 addition & 1 deletion denops/futago/futago.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// =============================================================================
// File : futago.ts
// Author : yukimemi
// Last Change : 2024/02/04 00:00:34.
// Last Change : 2024/03/02 15:55:51.
// =============================================================================

import * as datetime from "https://deno.land/std@0.217.0/datetime/mod.ts";
Expand Down
33 changes: 18 additions & 15 deletions denops/futago/futago_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// =============================================================================
// File : futago_test.ts
// Author : yukimemi
// Last Change : 2024/01/28 01:28:20.
// Last Change : 2024/03/02 14:53:45.
// =============================================================================

import { Futago } from "./futago.ts";
Expand All @@ -11,20 +11,23 @@ Deno.test({
name: "Test sendMessageStream()",
fn: async () => {
const db = await Deno.openKv();
const futago = new Futago(
0,
"gemini-pro",
db,
"",
);
futago.startChat();
const result = futago.sendMessageStream("こんにちは!君の名は?");
let response = "";
for await (const chunk of result) {
console.log(chunk);
response += chunk;
try {
const futago = new Futago(
0,
"gemini-pro",
db,
"",
);
futago.startChat();
const result = futago.sendMessageStream("こんにちは!君の名は?");
let response = "";
for await (const chunk of result) {
console.log(chunk);
response += chunk;
}
assertStringIncludes(response, "私は");
} finally {
db.close();
}
assertStringIncludes(response, "私は");
db.close();
},
});

0 comments on commit c8ccaf1

Please sign in to comment.