yes
This commit is contained in:
parent
14867491af
commit
05f3b48f11
6 changed files with 68 additions and 34 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -11,7 +11,8 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordeno/bot": "^19.0.0-next.d81b28a",
|
"@discordeno/bot": "^19.0.0-next.d81b28a",
|
||||||
"@discordeno/rest": "^19.0.0-next.d81b28a"
|
"@discordeno/rest": "^19.0.0-next.d81b28a",
|
||||||
|
"ollama": "^0.5.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run --watch src/index.ts",
|
"dev": "bun run --watch src/index.ts",
|
||||||
|
|
40
src/interactions/ai.ts
Normal file
40
src/interactions/ai.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import type { Command } from "../lib/types/command";
|
||||||
|
import { type Interaction } from "@discordeno/bot";
|
||||||
|
import SlashCommand from "../lib/classes/SlashCommand";
|
||||||
|
import { Ollama } from "ollama";
|
||||||
|
|
||||||
|
const ollama = new Ollama({ host: "http://host.docker.internal:11434" });
|
||||||
|
|
||||||
|
export default class extends SlashCommand implements Command {
|
||||||
|
name = "ai";
|
||||||
|
description = "Send a message to llama3.";
|
||||||
|
options = [{ type: 3, name: "input", description: "Text input to send to llama3.", required: true }];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(interaction: Interaction) {
|
||||||
|
await interaction.defer();
|
||||||
|
|
||||||
|
const input = interaction.data?.options?.find((_) => _.name === "input")?.value as string;
|
||||||
|
let fullMessage = "";
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
const response = await ollama.chat({
|
||||||
|
model: "terrye",
|
||||||
|
messages: [{ role: "user", content: input }],
|
||||||
|
stream: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
for await (const part of response) {
|
||||||
|
fullMessage += part.message.content;
|
||||||
|
index++;
|
||||||
|
|
||||||
|
if (index % 10 === 0) await interaction.edit(fullMessage);
|
||||||
|
if (part.done) await interaction.edit(fullMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,14 +1,6 @@
|
||||||
import type { Command } from "../lib/types/command";
|
import type { Command } from "../lib/types/command";
|
||||||
import {
|
import { InteractionResponseTypes } from "@discordeno/bot";
|
||||||
MessageComponentTypes,
|
|
||||||
TextStyles,
|
|
||||||
type Interaction,
|
|
||||||
type InteractionResponse,
|
|
||||||
InteractionResponseTypes,
|
|
||||||
} from "@discordeno/bot";
|
|
||||||
import SlashCommand from "../lib/classes/SlashCommand";
|
import SlashCommand from "../lib/classes/SlashCommand";
|
||||||
import Modal from "../lib/classes/Modal";
|
|
||||||
import { collectModal } from "../lib/handlers/ModalHandler";
|
|
||||||
|
|
||||||
export default class extends SlashCommand implements Command {
|
export default class extends SlashCommand implements Command {
|
||||||
name = "default";
|
name = "default";
|
||||||
|
@ -19,7 +11,7 @@ export default class extends SlashCommand implements Command {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(interaction: Interaction) {
|
async run() {
|
||||||
return {
|
return {
|
||||||
type: InteractionResponseTypes.ChannelMessageWithSource,
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
data: { content: "my name is terry and im going to destroy thgis world" },
|
data: { content: "my name is terry and im going to destroy thgis world" },
|
||||||
|
|
|
@ -17,9 +17,10 @@ export function handle(interaction: Interaction) {
|
||||||
|
|
||||||
resolved
|
resolved
|
||||||
.run(interaction)
|
.run(interaction)
|
||||||
.then((response: InteractionResponse) =>
|
.then((response: InteractionResponse | boolean) => {
|
||||||
REST.sendInteractionResponse(interaction.id, interaction.token, response)
|
if (!response) return;
|
||||||
)
|
REST.sendInteractionResponse(interaction.id, interaction.token, response as InteractionResponse);
|
||||||
|
})
|
||||||
.catch((e: Error) => {
|
.catch((e: Error) => {
|
||||||
console.log("CommandHandler.ts -> Exception");
|
console.log("CommandHandler.ts -> Exception");
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|
2
src/lib/types/command.d.ts
vendored
2
src/lib/types/command.d.ts
vendored
|
@ -1,6 +1,6 @@
|
||||||
import { type Interaction, type InteractionCallbackData, type InteractionResponse } from "@discordeno/bot";
|
import { type Interaction, type InteractionCallbackData, type InteractionResponse } from "@discordeno/bot";
|
||||||
|
|
||||||
interface Command {
|
interface Command {
|
||||||
run(interaction: Interaction): Promise<InteractionResponse>;
|
run(interaction: Interaction): Promise<InteractionResponse | boolean>;
|
||||||
autocomplete?(interaction: Interaction): Promise<InteractionCallbackData>;
|
autocomplete?(interaction: Interaction): Promise<InteractionCallbackData>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue