Skip to content

Commit

Permalink
Start http service earlier and add /ready http route
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Oct 10, 2024
1 parent b49f843 commit 523f9f4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
29 changes: 16 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
services:
subql-ai:
image: subquerynetwork/subql-ai-app
# build:
# context: .
# dockerfile: ./Dockerfile
# image: subquerynetwork/subql-ai-app
build:
context: .
dockerfile: ./Dockerfile
ports:
- 7827:7827
restart: unless-stopped
Expand All @@ -14,24 +14,27 @@ services:
# - -p=/app/index.ts # TODO this doesn't work because dependencies are not copied
- -p=ipfs://QmNaNBhXJoFpRJeNQcnTH8Yh6Rf4pzJy6VSnfnQSZHysdZ
- -h=http://host.docker.internal:11434
# healthcheck:
# test: ["CMD", "curl", "-f", "http://subql-ai:7827/health"]
# interval: 3s
# timeout: 5s
# retries: 10
healthcheck:
test: ["CMD", "curl", "-f", "http://subql-ai:7827/ready"]
interval: 3s
timeout: 5s
retries: 10

# A simple chat UI
ui:
image: ghcr.io/open-webui/open-webui:main
ports:
- 8080:8080
restart: always
depends_on:
"subql-ai":
condition: service_healthy
environment:
- 'OPENAI_API_BASE_URLS=http://subql-ai:7827/v1'
- 'OPENAI_API_KEYS=foobar'
- 'WEBUI_AUTH=false'
- "OPENAI_API_BASE_URLS=http://subql-ai:7827/v1"
- "OPENAI_API_KEYS=foobar"
- "WEBUI_AUTH=false"
volumes:
- open-webui:/app/backend/data
- open-webui:/app/backend/data

volumes:
open-webui:
8 changes: 4 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function runApp(config: {
);
const sandbox = await getDefaultSandbox(resolve(projectPath));

const ctx = await makeContext(
const pendingCtx = makeContext(
sandbox,
model,
(dbPath) =>
Expand All @@ -44,7 +44,7 @@ export async function runApp(config: {
),
);

const runnerHost = new RunnerHost(() => {
const runnerHost = new RunnerHost(async () => {
const chatStorage = new MemoryChatStorage();

chatStorage.append([{ role: "system", content: sandbox.systemPrompt }]);
Expand All @@ -53,7 +53,7 @@ export async function runApp(config: {
sandbox,
chatStorage,
model,
ctx,
await pendingCtx,
);
});

Expand All @@ -66,7 +66,7 @@ export async function runApp(config: {
break;
case "http":
default:
http(runnerHost, config.port);
http(runnerHost, config.port, pendingCtx);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ export type ChatChunkResponse = Static<typeof ChatChunkResponse>;
export function http(
runnerHost: RunnerHost,
port: number,
onReady?: Promise<unknown>,
): Deno.HttpServer<Deno.NetAddr> {
const app = new Hono();

// The ready status should change once the project is fully loaded, including the vector DB
let ready = false;
onReady?.then(() => ready = true);

app.get("/health", (c) => {
return c.text("ok");
});

app.get("/ready", (c) => {
return c.text(ready.toString());
});

app.get("/v1/models", (c) => {
return c.json({
object: "list",
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox/webWorker/webWorkerSandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class WebWorkerSandbox implements ISandbox {

public static async create(path: string): Promise<WebWorkerSandbox> {
const w = new Worker(
import.meta.resolve("./webWorker.ts" /*path*/),
import.meta.resolve("./webWorker.ts"),
{
type: "module",
deno: {
Expand Down

0 comments on commit 523f9f4

Please sign in to comment.