Skip to content

Commit

Permalink
feat(examples): use bee-agent-framework in imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas2D committed Sep 3, 2024
1 parent 5d85086 commit 50f7d72
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarn lint-staged
CI=true yarn lint && yarn run test:unit && yarn copyright
CI=true yarn lint && yarn ts:check && yarn run test:unit && yarn copyright
1 change: 0 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"*.{ts,js}": "eslint --fix",
"*.ts": "tsc-files --noEmit",
"*": "prettier --ignore-unknown --write"
}
20 changes: 17 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check

// @ts-expect-error missing types
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import prettierConfig from "eslint-config-prettier";
Expand Down Expand Up @@ -70,11 +69,26 @@ export default tseslint.config(
},
},
{
files: ["examples/**"],
files: ["examples/**/*.ts"],
languageOptions: {
parserOptions: {
project: "./tsconfig.examples.json",
},
},
rules: {
"no-restricted-imports": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-vars": "off",
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["@/"],
message: "Use 'bee-agent-framework' instead.",
},
],
},
],
},
},
// @ts-expect-error wrong types
Expand Down
20 changes: 10 additions & 10 deletions examples/agents/bee.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import "dotenv/config.js";
import { BeeAgent } from "@/agents/bee/agent.js";
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { createConsoleReader } from "../helpers/io.js";
import { FrameworkError } from "@/errors.js";
import { TokenMemory } from "@/memory/tokenMemory.js";
import { Logger } from "@/logger/logger.js";
import { PythonTool } from "@/tools/python/python.js";
import { LocalPythonStorage } from "@/tools/python/storage.js";
import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js";
import { WikipediaTool } from "@/tools/search/wikipedia.js";
import { OpenMeteoTool } from "@/tools/weather/openMeteo.js";
import { FrameworkError } from "bee-agent-framework/errors";
import { TokenMemory } from "bee-agent-framework/memory/tokenMemory";
import { Logger } from "bee-agent-framework/logger/logger";
import { PythonTool } from "bee-agent-framework/tools/python/python";
import { LocalPythonStorage } from "bee-agent-framework/tools/python/storage";
import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
import { WikipediaTool } from "bee-agent-framework/tools/search/wikipedia";
import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";

Logger.root.level = "silent"; // disable internal logs
const logger = new Logger({ name: "app", level: "trace" });
Expand Down
8 changes: 4 additions & 4 deletions examples/agents/bee_reusable.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "dotenv/config.js";
import { BeeAgent } from "@/agents/bee/agent.js";
import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js";
import { UnconstrainedMemory } from "@/memory/unconstrainedMemory.js";
import { OpenAIChatLLM } from "@/adapters/openai/chat.js";
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
import { UnconstrainedMemory } from "bee-agent-framework/memory/unconstrainedMemory";
import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat";

