-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tim <[email protected]>
- Loading branch information
Showing
9 changed files
with
283 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { AiInput, Completions, Tokenizer } from "@effect/ai" | ||
import { AiHelpers, CompletionsLive } from "bot/Ai" | ||
import { ChannelsCache } from "bot/ChannelsCache" | ||
import { DiscordApplication, DiscordLive } from "bot/Discord" | ||
import { NotInThreadError } from "bot/Summarizer" | ||
import { Discord, DiscordREST, Ix } from "dfx" | ||
import { InteractionsRegistry } from "dfx/gateway" | ||
import { Effect, Layer } from "effect" | ||
|
||
const systemInstruction = `You are Effect Bot, a helpful assistant for the Effect Discord community. | ||
Generate a light-hearted, comedic message to the user based on the included conversation indicating that, without a minimal reproduction of the described issue, the Effect team will not be able to further investigate. | ||
Your message should in no way be offensive to the user.` | ||
|
||
const make = Effect.gen(function* () { | ||
const ai = yield* AiHelpers | ||
const channels = yield* ChannelsCache | ||
const completions = yield* Completions.Completions | ||
const registry = yield* InteractionsRegistry | ||
const tokenizer = yield* Tokenizer.Tokenizer | ||
const discord = yield* DiscordREST | ||
const application = yield* DiscordApplication | ||
const scope = yield* Effect.scope | ||
|
||
const command = Ix.global( | ||
{ | ||
name: "repro", | ||
description: | ||
"Generate a message indicating that reproduction is required", | ||
}, | ||
Effect.gen(function* () { | ||
const context = yield* Ix.Interaction | ||
const channel = yield* channels.get( | ||
context.guild_id!, | ||
context.channel_id!, | ||
) | ||
if (channel.type !== Discord.ChannelType.PUBLIC_THREAD) { | ||
return yield* new NotInThreadError() | ||
} | ||
yield* respond(channel, context).pipe(Effect.forkIn(scope)) | ||
return Ix.response({ | ||
type: Discord.InteractionCallbackType | ||
.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, | ||
}) | ||
}).pipe( | ||
Effect.annotateLogs("command", "repro"), | ||
Effect.withSpan("ReproRequester.command"), | ||
), | ||
) | ||
|
||
const respond = (channel: Discord.Channel, context: Discord.Interaction) => | ||
Effect.gen(function* () { | ||
const input = yield* ai.generateAiInput(channel) | ||
const content = yield* tokenizer.truncate(input, 30_000).pipe( | ||
Effect.flatMap(completions.create), | ||
Effect.map(response => response.text), | ||
AiInput.provideSystem(systemInstruction), | ||
Effect.annotateLogs({ | ||
thread: channel.id, | ||
}), | ||
) | ||
yield* discord.editOriginalInteractionResponse( | ||
application.id, | ||
context.token, | ||
{ content }, | ||
) | ||
}).pipe( | ||
Effect.withSpan("ReproRequester.respond", { | ||
attributes: { channel: channel.id }, | ||
}), | ||
) | ||
|
||
const ix = Ix.builder | ||
.add(command) | ||
.catchTagRespond("NotInThreadError", () => | ||
Effect.succeed( | ||
Ix.response({ | ||
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: "This command can only be used in a thread", | ||
flags: Discord.MessageFlag.EPHEMERAL, | ||
}, | ||
}), | ||
), | ||
) | ||
.catchAllCause(Effect.logError) | ||
|
||
yield* registry.register(ix) | ||
}) | ||
|
||
export const ReproRequesterLive = Layer.scopedDiscard(make).pipe( | ||
Layer.provide(AiHelpers.Default), | ||
Layer.provide(ChannelsCache.Default), | ||
Layer.provide(CompletionsLive), | ||
Layer.provide(DiscordLive), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters