@aigne/example-chat-bot 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ # Change the name of this file to .env.local and fill in the following values
2
+
3
+ OPENAI_API_KEY="" # Your OpenAI API key
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Chatbot Example
2
+
3
+ This is a demonstration of using [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) and [AIGNE CLI](https://github.com/AIGNE-io/aigne-framework/blob/main/docs/cli.md) to create and run a agent-based chatbot.
4
+
5
+ ## Prerequisites
6
+
7
+ - [Node.js](https://nodejs.org) and npm installed on your machine
8
+ - [OpenAI API key](https://platform.openai.com/api-keys) used to interact with OpenAI API
9
+ - [Pnpm](https://pnpm.io) [Optional] if you want to run the example from source code
10
+
11
+ ## Try without Installation
12
+
13
+ ```bash
14
+ export OPENAI_API_KEY=YOUR_OPENAI_API_KEY # Setup your OpenAI API key
15
+
16
+ npx -y @aigne/example-chat-bot # Run the example
17
+ ```
@@ -0,0 +1,32 @@
1
+ # Aigne Default Template
2
+
3
+ This is the default project template for the Aigne framework, providing a basic chat agent and JavaScript code execution functionality.
4
+
5
+ ## Template Structure
6
+
7
+ - `aigne.yaml` - Project configuration file that defines the chat model used and references to agents
8
+ - `chat.yaml` - Chat agent configuration, including agent instructions and tools used
9
+ - `sandbox.js` - JavaScript code execution tool for running JavaScript code within conversations
10
+ - `sandbox.test.js` - Test file to verify the functionality of the code execution tool
11
+
12
+ ## Quick Start
13
+
14
+ ### Install AIGNE CLI
15
+
16
+ ```bash
17
+ npm install -g aigne
18
+ ```
19
+
20
+ ### Start the Project
21
+
22
+ ```bash
23
+ aigne run
24
+ ```
25
+
26
+ ## Testing
27
+
28
+ Run the following command to execute test cases:
29
+
30
+ ```bash
31
+ aigne test
32
+ ```
@@ -0,0 +1,7 @@
1
+ chat_model:
2
+ name: gpt-4o-mini
3
+ temperature: 0.8
4
+ agents:
5
+ - chat.yaml
6
+ tools:
7
+ - sandbox.js
@@ -0,0 +1,7 @@
1
+ name: chat
2
+ description: Chat agent
3
+ instructions: |
4
+ You are a helpful assistant that can answer questions and provide information on a wide range of topics.
5
+ Your goal is to assist users in finding the information they need and to engage in friendly conversation.
6
+ tools:
7
+ - sandbox.js
@@ -0,0 +1,26 @@
1
+ import vm from "node:vm";
2
+
3
+ export default async function evaluateJs({ code }) {
4
+ const sandbox = {};
5
+ const context = vm.createContext(sandbox);
6
+ const result = vm.runInContext(code, context, { displayErrors: true });
7
+ return { result };
8
+ }
9
+
10
+ evaluateJs.description = "This agent evaluates JavaScript code.";
11
+
12
+ evaluateJs.input_schema = {
13
+ type: "object",
14
+ properties: {
15
+ code: { type: "string", description: "JavaScript code to evaluate" },
16
+ },
17
+ required: ["code"],
18
+ };
19
+
20
+ evaluateJs.output_schema = {
21
+ type: "object",
22
+ properties: {
23
+ result: { type: "any", description: "Result of the evaluated code" },
24
+ },
25
+ required: ["result"],
26
+ };
@@ -0,0 +1,7 @@
1
+ import assert from "node:assert";
2
+ import test from "node:test";
3
+ import evaluateJs from "./sandbox.js";
4
+
5
+ test("evaluateJs should execute script correctly", async () => {
6
+ assert.deepEqual(await evaluateJs({ code: "1 + 2" }), { result: 3 });
7
+ });
package/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env npx -y bun
2
+
3
+ import assert from "node:assert";
4
+ import { spawnSync } from "node:child_process";
5
+ import { join } from "node:path";
6
+
7
+ const { OPENAI_API_KEY } = process.env;
8
+ assert(OPENAI_API_KEY, "Please set the OPENAI_API_KEY environment variable");
9
+
10
+ spawnSync("npx", ["-y", "@aigne/cli", "run", join(import.meta.dirname, "agents")], {
11
+ stdio: "inherit",
12
+ });
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@aigne/example-chat-bot",
3
+ "version": "1.1.0",
4
+ "description": "A demonstration of using AIGNE Framework to build a chat bot",
5
+ "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
+ "homepage": "https://github.com/AIGNE-io/aigne-framework/tree/main/examples/chat-bot",
7
+ "license": "ISC",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/AIGNE-io/aigne-framework"
11
+ },
12
+ "type": "module",
13
+ "bin": "index.ts",
14
+ "files": [
15
+ "agents",
16
+ ".env.local.example",
17
+ "*.ts",
18
+ "README.md"
19
+ ],
20
+ "dependencies": {
21
+ "@aigne/cli": "^1.1.0"
22
+ },
23
+ "scripts": {
24
+ "start": "npx -y bun run index.ts",
25
+ "lint": "tsc --noEmit"
26
+ }
27
+ }