// We create an agent
let agent = new BeeAgent({
Expand Down
10 changes: 5 additions & 5 deletions examples/agents/simple.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import "dotenv/config.js";
import { BeeAgent } from "@/agents/bee/agent.js";
import { TokenMemory } from "@/memory/tokenMemory.js";
import { DuckDuckGoSearchTool } from "@/tools/search/duckDuckGoSearch.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { OpenMeteoTool } from "@/tools/weather/openMeteo.js";
import { BeeAgent } from "bee-agent-framework/agents/bee/agent";
import { TokenMemory } from "bee-agent-framework/memory/tokenMemory";
import { DuckDuckGoSearchTool } from "bee-agent-framework/tools/search/duckDuckGoSearch";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";
import { OpenMeteoTool } from "bee-agent-framework/tools/weather/openMeteo";

const llm = new OllamaChatLLM();
const agent = new BeeAgent({
Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "dotenv/config";

import { Logger } from "@/logger/logger.js";
import { Logger } from "bee-agent-framework/logger/logger";
Logger.defaults.pretty = true;
6 changes: 3 additions & 3 deletions examples/llms/chat.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "dotenv/config.js";
import { createConsoleReader } from "examples/helpers/io.js";
import { Logger } from "@/logger/logger.js";
import { BaseMessage, Role } from "@/llms/primitives/message.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { Logger } from "bee-agent-framework/logger/logger";
import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";

Logger.root.level = "info"; // or your custom level

Expand Down
6 changes: 3 additions & 3 deletions examples/llms/chatCallback.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "dotenv/config.js";
import { createConsoleReader } from "examples/helpers/io.js";
import { Logger } from "@/logger/logger.js";
import { BaseMessage, Role } from "@/llms/primitives/message.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { Logger } from "bee-agent-framework/logger/logger";
import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";

Logger.root.level = "info"; // or your custom level

Expand Down
6 changes: 3 additions & 3 deletions examples/llms/chatStream.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "dotenv/config.js";
import { createConsoleReader } from "examples/helpers/io.js";
import { Logger } from "@/logger/logger.js";
import { BaseMessage, Role } from "@/llms/primitives/message.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { Logger } from "bee-agent-framework/logger/logger";
import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";

Logger.root.level = "info"; // or your custom level

Expand Down
6 changes: 3 additions & 3 deletions examples/llms/providers/bam.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseMessage } from "@/llms/primitives/message.js";
import { BAMLLM } from "@/adapters/bam/llm.js";
import { BAMChatLLM } from "@/adapters/bam/chat.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { BAMLLM } from "bee-agent-framework/adapters/bam/llm";
import { BAMChatLLM } from "bee-agent-framework/adapters/bam/chat";

{
console.info("===RAW===");
Expand Down
4 changes: 2 additions & 2 deletions examples/llms/providers/langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// - @langchain/cohere (or any other provider related package that you would like to use)
// List of available providers: https://js.langchain.com/v0.2/docs/integrations/chat/

import { BaseMessage } from "@/llms/primitives/message.js";
import { LangChainChatLLM } from "@/adapters/langchain/llms/chat.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { LangChainChatLLM } from "bee-agent-framework/adapters/langchain/llms/chat";
// @ts-expect-error package not installed
import { ChatCohere } from "@langchain/cohere";

Expand Down
6 changes: 3 additions & 3 deletions examples/llms/providers/ollama.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OllamaLLM } from "@/adapters/ollama/llm.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { BaseMessage } from "@/llms/primitives/message.js";
import { OllamaLLM } from "bee-agent-framework/adapters/ollama/llm";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";

{
console.info("===RAW===");
Expand Down
4 changes: 2 additions & 2 deletions examples/llms/providers/openai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv/config";
import { BaseMessage } from "@/llms/primitives/message.js";
import { OpenAIChatLLM } from "@/adapters/openai/chat.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { OpenAIChatLLM } from "bee-agent-framework/adapters/openai/chat";

const llm = new OpenAIChatLLM({
modelId: "gpt-4o",
Expand Down
4 changes: 2 additions & 2 deletions examples/llms/providers/watsonx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv/config";
import { BaseMessage } from "@/llms/primitives/message.js";
import { WatsonXChatLLM } from "@/adapters/watsonx/chat.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { WatsonXChatLLM } from "bee-agent-framework/adapters/watsonx/chat";

const chatLLM = WatsonXChatLLM.fromPreset("meta-llama/llama-3-1-70b-instruct", {
apiKey: process.env.WATSONX_API_KEY,
Expand Down
8 changes: 4 additions & 4 deletions examples/llms/providers/watsonx_verbose.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import "dotenv/config";
import { BaseMessage } from "@/llms/primitives/message.js";
import { WatsonXChatLLM } from "@/adapters/watsonx/chat.js";
import { WatsonXLLM } from "@/adapters/watsonx/llm.js";
import { PromptTemplate } from "@/template.js";
import { BaseMessage } from "bee-agent-framework/llms/primitives/message";
import { WatsonXChatLLM } from "bee-agent-framework/adapters/watsonx/chat";
import { WatsonXLLM } from "bee-agent-framework/adapters/watsonx/llm";
import { PromptTemplate } from "bee-agent-framework/template";

const template = new PromptTemplate({
variables: ["messages"],
Expand Down
4 changes: 2 additions & 2 deletions examples/llms/structured.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "dotenv/config.js";
import { z } from "zod";
import { BaseMessage, Role } from "@/llms/primitives/message.js";
import { OllamaChatLLM } from "@/adapters/ollama/chat.js";
import { BaseMessage, Role } from "bee-agent-framework/llms/primitives/message";
import { OllamaChatLLM } from "bee-agent-framework/adapters/ollama/chat";

const llm = new OllamaChatLLM();
const response = await llm.generateStructured(
Expand Down
2 changes: 1 addition & 1 deletion examples/llms/text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "dotenv/config.js";
import { createConsoleReader } from "examples/helpers/io.js";
import { WatsonXLLM } from "@/adapters/watsonx/llm.js";
import { WatsonXLLM } from "bee-agent-framework/adapters/watsonx/llm";

const llm = new WatsonXLLM({
modelId: "google/flan-ul2",
Expand Down
6 changes: 3 additions & 3 deletions examples/template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "examples/helpers/setup.js";
import { PromptTemplate } from "@/template.js";
import { Logger } from "@/logger/logger.js";
import "./helpers/setup.js";
import { PromptTemplate } from "bee-agent-framework/template";
import { Logger } from "bee-agent-framework/logger/logger";

const logger = new Logger({ name: "template" });

Expand Down
2 changes: 1 addition & 1 deletion examples/tools/helloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
StringToolOutput,
Tool,
ToolInput,
} from "@/tools/base.js";
} from "bee-agent-framework/tools/base";
import { z } from "zod";

type ToolOptions = BaseToolOptions;
Expand Down
6 changes: 3 additions & 3 deletions examples/tools/openLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
ToolInput,
JSONToolOutput,
ToolError,
} from "@/tools/base.js";
} from "bee-agent-framework/tools/base";
import { z } from "zod";
import { createURLParams } from "@/internals/fetcher.js";
import { createURLParams } from "bee-agent-framework/internals/fetcher";

type ToolOptions = BaseToolOptions;
type ToolRunOptions = BaseToolRunOptions;
Expand Down Expand Up @@ -117,7 +117,7 @@ export class OpenLibraryTool extends Tool<OpenLibraryToolOutput, ToolOptions, To

protected async _run(input: ToolInput<this>, options?: ToolRunOptions) {
const params = createURLParams(input);
const url = `https://openlibrary.org/search.json?${decodeURIComponent(params.toString())}`;
const url = `https://openlibrary.org/searchon?${decodeURIComponent(params.toString())}`;
const response = await fetch(url, {
signal: options?.signal,
});
Expand Down
13 changes: 13 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "..",
"rootDir": "..",
"paths": {
"bee-agent-framework/*": ["./src/*.js"],
"@/*": ["./src/*"]
}
},
"references": [{ "path": "./src" }],
"exclude": ["../tests", "../**/*.test.ts"]
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
"scripts": {
"clean": "rimraf dist",
"build": "yarn clean && yarn ts:check && tsup",
"ts:check": "tsc --noEmit",
"start:bee": "tsx examples/agents/bee.ts",
"ts:check": "tsc --noEmit && tsc -p tsconfig.examples.json --noEmit",
"start": "tsx --tsconfig tsconfig.examples.json",
"start:bee": "yarn start -- examples/agents/bee.ts",
"infra:start-all": "yarn _docker compose up -d",
"infra:start-code-interpreter": "yarn _docker compose up bee-code-interpreter",
"infra:stop-all": "yarn _docker compose down",
Expand Down Expand Up @@ -126,6 +127,7 @@
"@swc/core": "^1.7.14",
"@types/eslint": "^9.6.1",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__js": "^8.42.3",
"@types/mustache": "^4",
"@types/needle": "^3.3.0",
"@types/node": "^20.16.1",
Expand Down Expand Up @@ -154,7 +156,7 @@
"temp-dir": "^3.0.0",
"tsc-files": "^1.1.4",
"tsup": "^8.2.4",
"tsx": "^4.17.0",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0",
"vite-tsconfig-paths": "^5.0.1",
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./examples/tsconfig.json"
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"@tests/*": ["./tests/*"]
},
"useUnknownInCatchVariables": false
}
},
"exclude": ["examples"]
}
6 changes: 5 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ export default defineConfig({
define: {
__LIBRARY_VERSION: JSON.stringify(packageJson.version),
},
plugins: [tsConfigPaths()],
plugins: [
tsConfigPaths({
projects: ["tsconfig.json"],
}),
],
});
22 changes: 16 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ __metadata:
languageName: node
linkType: hard

"@types/eslint@npm:^9.6.1":
"@types/eslint@npm:*, @types/eslint@npm:^9.6.1":
version: 9.6.1
resolution: "@types/eslint@npm:9.6.1"
dependencies:
Expand All @@ -1846,6 +1846,15 @@ __metadata:
languageName: node
linkType: hard

"@types/eslint__js@npm:^8.42.3":
version: 8.42.3
resolution: "@types/eslint__js@npm:8.42.3"
dependencies:
"@types/eslint": "npm:*"
checksum: 10c0/ccc5180b92155929a089ffb03ed62625216dcd5e46dd3197c6f82370ce8b52c7cb9df66c06b0a3017995409e023bc9eafe5a3f009e391960eacefaa1b62d9a56
languageName: node
linkType: hard

"@types/estree@npm:*, @types/estree@npm:1.0.5, @types/estree@npm:^1.0.0":
version: 1.0.5
resolution: "@types/estree@npm:1.0.5"
Expand Down Expand Up @@ -2508,6 +2517,7 @@ __metadata:
"@swc/core": "npm:^1.7.14"
"@types/eslint": "npm:^9.6.1"
"@types/eslint-config-prettier": "npm:^6.11.3"
"@types/eslint__js": "npm:^8.42.3"
"@types/mustache": "npm:^4"
"@types/needle": "npm:^3.3.0"
"@types/node": "npm:^20.16.1"
Expand Down Expand Up @@ -2554,7 +2564,7 @@ __metadata:
temp-dir: "npm:^3.0.0"
tsc-files: "npm:^1.1.4"
tsup: "npm:^8.2.4"
tsx: "npm:^4.17.0"
tsx: "npm:^4.19.0"
turndown: "npm:^7.2.0"
typescript: "npm:^5.5.4"
typescript-eslint: "npm:^8.2.0"
Expand Down Expand Up @@ -8949,9 +8959,9 @@ __metadata:
languageName: node
linkType: hard

"tsx@npm:^4.17.0":
version: 4.17.0
resolution: "tsx@npm:4.17.0"
"tsx@npm:^4.19.0":
version: 4.19.0
resolution: "tsx@npm:4.19.0"
dependencies:
esbuild: "npm:~0.23.0"
fsevents: "npm:~2.3.3"
Expand All @@ -8961,7 +8971,7 @@ __metadata:
optional: true
bin:
tsx: dist/cli.mjs
checksum: 10c0/ad720b81d6447c7695d24c27947fa1a2b6db9d2ef03216389edd6fa0006aa479bc0d8348a1ac9975a08edef4ce791ff5629a24d8dccbb0987f42e5407785cfa4
checksum: 10c0/d14463a78067c6db84c677b79b14861de6d7f6fb0ffa5727cc500c4552459e936395a3854ad0112af0fd7b263bcedd62ce3929b036188eb10cd9902a607ffe34
languageName: node
linkType: hard

Expand Down

0 comments on commit 50f7d72

Please sign in to comment.