Skip to content

Commit

Permalink
docs: document symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
mumu-lhl committed Aug 1, 2024
1 parent bc22a11 commit 9fdedae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
17 changes: 14 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"name": "@mumulhl/duckduckgo-ai-chat",
"version": "2.0.1",
"exports": "./mod.ts"
"exports": "./mod.ts",
"tasks": {
"dev": "deno run --watch main.ts"
"test": "deno run -A test.ts",
},
"imports": {
"@lukeed/fetch-event-stream": "jsr:@lukeed/fetch-event-stream@^0.1.5",
"@std/assert": "jsr:@std/assert@1"
"@std/assert": "jsr:@std/assert@1",
},
"publish": {
"include": [
"LICENSE",
"README.md",
"README_CN.md",
"*.ts",
],
"exclude": [
"test.ts",
],
}
}
28 changes: 27 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class Chat {
this.messages = [];
}

async fetch(content: string) {
/**
* Fetching the original message.
*
* @param content The content to send.
* @returns The original message.
*/
async fetch(content: string): Promise<Response> {
this.messages.push({ content, role: "user" });
const payload: ChatPayload = {
model: this.model,
Expand All @@ -52,6 +58,12 @@ class Chat {
}
}

/**
* Fetching the full message.
*
* @param content The content to send.
* @returns The full message.
*/
async fetchFull(content: string): Promise<string> {
const message = await this.fetch(content);
let text = "";
Expand All @@ -76,6 +88,12 @@ class Chat {
return text;
}

/**
* Fetching the streaming message.
*
* @param content The content to send.
* @returns The streaming message.
*/
async *fetchStream(content: string): AsyncGenerator<string, void> {
const message = await this.fetch(content);
const stream = events(message);
Expand All @@ -100,13 +118,21 @@ class Chat {
this.messages.push({ content: text, role: "assistant" });
}

/**
* Redo.
*/
redo() {
this.newVqd = this.oldVqd;
this.messages.pop();
this.messages.pop();
}
}

/** Init chat.
*
* @param model The model used by chat.
* @returns A Chat instance.
*/
async function initChat(model: Model): Promise<Chat> {
const status = await fetch(STATUS_URL, { headers: STATUS_HEADERS });
const vqd = status.headers.get("x-vqd-4");
Expand Down
1 change: 0 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ async function test(name: string, fn: any) {
console.log(name);
await fn();
console.log();
console.log();
}

await test("Init chat", async () => {
Expand Down

0 comments on commit 9fdedae

Please sign in to comment.