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

chore: added examples for bare and slack #17

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
3 changes: 3 additions & 0 deletions examples/bare/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
rslib.config.ts
9 changes: 9 additions & 0 deletions examples/bare/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"root": true,
"extends": ["@callstack/eslint-config/node", "prettier"],
"settings": {
"import/resolver": {
"typescript": true
}
}
}
28 changes: 28 additions & 0 deletions examples/bare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "bare-example",
"version": "1.0.0",
"description": "Example usage of byorg.ai core",
"type": "module",
"main": "dist/index.js",
"source": "src/index.js",
"private": true,
"scripts": {
"build": "rsbuild build",
"example": "pnpm build && mv dist/index.js dist/index.cjs && dotenv -- node dist/index.cjs"
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.3.1",
"@callstack/byorg-utils": "0.3.1"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
"@callstack/eslint-config": "^14.2.0",
"@rsbuild/core": "^1.0.5",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
},
"author": "",
"license": "ISC"
}
39 changes: 39 additions & 0 deletions examples/bare/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { defineConfig } from '@rsbuild/core';

const shared = {
source: {
tsconfigPath: './tsconfig.build.json',
},
};

export default defineConfig({
source: {
entry: {
index: {
filename: 'index.js',
import: './src/index.ts',
},
},
tsconfigPath: './tsconfig.build.json',
},
output: {
target: 'node',
minify: false,
},
tools: {
rspack: {
module: {
parser: {
javascript: {
dynamicImportMode: 'eager',
},
},
},
resolve: {
extensionAlias: {
'.js': ['.js', '.ts'],
},
},
},
},
});
81 changes: 81 additions & 0 deletions examples/bare/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import readline from 'readline';
import { Message, VercelChatModelAdapter, createApp } from '@callstack/byorg-core';
import { createOpenAI } from '@ai-sdk/openai';
import { requireEnv } from '@callstack/byorg-utils';

const LANGUAGE_MODEL = 'gpt-4o-2024-11-20';
const API_KEY = requireEnv('OPENAI_API_KEY');

const openAiProvider = createOpenAI({
apiKey: API_KEY,
compatibility: 'strict', // strict mode, enable when using the OpenAI API
});

const openAiModel = openAiProvider.languageModel(LANGUAGE_MODEL);

const chatModel = new VercelChatModelAdapter({
languageModel: openAiModel,
});

const systemPrompt = () => {
return 'Your name is Cassandra. You are an AI Assistant.';
};

const app = createApp({
chatModel,
systemPrompt,
});

// Create a readline interface for user input
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'You: ',
});

// Create array for messages
const messages: Message[] = [];

// Start the CLI chat
console.log('Welcome to the byorg.ai example cli Chat!\n');

rl.prompt();

rl.on('line', async (line: string) => {
const input = line.trim();

if (input.toLowerCase() === 'exit') {
console.log('\nGoodbye!');
rl.close();
return;
}

messages.push({ role: 'user', content: input });

process.stdout.write('\n');
process.stdout.write('Bot: ');

let currentMessage = '';
const { response } = await app.processMessages(messages, {
onPartialResponse: (text: string) => {
const delta = text.slice(currentMessage.length);
currentMessage += delta;
process.stdout.write(delta);
},
});

if (response.role === 'assistant') {
messages.push({ role: response.role, content: response.content });
}

process.stdout.write('\n\n');

rl.prompt();

return;
});

process.on('SIGINT', () => {
console.log('Ctrl-C was pressed');
process.exit();
});
8 changes: 8 additions & 0 deletions examples/bare/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": false,
"paths": {}
}
}
17 changes: 17 additions & 0 deletions examples/bare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "esnext",
"module": "node16",
"moduleResolution": "node16",
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noStrictGenericChecks": false,
"skipLibCheck": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react"
},
"include": ["src"]
}
3 changes: 3 additions & 0 deletions examples/discord/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
rslib.config.ts
9 changes: 9 additions & 0 deletions examples/discord/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"root": true,
"extends": ["@callstack/eslint-config/node", "prettier"],
"settings": {
"import/resolver": {
"typescript": true
}
}
}
31 changes: 31 additions & 0 deletions examples/discord/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "discord-example",
"version": "1.0.0",
"description": "Example usage of byorg.ai discord integration",
"type": "module",
"main": "dist/index.js",
"private": true,
"bin": {
"example": "./index.js"
},
"scripts": {
"build": "rsbuild build",
"example": "pnpm build && mv dist/index.js dist/index.cjs && dotenv -- node dist/index.cjs"
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.3.1",
"@callstack/byorg-discord": "0.3.1",
"@callstack/byorg-utils": "0.3.1"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
"@callstack/eslint-config": "^14.2.0",
"@rsbuild/core": "^1.0.5",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
},
"author": "",
"license": "ISC"
}
33 changes: 33 additions & 0 deletions examples/discord/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineConfig } from '@rsbuild/core';

export default defineConfig({
source: {
entry: {
index: {
filename: 'index.js',
import: './src/index.ts',
},
},
tsconfigPath: './tsconfig.build.json',
},
output: {
target: 'node',
minify: false,
},
tools: {
rspack: {
module: {
parser: {
javascript: {
dynamicImportMode: 'eager',
},
},
},
resolve: {
extensionAlias: {
'.js': ['.js', '.ts'],
},
},
},
},
});
32 changes: 32 additions & 0 deletions examples/discord/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// import readline from 'readline';
// import { Message, VercelChatModelAdapter, createApp } from '@callstack/byorg-core';
// import { createOpenAI } from '@ai-sdk/openai';
// import { requireEnv } from '@callstack/byorg-utils';
// import { createDiscordApp } from '@callstack/byorg-discord';

// const LANGUAGE_MODEL = 'gpt-4o-2024-11-20';
// const API_KEY = requireEnv('OPENAI_API_KEY');

// const openAiProvider = createOpenAI({
// apiKey: API_KEY,
// compatibility: 'strict', // strict mode, enable when using the OpenAI API
// });

// const openAiModel = openAiProvider.languageModel(LANGUAGE_MODEL);

// const chatModel = new VercelChatModelAdapter({
// languageModel: openAiModel,
// });

// const systemPrompt = () => {
// return 'Your name is Cassandra. You are an AI Assistant.';
// };

// const app = createApp({
// chatModel,
// systemPrompt,
// });

// // const discord = createDiscordApp({
// // app,
// // });
8 changes: 8 additions & 0 deletions examples/discord/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": false,
"paths": {}
}
}
17 changes: 17 additions & 0 deletions examples/discord/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "esnext",
"module": "node16",
"moduleResolution": "node16",
"noEmit": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noStrictGenericChecks": false,
"skipLibCheck": true,
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react"
},
"include": ["src"]
}
3 changes: 3 additions & 0 deletions examples/slack/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
rslib.config.ts
9 changes: 9 additions & 0 deletions examples/slack/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"root": true,
"extends": ["@callstack/eslint-config/node", "prettier"],
"settings": {
"import/resolver": {
"typescript": true
}
}
}
31 changes: 31 additions & 0 deletions examples/slack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "slack-example",
"version": "1.0.0",
"description": "Example usage of byorg.ai slack integration",
"type": "module",
"main": "dist/index.js",
"private": true,
"bin": {
"example": "./index.js"
},
"scripts": {
"build": "rsbuild build",
"example": "pnpm build && mv dist/index.js dist/index.cjs && dotenv -- node dist/index.cjs"
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.3.1",
"@callstack/byorg-slack": "0.3.1",
"@callstack/byorg-utils": "0.3.1"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
"@callstack/eslint-config": "^14.2.0",
"@rsbuild/core": "^1.0.5",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
},
"author": "",
"license": "ISC"
}
Loading
Loading