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

Refactor directory structure #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 "./airtable.js";

import { setupServer } from "msw/node";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
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";
// eslint-disable-next-line no-restricted-imports
import { createConsoleReader } from "../../examples/helpers/io.js";
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 +40,8 @@ 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";
// eslint-disable-next-line no-restricted-imports
import { AirtableTool } from "../../airtable/airtable.js";

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
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