-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic deno code for using wiki
- Loading branch information
Showing
6 changed files
with
101 additions
and
2,602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DEEPSEEK_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{ | ||
"tasks": { | ||
"dev": "deno run --watch main.ts" | ||
"dev": "deno run --watch --allow-read --allow-net main.ts" | ||
}, | ||
"imports": { | ||
"@std/assert": "jsr:@std/assert@1", | ||
"@std/fs": "jsr:@std/fs@^1.0.5", | ||
"@std/path": "jsr:@std/path@^1.0.8" | ||
"@std/path": "jsr:@std/path@^1.0.8", | ||
"tiddlywiki": "npm:tiddlywiki@^5.3.6", | ||
"tw5-typed": "npm:tw5-typed@^0.5.14" | ||
}, | ||
"compilerOptions": { | ||
"types": ["npm:tw5-typed"] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { join } from "@std/path"; | ||
import "tw5-typed"; | ||
import { TiddlyWiki } from "tiddlywiki"; | ||
|
||
const wikiInstance = TiddlyWiki(); | ||
const wikiPath = join(Deno.cwd(), "wiki"); | ||
wikiInstance.boot.argv = [wikiPath, "--version"]; | ||
wikiInstance.boot.startup({}); | ||
|
||
export async function generateChatML(tidContent: string): Promise<string> { | ||
const dataPromptTiddlers = wikiInstance.wiki.filterTiddlers( | ||
`[!is[system]tag[Prompt]tag[Data]]`, | ||
) | ||
.map((title) => wikiInstance.wiki.getTiddler(title)) | ||
.filter((tiddler) => tiddler !== undefined) | ||
.filter((tiddler) => tiddler.fields.prompt !== undefined); | ||
|
||
const chatmlContents = await Promise.all(dataPromptTiddlers.map(async (tiddler) => { | ||
const prompt = tiddler.fields.prompt as string; | ||
const AIOutput = await callLLM(prompt, tidContent); | ||
const chatmlContent = wikiInstance.wiki.renderTiddler("text/plain", tiddler.fields.title, { | ||
variables: { | ||
prompt, | ||
AIOutput, | ||
} | ||
}) | ||
return chatmlContent; | ||
})) | ||
|
||
|
||
// 合并所有消息 | ||
return chatmlContents.join(""); | ||
} | ||
|
||
async function callLLM( | ||
systemPrompt: string, | ||
userPrompt: string, | ||
): Promise<string> { | ||
// 调用 LLM API 的逻辑,提取为可替换的函数 | ||
// ...implementation... | ||
return ""; // 返回助手的回复 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.