Skip to content

Commit

Permalink
feat: restructure directories
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
  • Loading branch information
akihikokuroda committed Nov 7, 2024
1 parent cf85dc2 commit 13891f0
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 26 deletions.
6 changes: 3 additions & 3 deletions examples/agents/manyToolsAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia";
// import { ArXivTool } from "bee-agent-framework/tools/arxiv";

// contrib tools
// import { HelloWorldTool } from "@/tools/helloWorld.js";
import { OpenLibraryTool } from "bee-community-tools/tools/openLibrary";
import { ImageDescriptionTool } from "bee-community-tools/tools/imageDescription";
// import { HelloWorldTool } from "./tools/helloWorld.js";
import { OpenLibraryTool } from "bee-community-tools/tools/openLibrary/openLibrary";
import { ImageDescriptionTool } from "bee-community-tools/tools/imageDescriptions/imageDescription";

Logger.root.level = "silent"; // disable internal logs
const logger = new Logger({ name: "app", level: "trace" });
Expand Down
6 changes: 4 additions & 2 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"baseUrl": "..",
"rootDir": "..",
"paths": {
"bee-community-tools/*": ["./src/*.js"],
"@/*": ["./src/*"]
"bee-community-tools/tools/*": ["./tools/*.js"],
"@/*": ["./src/*"],
"@tools/*": ["./tools/*"],
"@helpers/*": ["./tools/examples/helpers/*"]
}
},
"references": [{ "path": "./src" }],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"lint:fix": "yarn eslint --fix",
"format": "yarn prettier --check .",
"format:fix": "yarn prettier --write .",
"test:unit": "vitest run src",
"test:unit": "vitest run tools -t \"Unit Test\"",
"test:unit:watch": "vitest run src",
"test:e2e": "vitest run tests",
"test:e2e": "vitest run tools -t \"e2e Test\"",
"test:e2e:watch": "vitest watch tests",
"test:all": "vitest run",
"test:watch": "vitest watch",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { describe, test } from "vitest";
import { AirtableTool, AirtableToolOptions } from "@/tools/airtable.js";
import { AirtableTool, AirtableToolOptions } from "@tools/airtable/airtable.js";

Check failure on line 18 in tools/airtable/airtableTool.ts

View workflow job for this annotation

GitHub Actions / Lint & Build & Test

Cannot find module '@tools/airtable/airtable.js' or its corresponding type declarations.

import { setupServer } from "msw/node";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import "dotenv/config.js";
import { BAMChatLLM } from "bee-agent-framework/adapters/bam/chat";
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { createConsoleReader } from "../helpers/io.js";
import { createConsoleReader } from "@tools/examples/helpers/io.js";

Check failure on line 20 in tools/airtable/examples/airTableToolAgent.ts

View workflow job for this annotation

GitHub Actions / Lint & Build & Test

Cannot find module '@tools/examples/helpers/io.js' or its corresponding type declarations.
import { FrameworkError } from "bee-agent-framework/errors";
import { TokenMemory } from "bee-agent-framework/memory/tokenMemory";
import { Logger } from "bee-agent-framework/logger/logger";
Expand All @@ -39,7 +39,7 @@ import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckG
import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia";

// AirTable tool
import { AirtableTool } from "bee-community-tools/tools/airtable";
import { AirtableTool } from "@tools/airtable/airtable.js";

Check failure on line 42 in tools/airtable/examples/airTableToolAgent.ts

View workflow job for this annotation

GitHub Actions / Lint & Build & Test

Cannot find module '@tools/airtable/airtable.js' or its corresponding type declarations.

