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: add discord example #25

Merged
merged 8 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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
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'/,
],
},
},
});
74 changes: 41 additions & 33 deletions examples/discord/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
// 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';

// 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,
// // });
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 DISCORD_BOT_TOKEN = requireEnv('DISCORD_BOT_TOKEN');

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 discordClient = await createDiscordApp({
app,
});

void (async () => {
try {
await discordClient.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
Loading