-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added examples for bare and slack
- Loading branch information
Showing
23 changed files
with
940 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
rslib.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"noEmit": false, | ||
"paths": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
rslib.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
// // }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"noEmit": false, | ||
"paths": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
dist/ | ||
rslib.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.