diff --git a/README.md b/README.md index 0ad269a..30850f1 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ $ npm install -g @offline-ai/cli $ ai COMMAND running command... $ ai (--version) -@offline-ai/cli/0.4.2 linux-x64 node-v20.14.0 +@offline-ai/cli/0.4.3 linux-x64 node-v20.14.0 $ ai --help [COMMAND] USAGE $ ai COMMAND @@ -396,7 +396,7 @@ EXAMPLES $ ai agent publish ``` -_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.4.2/src/commands/agent/index.ts)_ +_See code: [src/commands/agent/index.ts](https://github.com/offline-ai/cli/blob/v0.4.3/src/commands/agent/index.ts)_ ## `ai autocomplete [SHELL]` diff --git a/TODO b/TODO index 913aca1..096c2fd 100644 --- a/TODO +++ b/TODO @@ -41,3 +41,4 @@ bugs: ✔ `$exec`应该传递`llmStream`事件以便于显示外部脚本过程的流进度. @done(24-08-25 06:01) ✔ can not work on Windows @done(24-08-25 06:01) ☐ ai brain can not list downloaded + ☐ ai brain refresh can not work if no maxCount option diff --git a/lib/file.ai.yaml b/lib/file.ai.yaml index eb49bc4..ea71314 100644 --- a/lib/file.ai.yaml +++ b/lib/file.ai.yaml @@ -1,10 +1,10 @@ --- -version: 0.2.2 +version: 0.3.0 type: lib description: |- the simple text file loader. You can use environment variables in file path, eg, "$HOME/documents/document.md". - It can be used in prompt. eg, `user: think about the following file content: @file(document.md)` + It can be used in prompt. eg, `user: "think about the following file content: @file(document.md)"` tag: - file - loader @@ -22,10 +22,17 @@ output: # the file content const fs = await import('fs'); const path = await import('path'); let filepath = this.content || this[0] - const filename = path.basename(filepath); - filepath = expandPath(filepath) - const content = fs.readFileSync(filepath, 'utf8'); - if (this.onlyContent) return content; - return `filename: ${filename}\nfile content:\n${content}` + if (!filepath) {throw new Error('No file path provided.')} + if (filepath.startsWith('https://') || filepath.startsWith('http://')) { + const content = await fetch(filepath).then(res => res.text()); + if (this.onlyContent) return content; + return `url: ${filepath}\nfile content:\n${content}` + } else { + const filename = path.basename(filepath); + filepath = expandPath(filepath) + const content = fs.readFileSync(filepath, 'utf8'); + if (this.onlyContent) return content; + return `filename: ${filename}\nfile content:\n${content}` + } } $loadFile