-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 2 commits
31abd31
f1a1a65
a632685
4ef2997
cea9c91
ccbd1c8
6176a10
6ee9b15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@callstack/byorg-discord': minor | ||
'discord-example': patch | ||
--- | ||
|
||
added start function to abstract away passing bot token |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,14 @@ | |
"dependencies": { | ||
"@ai-sdk/openai": "^1.0.2", | ||
"@callstack/byorg-core": "0.4.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you replace all 0.4.2 references with workspace (in every package)? There was a bug if you released it with changeset, but now we do release it with |
||
"@callstack/byorg-discord": "0.4.2", | ||
"@callstack/byorg-utils": "0.4.2" | ||
"@callstack/byorg-discord": "workspace:^", | ||
"@callstack/byorg-utils": "0.4.2", | ||
"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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
// 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 { 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 openAiModel = openAiProvider.languageModel(LANGUAGE_MODEL); | ||
|
||
// const chatModel = new VercelChatModelAdapter({ | ||
// languageModel: openAiModel, | ||
// }); | ||
const chatModel = new VercelChatModelAdapter({ | ||
languageModel: openAiModel, | ||
}); | ||
|
||
// const systemPrompt = () => { | ||
// return 'Your name is Cassandra. You are an 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 = createDiscordApp({ | ||
// // app, | ||
// // }); | ||
void createDiscordApp({ | ||
app, | ||
botToken: DISCORD_BOT_TOKEN, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@callstack/byorg-discord", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave version updating to changset |
||
"type": "module", | ||
"license": "MIT", | ||
"author": "Szymon Chmal <[email protected]> (https://github.com/V3R0N), Maciej Jastrzebski <[email protected]> (https://github.com/mdjastrzebski), Kewin Wereszczynski <[email protected]> (https://github.com/Q1w1N)", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,18 @@ const UPDATE_THROTTLE_TIME = 200; | |
|
||
export type DiscordApplicationConfig = { | ||
app: Application; | ||
botToken: string; | ||
}; | ||
|
||
export async function createDiscordApp(options: DiscordApplicationConfig) { | ||
const { app } = options; | ||
type ClientStart = { | ||
start: () => Promise<string>; | ||
}; | ||
|
||
export type DiscordClient = Client & ClientStart; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add code comment documenting this hack |
||
|
||
export function createDiscordApp(options: DiscordApplicationConfig): DiscordClient { | ||
const { app, botToken } = options; | ||
|
||
const botToken = process.env['DISCORD_BOT_TOKEN'] as string; | ||
const client = new Client({ | ||
intents: [ | ||
GatewayIntentBits.DirectMessages, | ||
|
@@ -20,7 +26,7 @@ export async function createDiscordApp(options: DiscordApplicationConfig) { | |
GatewayIntentBits.GuildMessages, | ||
], | ||
partials: [Partials.Channel], | ||
}); | ||
}) as DiscordClient; | ||
|
||
client.once(Events.ClientReady, (readyClient) => { | ||
console.log(`Ready! Logged in as ${readyClient.user.tag}`); | ||
|
@@ -76,7 +82,9 @@ export async function createDiscordApp(options: DiscordApplicationConfig) { | |
await pendingEffects; | ||
}); | ||
|
||
await client.login(botToken); | ||
client.start = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we adding methods to existing discord object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make usage of discord the same as slack, and to abstract away the "login" method that takes in the bot token as an argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see any code in this PR actually calling this method. Is it needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now added |
||
return client.login(botToken); | ||
}; | ||
|
||
return client; | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] implementing example actually accounts as a minor ;-)