Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile and publish extension #79

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Package Extension

on:
push:
branches: [main]
workflow_dispatch:

jobs:
npm-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Install dependencies
run: npm install && npx tsc -p core && npm link ./core -w cli

- name: Package Extension
run: npm run --workspace extension

- name: Publish extension artifact
uses: actions/upload-artifact
with:
name: extension
path: extension/ailly-*.vsix
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"--profile-temp",
"--extensionDevelopmentPath=${workspaceFolder}/extension"
],
"outFiles": ["${workspaceFolder}/extension/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
"outFiles": ["${workspaceFolder}/extension/out/**/*.js"]
// "preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Ailly Extension Tests",
Expand Down
1 change: 0 additions & 1 deletion cli/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export async function loadFs(fs, args) {
const root = resolve(args.values.root ?? '.');
fs.cd(root);


const settings = await ailly.Ailly.makePipelineSettings({
root,
out: resolve(args.values.out ?? root),
Expand Down
1 change: 0 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as ailly from "@ailly/core";
import { makeArgs, help } from "./args.js";
import { loadFs, LOGGER } from "./fs.js";
import { version } from "./version.js";
import { promisify } from "node:util";

await main();

Expand Down
14 changes: 9 additions & 5 deletions core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const content = {
};

export const Ailly = aillyModule;
export const version = getVersion(import.meta.url);
export const version = getVersion(import.meta?.url ?? "file://" + __filename);

// TODO move this to jiffies
import { execSync } from "node:child_process";
Expand All @@ -27,10 +27,14 @@ import { normalize, join } from "node:path";
import { readFileSync } from "node:fs";

export function getVersion(root: /*ImportMeta.URL*/ string) {
const cwd = normalize(join(fileURLToPath(root), ".."));
const packageJson = join(cwd, "./package.json");
const pkg = JSON.parse(readFileSync(packageJson, { encoding: "utf8" }));
return pkg.version;
try {
const cwd = normalize(join(fileURLToPath(root), ".."));
const packageJson = join(cwd, "./package.json");
const pkg = JSON.parse(readFileSync(packageJson, { encoding: "utf8" }));
return pkg.version;
} catch (_) {
return "unknown";
}
}

export function getRevision(root: /* ImportMeta.URL */ string) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/actions/prompt_thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ async function generateOne(
messages: meta?.messages
?.map((m) => ({
role: m.role,
content: m.content.replaceAll("\n", " ").substring(0, 150) + "...",
content: m.content.replace(/\n/g, " ").substring(0, 150) + "...",
// tokens: m.tokens,
}))
// Skip the last `assistant` message
.filter((m, i, a) => !(m.role == "assistant" && i === a.length - 1))
.map(({ role, content }) => `${role}: ${content.replaceAll("\n", "\\n")}`)
.map(({ role, content }) => `${role}: ${content.replace(/\n/g, "\\n")}`)
.join("\n\t"),
});
const generated = await engine.generate(c, settings);
Expand Down
14 changes: 13 additions & 1 deletion core/src/engine/bedrock/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ export async function generate(
if (c.context.edit) {
const lang = c.context.edit.file.split(".").at(-1) ?? "";
fence = "```" + lang;
const { start, end } = c.context.edit as { start?: number; end?: number };
if (start != undefined) {
if (messages.at(-1)?.role === "user") {
messages.at(-1)!.content += [
"",
"You are replacing this section:",
"```",
c.meta?.text?.split("\n").slice(start, end),
"```",
].join("\n");
}
}
messages.push({ role: "assistant", content: fence });
stopSequences = ["```"];
}
Expand Down Expand Up @@ -176,7 +188,7 @@ export function getMessagesFolder(
(content.context.folder ?? [])
.map((c) => context[c])
.map<string>(
(c) => `<file name="${c.name}>\n${c.prompt ?? c.response ?? ""}</file>`
(c) => `<file name="${c.name}>\n${c.meta?.text ?? c.prompt + "\n" + c.response}</file>`
)
.join("\n") +
"\n</folder>";
Expand Down
1 change: 1 addition & 0 deletions core/src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Engine {
): Promise<{ debug: D; message: string }>;
vector(s: string, parameters: ContentMeta): Promise<number[]>;
view?(): Promise<View>;
models?(): string[];
}

export interface Message {
Expand Down
9 changes: 5 additions & 4 deletions core/src/engine/mistral/mistral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export async function generate(
}

let cwd = dirname(
import.meta.url
.replace(/^file:/, "")
.replace("ailly/core/dist", "ailly/core/src")
(import.meta?.url.replace(/^file:/, "") ?? __filename).replace(
"ailly/core/dist",
"ailly/core/src"
)
);
let command = join(cwd, normalize(".venv/bin/python3"));
let args = [join(cwd, "mistral.py"), prompt];
Expand All @@ -35,7 +36,7 @@ export async function generate(
child.on("disconnect", done);

const error = (cause: unknown) =>
reject(new Error("child_process had a problem", { cause }));
reject(new Error("child_process had a problem" /*, { cause }*/));
child.on("error", error);
});
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/engine/noop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getLogger } from "@davidsouther/jiffies/lib/esm/log.js";
import { Content } from "../content/content.js";
import { LOGGER as ROOT_LOGGER } from "../util.js";
import type { PipelineSettings } from "../ailly";
import type { Message } from "./index";
import type { PipelineSettings } from "../ailly.js";
import type { Message } from "./index.js";

const LOGGER = getLogger("@ailly/core:noop");

Expand Down
8 changes: 4 additions & 4 deletions core/src/engine/openai.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OpenAI, toFile } from "openai";
import { assertExists } from "@davidsouther/jiffies/lib/esm/assert.js";
import type { Content } from "../content/content";
import type { PipelineSettings } from "../ailly";
import type { Message, Summary } from "./index";
import type { Content } from "../content/content.js";
import type { PipelineSettings } from "../ailly.js";
import type { Message, Summary } from "./index.js";
import { LOGGER, isDefined } from "../util.js";
import { encode } from "../encoding.js";

Expand Down Expand Up @@ -85,7 +85,7 @@ async function callOpenAiWithRateLimit(
} catch (e: any) {
LOGGER.warn("Error calling openai", e.message);
if (retry == 0) {
throw new Error("Failed 3 times to call openai", { cause: e });
throw new Error("Failed 3 times to call openai" /*, { cause: e }*/);
}
if (e.error.code == "rate_limit_exceeded") {
await new Promise((resolve) => {
Expand Down
44 changes: 42 additions & 2 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "David Souther <[email protected]>",
"contributors": [],
"repository": "https://github.com/davidsouther/ailly",
"version": "0.0.1",
"version": "0.1.0",
"engines": {
"vscode": "^1.83.0"
},
Expand All @@ -22,6 +22,10 @@
{
"command": "ailly.generate",
"title": "Ailly: Generate"
},
{
"command": "ailly.edit",
"title": "Ailly: Edit"
}
],
"menus": {
Expand All @@ -36,6 +40,40 @@
{
"title": "Ailly",
"properties": {
"ailly.engine": {
"type": "string",
"default": "bedrock",
"enum": [
"bedrock",
"openai"
],
"description": "The Ailly engine to use when making LLM calls."
},
"ailly.model": {
"type": [
"string",
"null"
],
"default": "haiku",
"description": "The default model to use when making LLM calls."
},
"ailly.log-level": {
"type": "string",
"default": "info",
"enum": [
"debug",
"info",
"warn",
"error",
"silent"
],
"description": "The log level to record Ailly details."
},
"ailly.log-pretty": {
"type": "boolean",
"default": false,
"description": "JSON (false) or pretty print (true) logs."
},
"ailly.openai-api-key": {
"type": [
"string",
Expand All @@ -50,15 +88,17 @@
},
"scripts": {
"vscode:prepublish": "npm run esbuild-base -- --minify",
"esbuild-base": "esbuild ./src/extension.cts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
"esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"test-compile": "tsc -p ./",
"compile": "tsc -p ./",
"build": "esbuild",
"watch": "tsc -watch -p ./",
"pretest": "npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js",
"prepackage": "npm run vscode:prepublish",
"package": "vsce package"
},
"devDependencies": {
Expand Down
57 changes: 0 additions & 57 deletions extension/src/extension.cts

This file was deleted.

Loading