mirror of
https://github.com/kevinthedang/discord-ollama.git
synced 2026-06-20 21:57:26 -04:00
Summary Command (#194)
This commit is contained in:
@@ -9,6 +9,7 @@ import { ClearUserChannelHistory } from './cleanUserChannelHistory.js'
|
||||
import { PullModel } from './pullModel.js'
|
||||
import { SwitchModel } from './switchModel.js'
|
||||
import { DeleteModel } from './deleteModel.js'
|
||||
import { Summary } from './summary.js'
|
||||
|
||||
export default [
|
||||
ThreadCreate,
|
||||
@@ -20,5 +21,6 @@ export default [
|
||||
ClearUserChannelHistory,
|
||||
PullModel,
|
||||
SwitchModel,
|
||||
DeleteModel
|
||||
DeleteModel,
|
||||
Summary
|
||||
] as SlashCommand[]
|
||||
50
src/commands/summary.ts
Normal file
50
src/commands/summary.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Client, CommandInteraction, Message, MessageFlags, SendableChannels } from "discord.js";
|
||||
import { accessChannelContext, normalMessage, SlashCommand, summarizeContextHistory, UserCommand, UserMessage } from "../utils/index.js";
|
||||
import { ollama } from "../client.js"
|
||||
|
||||
export const Summary: SlashCommand = {
|
||||
name: 'summary',
|
||||
description: 'provides a summary of the chat history.',
|
||||
|
||||
// Generate Summary from additional context
|
||||
run: async (client: Client, interaction: CommandInteraction) => {
|
||||
// fetch channel
|
||||
const channel = await client.channels.fetch(interaction.channelId)
|
||||
if (!channel || !UserCommand.includes(channel.type)) return
|
||||
|
||||
// Defer
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral })
|
||||
|
||||
// create summary using context
|
||||
let channelContext: UserMessage[] = await new Promise((resolve) => {
|
||||
accessChannelContext(interaction.channelId, (additionalContext) => {
|
||||
if (additionalContext?.messages)
|
||||
resolve(additionalContext.messages)
|
||||
else
|
||||
resolve([])
|
||||
})
|
||||
})
|
||||
|
||||
if (channelContext.length === 0) {
|
||||
interaction.reply({
|
||||
content: `There are no recent chat messages in this channel.`,
|
||||
flags: MessageFlags.Ephemeral
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Push summarize prompt
|
||||
channelContext.push({
|
||||
role: "user",
|
||||
content: "Please Summarize everything from the prior messages, provide in bullet point fashion on what people have said prior. For example: \"Someone mentioned/talked about ...\"",
|
||||
images: []
|
||||
})
|
||||
|
||||
// todo: instead of a default of codellama, we can user default model somehow. Look into later.
|
||||
const response: string = await summarizeContextHistory(ollama, "codellama", channelContext)
|
||||
|
||||
console.log(response)
|
||||
|
||||
interaction.editReply({ content: response })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user