const AIRTABLE_TOKEN: string = parseEnv("AIRTABLE_TOKEN", z.string());
const AIRTABLE_BASE: string = parseEnv("AIRTABLE_BASE", z.string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import { AirtableTool } from "@/tools/airtable.js";
// eslint-disable-next-line no-restricted-imports
import { AirtableTool } from "../../airtable.js";
import { beforeEach, expect } from "vitest";

const AIRTABLE_TOKEN: string = process.env.AIRTABLE_TOKEN as string;
const AIRTABLE_BASE: string = process.env.AIRTABLE_BASE as string;

describe("AirtableTool", () => {
describe("AirtableTool e2e Test", () => {
let instance: AirtableTool;

beforeEach(() => {
Expand Down
89 changes: 89 additions & 0 deletions tools/examples/helpers/io.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Copyright 2024 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import readline from "node:readline/promises";
import { stdin, stdout } from "node:process";
import picocolors from "picocolors";
import * as R from "remeda";
import stripAnsi from "strip-ansi";

interface ReadFromConsoleInput {
fallback?: string;
input?: string;
allowEmpty?: boolean;
}

export function createConsoleReader({
fallback,
input = "User 👤 : ",
allowEmpty = false,
}: ReadFromConsoleInput = {}) {
const rl = readline.createInterface({ input: stdin, output: stdout, terminal: true });
let isActive = true;

return {
write(role: string, data: string) {
rl.write(
[role && R.piped(picocolors.red, picocolors.bold)(role), stripAnsi(data ?? "")]
.filter(Boolean)
.join(" ")
.concat("\n"),
);
},
async prompt(): Promise<string> {
for await (const { prompt } of this) {
return prompt;
}
process.exit(0);
},
async *[Symbol.asyncIterator]() {
if (!isActive) {
return;
}

try {
rl.write(
`${picocolors.dim(`Interactive session has started. To escape, input 'q' and submit.\n`)}`,
);

for (let iteration = 1, prompt = ""; isActive; iteration++) {
prompt = await rl.question(R.piped(picocolors.cyan, picocolors.bold)(input));
prompt = stripAnsi(prompt);

if (prompt === "q") {
break;
}
if (!prompt.trim() || prompt === "\n") {
prompt = fallback ?? "";
}
if (allowEmpty !== false && !prompt.trim()) {
rl.write("Error: Empty prompt is not allowed. Please try again.\n");
iteration -= 1;
continue;
}
yield { prompt, iteration };
}
} catch (e) {
if (e.code === "ERR_USE_AFTER_CLOSE") {
return;
}
} finally {
isActive = false;
rl.close();
}
},
};
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

describe("Test", () => {
describe("Test e2e Test", () => {
it("Runs", async () => {
expect(1).toBe(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/

import { describe, test } from "vitest";
import { HelloWorldTool } from "./helloWorld.js";
// eslint-disable-next-line no-restricted-imports
import { HelloWorldTool } from "../helloWorld.js";

describe("HelloWorldTool", () => {
describe("HelloWorldTool Unit Test", () => {
test("HelloWorld", () => {
const helloWorldTool = new HelloWorldTool();
helloWorldTool
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import { ImageDescriptionTool } from "@/tools/imageDescription.js";
// eslint-disable-next-line no-restricted-imports
import { ImageDescriptionTool } from "../../imageDescription.js";

import { beforeEach, expect } from "vitest";

describe("ImageDescriptionTool", () => {
describe("ImageDescriptionTool e2e Test", () => {
let instance: ImageDescriptionTool;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { ImageDescriptionTool } from "@/tools/imageDescription.js";
// eslint-disable-next-line no-restricted-imports
import { ImageDescriptionTool } from "../imageDescription.js";

import { afterAll, afterEach, beforeAll, expect, describe, test, vi } from "vitest";
import { setupServer } from "msw/node";
Expand All @@ -38,7 +39,7 @@ const handlers = [

const server = setupServer(...handlers);

describe("ImageDescriptionTool", () => {
describe("ImageDescriptionTool Unit Test", () => {
beforeAll(() => {
vi.stubEnv("IMAGE_DESC_VLLM_API", "https://api.openai.com");
vi.stubEnv("IMAGE_DESC_MODEL_ID", "llava-hf/llama3-llava-next-8b-hf");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/

import { OpenLibraryTool } from "@/tools/openLibrary.js";
// eslint-disable-next-line no-restricted-imports
import { OpenLibraryTool } from "../../openLibrary.js";

import { beforeEach, expect } from "vitest";

describe("Open Library", () => {
describe("Open Library e2e Test", () => {
let instance: OpenLibraryTool;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import { describe, test } from "vitest";
import { OpenLibraryTool } from "./openLibrary.js";
// eslint-disable-next-line no-restricted-imports
import { OpenLibraryTool } from "../openLibrary.js";
import { setupServer } from "msw/node";
import { http, HttpResponse } from "msw";
import { ToolError } from "bee-agent-framework/tools/base";
Expand Down Expand Up @@ -57,7 +58,7 @@ const server = setupServer(
}),
);

describe("OpenLibraryTool", () => {
describe("OpenLibraryTool Unit Test", () => {
const openLibraryTool = new OpenLibraryTool();

beforeAll(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/version.test.ts → tools/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import { Version } from "@/version.js";
import { Version } from "./version.js";

describe("Version", () => {
describe("Version Unit Test", () => {
it("has a valid version", () => {
expect(Version).toBeTruthy();
});
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import tsConfig from "./tsconfig.json";
import { JscTarget } from "@swc/types";

export default defineConfig({
entry: ["src/**/*.{ts,js}", "!src/**/*.test.ts"],
entry: ["tools/**/*.{ts,js}", "!tools/**/*.test.ts"],
tsconfig: "./tsconfig.json",
sourcemap: true,
dts: true,
Expand Down

0 comments on commit 13891f0

Please sign in to comment.