Skip to content

Commit

Permalink
Merge pull request #26 from subquery/init-and-repl
Browse files Browse the repository at this point in the history
Fix init files, fix repl env vars, update submodule
  • Loading branch information
stwiname authored Nov 6, 2024
2 parents 658072b + c2cd2f9 commit b1e56de
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/ipfs_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 4 additions & 2 deletions src/subcommands/bundle_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ 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();
});

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",
Expand Down
7 changes: 6 additions & 1 deletion src/subcommands/httpCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export async function httpCli(
host: string,
stream = true,
apiKey = "",
): Promise<void> {
let messages: Message[] = [];

const client = new OpenAI({
apiKey, // Defaults to empty because were not using OpenAI to connect to
baseURL: `${host}/v1`,
});

Expand Down
25 changes: 6 additions & 19 deletions src/subcommands/init.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -99,23 +102,7 @@ export async function initProject(opts: Options): Promise<void> {
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);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
services:
const DOCKER_COMPOSE = `services:
subql-ai:
image: subquerynetwork/subql-ai-app:latest
ports:
Expand Down Expand Up @@ -27,3 +27,6 @@ services:
volumes:
open-webui:
`;

export default DOCKER_COMPOSE;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Logs
const GIT_IGNORE = `# Logs
logs
*.log
npm-debug.log*
Expand Down Expand Up @@ -127,4 +127,7 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*
`;

export default GIT_IGNORE;
24 changes: 13 additions & 11 deletions src/subcommands/init/README.md → src/subcommands/init/readme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SubQuery AI App Example
const README = `# SubQuery AI App Example
## Start
Expand All @@ -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
Expand All @@ -25,25 +25,27 @@ 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
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;
2 changes: 1 addition & 1 deletion subquery-delegator

0 comments on commit b1e56de

Please sign in to comment.