diff --git a/CHANGELOG.md b/CHANGELOG.md index ad1ebd7..c3a667d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- init command failing (#26) +- repl command requiring OPENAI_API_KEY env var (#26) ## [0.0.4] - 2024-11-06 ### Fixed diff --git a/src/index.ts b/src/index.ts index 0efc00a..412ec7c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -248,10 +248,15 @@ yargs(Deno.args) type: "boolean", default: true, }, + apiKey: { + description: "If the host requires an API use this to set it.", + type: "string", + default: "", + }, }, async (argv) => { const { httpCli } = await import("./subcommands/httpCli.ts"); - await httpCli(argv.host, argv.stream); + await httpCli(argv.host, argv.stream, argv.apiKey); }, ) .command( diff --git a/src/ipfs_test.ts b/src/ipfs_test.ts index fcdc698..55c7015 100644 --- a/src/ipfs_test.ts +++ b/src/ipfs_test.ts @@ -30,7 +30,7 @@ Deno.test("cat a file", async () => { // Deno.test("upload stream to ipfs", async () => { -// const readable = await tarDir('./subquery-delegator') +// const readable = await tarDir('./subquery-delegator/network-delegation-helper/db') // const [res] = await ipfs.addFileStream(readable); // expect(res.cid).toBe("Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD"); diff --git a/src/subcommands/bundle_test.ts b/src/subcommands/bundle_test.ts index fd21f70..69438b9 100644 --- a/src/subcommands/bundle_test.ts +++ b/src/subcommands/bundle_test.ts @@ -3,7 +3,9 @@ import { expect } from "jsr:@std/expect"; import { IPFSClient } from "../ipfs.ts"; Deno.test("Generates a bundle", async () => { - const code = await generateBundle("./subquery-delegator/manifest.ts"); + const code = await generateBundle( + "./subquery-delegator/network-delegation-helper/manifest.ts", + ); expect(code.length).toBeTruthy(); }); @@ -11,7 +13,7 @@ Deno.test("Generates a bundle", async () => { Deno.test("Publishing a project to ipfs", async () => { // WebWorkers don't work in tests, use the unsafe sandbox instead const cid = await publishProject( - "./subquery-delegator/manifest.ts", + "./subquery-delegator/network-delegation-helper/manifest.ts", new IPFSClient( Deno.env.get("IPFS_ENDPOINT") ?? "https://unauthipfs.subquery.network/ipfs/api/v0", diff --git a/src/subcommands/httpCli.ts b/src/subcommands/httpCli.ts index 520d9b1..7341b6e 100644 --- a/src/subcommands/httpCli.ts +++ b/src/subcommands/httpCli.ts @@ -5,10 +5,15 @@ import { getPrompt } from "../util.ts"; import OpenAI from "openai"; import process from "node:process"; -export async function httpCli(host: string, stream = true): Promise { +export async function httpCli( + host: string, + stream = true, + apiKey = "", +): Promise { let messages: Message[] = []; const client = new OpenAI({ + apiKey, // Defaults to empty because were not using OpenAI to connect to baseURL: `${host}/v1`, }); diff --git a/src/subcommands/init.ts b/src/subcommands/init.ts index fcc3868..19ab198 100644 --- a/src/subcommands/init.ts +++ b/src/subcommands/init.ts @@ -1,4 +1,7 @@ import { resolve } from "@std/path/resolve"; +import README from "./init/readme.ts"; +import GITIGNORE from "./init/gitignore.ts"; +import DOCKER_COMPOSE from "./init/docker-compose.ts"; type Options = { name: string; @@ -99,23 +102,7 @@ export async function initProject(opts: Options): Promise { manifestTemplate(opts.model), ); await Deno.writeTextFile(resolve(dir, "project.ts"), projectTemplate()); - - if (import.meta.dirname) { - await Deno.copyFile( - resolve(import.meta.dirname, "./init/README.md"), - resolve(dir, "README.md"), - ); - await Deno.copyFile( - resolve(import.meta.dirname, "./init/template.gitignore"), - resolve(dir, ".gitignore"), - ); - await Deno.copyFile( - resolve(import.meta.dirname, "./init/docker-compose.yml"), - resolve(dir, "docker-compose.yml"), - ); - } else { - console.warn( - `import.meta.dirname not defined unable to copy template files`, - ); - } + await Deno.writeTextFile(resolve(dir, "README.md"), README); + await Deno.writeTextFile(resolve(dir, ".gitignore"), GITIGNORE); + await Deno.writeTextFile(resolve(dir, "docker-compose.yml"), DOCKER_COMPOSE); } diff --git a/src/subcommands/init/docker-compose.yml b/src/subcommands/init/docker-compose.ts similarity index 90% rename from src/subcommands/init/docker-compose.yml rename to src/subcommands/init/docker-compose.ts index 50cbd10..572a560 100644 --- a/src/subcommands/init/docker-compose.yml +++ b/src/subcommands/init/docker-compose.ts @@ -1,4 +1,4 @@ -services: +const DOCKER_COMPOSE = `services: subql-ai: image: subquerynetwork/subql-ai-app:latest ports: @@ -27,3 +27,6 @@ services: volumes: open-webui: +`; + +export default DOCKER_COMPOSE; diff --git a/src/subcommands/init/template.gitignore b/src/subcommands/init/gitignore.ts similarity index 96% rename from src/subcommands/init/template.gitignore rename to src/subcommands/init/gitignore.ts index 6a7d6d8..3925280 100644 --- a/src/subcommands/init/template.gitignore +++ b/src/subcommands/init/gitignore.ts @@ -1,4 +1,4 @@ -# Logs +const GIT_IGNORE = `# Logs logs *.log npm-debug.log* @@ -127,4 +127,7 @@ dist .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* +`; + +export default GIT_IGNORE; diff --git a/src/subcommands/init/README.md b/src/subcommands/init/readme.ts similarity index 52% rename from src/subcommands/init/README.md rename to src/subcommands/init/readme.ts index 483515f..d3b981f 100644 --- a/src/subcommands/init/README.md +++ b/src/subcommands/init/readme.ts @@ -1,4 +1,4 @@ -# SubQuery AI App Example +const README = `# SubQuery AI App Example ## Start @@ -8,13 +8,13 @@ - [deno](https://deno.com/) - [Ollama](https://ollama.com) - subql-ai cli - - `deno install -g -f --allow-env --allow-sys --allow-net --allow-import --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options --no-prompt -n subql-ai jsr:@subql/ai-app-framework/cli` + \`deno install -g -f --allow-env --allow-sys --allow-net --allow-import --allow-read --allow-write --allow-ffi --allow-run --unstable-worker-options --no-prompt -n subql-ai jsr:@subql/ai-app-framework/cli\` ## Editing your app -- `manifest.ts` - This file defines key configuration options for your app. +- \`manifest.ts\` - This file defines key configuration options for your app. Note: This is converted to JSON when publishing. -- `project.ts` - This is where the code for your app lives. It registers any +- \`project.ts\` - This is where the code for your app lives. It registers any tools and your system prompt. ## Run your app @@ -25,20 +25,20 @@ you can run Ollama locally. ### CLI -To start your app: `subql-ai -p ./manifest.ts` +To start your app: \`subql-ai -p ./manifest.ts\` To chat with your app using a cli, in another terminal you can run -`subql-ai repl` +\`subql-ai repl\` ### Docker Compose -To run your project in docker there is a provided `docker-compose.yml` file. +To run your project in docker there is a provided \`docker-compose.yml\` file. This will start your app as well as a simple chat web UI. -To start everything: `docker compose up`. +To start everything: \`docker compose up\`. -To use the web UI, head to `http://localhost:8080` and create a new chat. From -the list of models select `subql-ai` and begin chatting. +To use the web UI, head to \`http://localhost:8080\` and create a new chat. From +the list of models select \`subql-ai\` and begin chatting. ## Publish your app @@ -46,4 +46,6 @@ Once your app is ready you can publish it to IPFS to distribute it. This will bundle up the code and any vector data and upload it to IPFS. Then the app can be run from IPFS -`subql-ai publish -p ./manifest.ts` +\`subql-ai publish -p ./manifest.ts\` +`; +export default README; diff --git a/subquery-delegator b/subquery-delegator index a334343..5c29993 160000 --- a/subquery-delegator +++ b/subquery-delegator @@ -1 +1 @@ -Subproject commit a3343435505f911fa4865da42e5544fdb1ede504 +Subproject commit 5c299931fbdf3bc14b70740725b9656099cb1ada