Skip to content

Commit

Permalink
chore: add discord example (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Q1w1N authored Dec 7, 2024
1 parent cfb7b40 commit 5e25d3a
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 132 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-mangos-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@callstack/byorg-discord': minor
'discord-example': minor
---

discord: changed passing bot token variable and discord login
2 changes: 1 addition & 1 deletion docs/src/docs/core/system-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const systemPrompt = (context: RequestContext): Promise<string> | string
let date = new Date().toDateString();
let userName = context.extras.userName;

return `You are a helpful AI bot. Your name is Cassandra. You work for Callstack.
return `You are a helpful AI bot. Your name is Byorg. You work for ACME.
Current date: ${date}
You are talking with: ${userName}`;
};
Expand Down
2 changes: 1 addition & 1 deletion docs/src/docs/core/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Here is step by step how to start with byorg.
import { RequestContext } from '@callstack/byorg-core';

const systemPrompt = (context: RequestContext): Promise<string> | string => {
return "You are a helpful AI assistant named Cassandra";
return "You are a helpful AI assistant named Byorg";
};
```
### Create an Application instance
Expand Down
4 changes: 2 additions & 2 deletions examples/bare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.4.2",
"@callstack/byorg-utils": "0.4.2"
"@callstack/byorg-core": "workspace:*",
"@callstack/byorg-utils": "workspace:*"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
Expand Down
9 changes: 5 additions & 4 deletions examples/discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.4.2",
"@callstack/byorg-discord": "0.4.2",
"@callstack/byorg-utils": "0.4.2"
"@callstack/byorg-core": "workspace:*",
"@callstack/byorg-discord": "workspace:*",
"@callstack/byorg-utils": "workspace:*",
"zlib-sync": "^0.1.9"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
"@callstack/eslint-config": "^14.2.0",
"@rsbuild/core": "^1.0.5",
"dotenv-cli": "^7.4.2",
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.6.3"
Expand Down
5 changes: 5 additions & 0 deletions examples/discord/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default defineConfig({
'.js': ['.js', '.ts'],
},
},
ignoreWarnings: [
/the request of a dependency is an expression/,
/Can't resolve 'bufferutil'/,
/Can't resolve 'utf-8-validate'/,
],
},
},
});
56 changes: 30 additions & 26 deletions examples/discord/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
// TODO
// 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';
import { VercelChatModelAdapter, createApp } from '@callstack/byorg-core';
import { createOpenAI } from '@ai-sdk/openai';
import { logger, 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 LANGUAGE_MODEL = 'gpt-4o-2024-11-20';
const API_KEY = requireEnv('OPENAI_API_KEY');
const DISCORD_BOT_TOKEN = requireEnv('DISCORD_BOT_TOKEN');

// const openAiProvider = createOpenAI({
// apiKey: API_KEY,
// compatibility: 'strict', // strict mode, enable when using the OpenAI API
// });
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: openAiProvider.languageModel(LANGUAGE_MODEL),
});

// const chatModel = new VercelChatModelAdapter({
// languageModel: openAiModel,
// });
const systemPrompt = () => {
return 'Your name is Byorg. You are a helpful AI Assistant.';
};

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

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

// // const discord = createDiscordApp({
// // app,
// // });
void (async () => {
try {
await discord.login(DISCORD_BOT_TOKEN);
logger.info('Discord ready.');
} catch (error) {
logger.error('Dev Slack start error:', error);
}
})();
6 changes: 3 additions & 3 deletions examples/slack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"dependencies": {
"@ai-sdk/openai": "^1.0.2",
"@callstack/byorg-core": "0.4.2",
"@callstack/byorg-slack": "0.4.2",
"@callstack/byorg-utils": "0.4.2"
"@callstack/byorg-core": "workspace:*",
"@callstack/byorg-slack": "workspace:*",
"@callstack/byorg-utils": "workspace:*"
},
"devDependencies": {
"dotenv-cli": "^7.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test:watch": "vitest"
},
"dependencies": {
"@callstack/byorg-utils": "workspace:^*",
"@callstack/byorg-utils": "workspace:*",
"ts-regex-builder": "^1.8.2",
"zod": "^3.23.8"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@callstack/byorg-core": "workspace:^*",
"@callstack/byorg-core": "workspace:*",
"discord-interactions": "^4.1.0",
"discord.js": "^14.15.3"
},
Expand Down
5 changes: 1 addition & 4 deletions packages/discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ export type DiscordApplicationConfig = {
app: Application;
};

export async function createDiscordApp(options: DiscordApplicationConfig) {
export function createDiscordApp(options: DiscordApplicationConfig) {
const { app } = options;

const botToken = process.env['DISCORD_BOT_TOKEN'] as string;
const client = new Client({
intents: [
GatewayIntentBits.DirectMessages,
Expand Down Expand Up @@ -76,8 +75,6 @@ export async function createDiscordApp(options: DiscordApplicationConfig) {
await pendingEffects;
});

await client.login(botToken);

return client;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/document-loaders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@callstack/byorg-utils": "workspace:^*",
"@callstack/byorg-utils": "workspace:*",
"@google-cloud/local-auth": "^3.0.1",
"@notionhq/client": "^2.2.15",
"google-auth-library": "^9.14.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/slack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"test:watch": "vitest"
},
"dependencies": {
"@callstack/byorg-core": "workspace:^*",
"@callstack/byorg-utils": "workspace:^*",
"@callstack/slack-rich-text": "workspace:^*",
"@callstack/byorg-core": "workspace:*",
"@callstack/byorg-utils": "workspace:*",
"@callstack/slack-rich-text": "workspace:*",
"@slack/bolt": "^3.21.1",
"@slack/web-api": "^6.12.1",
"p-debounce": "^4.0.0",
Expand Down
Loading

0 comments on commit 5e25d3a

Please sign in to comment.