-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.ts
60 lines (48 loc) · 1.43 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// deno-lint-ignore-file no-explicit-any
import { initChat } from "./index.ts";
async function test(name: string, fn: any) {
console.log(name);
await fn();
console.log();
}
await test("Init chat", async () => {
await initChat("o3-mini");
});
await test("fetchFull", async () => {
const chat = await initChat("o3-mini");
const message = await chat.fetchFull("Who are you?");
console.log(message);
});
await test("fetchStream", async () => {
const chat = await initChat("o3-mini");
const stream = chat.fetchStream("Who are you?");
let text = "";
for await (const data of stream) {
text += data;
}
console.log(text);
});
await test("redo", async () => {
const chat = await initChat("o3-mini");
await chat.fetchFull("Hello");
let message = await chat.fetchFull(
"Recommend a famous place for me, please.",
);
console.log(message, chat.messages);
chat.redo();
message = await chat.fetchFull("Recommend a famous place for me, please.");
console.log(message, chat.messages);
});
await test("Chat", async () => {
const chat = await initChat("o3-mini");
let message = await chat.fetchFull("Hello");
console.log(message);
message = await chat.fetchFull(
"Your name is TypeScript. What's your name?",
);
console.log(message);
message = await chat.fetchFull("Assistant, give me a cup of coffee.");
console.log(message);
message = await chat.fetchFull("Yes, I need.");
console.log(message);
});