Skip to content

Commit

Permalink
要約Botの参加チャンネルを指定できるオプションを追加、要約データがない場合に落ちる問題を修正、要約モデルの切り替え機構を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
tissueMO committed Nov 12, 2024
1 parent f48a25a commit 4def0a6
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions extensions/discord/addon/RecordAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class RecordAddon extends Addon {
description: 'Botが退出しても要約を自動生成しません。',
type: ApplicationCommandOptionType.Boolean,
},
{
name: 'channel',
description: '参加チャンネル',
type: ApplicationCommandOptionType.Channel,
channelTypes: [ChannelType.GuildVoice],
},
],
},
{
Expand Down Expand Up @@ -186,15 +192,15 @@ class RecordAddon extends Addon {
await this.#clean(guild.id);

/** @type {VoiceChannel} 呼び出したユーザーが参加しているボイスチャンネル */
const channel = interaction.member.voice?.channel;
const channel = interaction.options.getChannel('channel') ?? interaction.member.voice?.channel;

// 文字起こし開始コマンド
if (interaction.commandName === 'record-start') {
console.info(`[RecordAddon] <${guild.name}> コマンド: 記録開始`);

if (!channel) {
await interaction.reply({
content: 'ボイスチャンネルに参加してから呼び出してください。',
content: 'ボイスチャンネルに参加してから呼び出すか、チャンネルを指定してください。',
ephemeral: true,
});
return;
Expand Down Expand Up @@ -273,7 +279,7 @@ class RecordAddon extends Addon {

if (!channel) {
await interaction.reply({
content: 'ボイスチャンネルに参加してから呼び出してください。',
content: 'ボイスチャンネルに参加させてから呼び出してください。',
ephemeral: true,
});
return;
Expand Down Expand Up @@ -365,7 +371,7 @@ class RecordAddon extends Addon {

if (!channel) {
await interaction.reply({
content: 'ボイスチャンネルに参加してから呼び出してください。',
content: 'ボイスチャンネルに参加させてから呼び出してください。',
ephemeral: true,
});
return;
Expand Down Expand Up @@ -427,8 +433,13 @@ class RecordAddon extends Addon {
if (autoSummary && process.env.DEFAULT_CHANNEL_ID) {
console.info(`[RecordAddon] 30秒後に要約します。`);
await setTimeout(30000);

const summary = await this.#summarize(previousChannel, start, end);
await client.channels.cache.get(process.env.DEFAULT_CHANNEL_ID).send(summary);
if (summary) {
await client.channels.cache.get(process.env.DEFAULT_CHANNEL_ID).send(summary);
} else {
console.info(`[RecordAddon] 該当期間の記録データがありません。`);
}
}
}
});
Expand Down Expand Up @@ -557,9 +568,15 @@ class RecordAddon extends Addon {
return null;
}

// 時間帯に応じてモデルを切り替える
let model = 'summarize';
if (start.hour() >= 17) {
model = 'summarize-casual';
}

const { data } = await axios.post(`${process.env.OPEN_WEBUI_HOST}/api/chat/completions`,
{
model: 'summarize',
model: model,
messages: [
{
role: 'user',
Expand All @@ -575,7 +592,7 @@ class RecordAddon extends Addon {
}
);

console.log(`[RecordAddon] OpenAIトークン消費:`, data.usage);
console.log(`[RecordAddon] OpenAIトークン消費<${model}>:`, data.usage);

const now = dayjs().tz().format('YYYY/MM/DD');
const header = `${now} ${start.format('HH:mm')}-${end.format('HH:mm')} <${channel.name}> にて:`;
Expand Down

0 comments on commit 4def0a6

Please sign in to comment.