11import { DiscordGatewayLayer } from "@chat/discord/DiscordGateway"
22import { DiscordApplication } from "@chat/discord/DiscordRest"
33import { Messages } from "@chat/discord/Messages"
4- import { AiInput } from "@effect/ai"
4+ import { AiInput , AiLanguageModel } from "@effect/ai"
5+ import { OpenAiLanguageModel } from "@effect/ai-openai"
56import { Discord , DiscordREST , Ix } from "dfx"
67import { InteractionsRegistry } from "dfx/gateway"
78import {
@@ -13,9 +14,10 @@ import {
1314 FiberMap ,
1415 Layer ,
1516 pipe ,
17+ Schema ,
1618 Stream
1719} from "effect"
18- import { AiHelpers } from "./Ai.ts"
20+ import { OpenAiLive } from "./Ai.ts"
1921import { ChannelsCache } from "./ChannelsCache.ts"
2022import { Github } from "./Github.ts"
2123
@@ -32,11 +34,11 @@ type GithubRepo = (typeof githubRepos)[number]
3234const make = Effect . gen ( function * ( ) {
3335 const rest = yield * DiscordREST
3436 const channels = yield * ChannelsCache
35- const ai = yield * AiHelpers
3637 const messages = yield * Messages
3738 const registry = yield * InteractionsRegistry
3839 const github = yield * Github
3940 const fiberMap = yield * FiberMap . make < Discord . Snowflake > ( )
41+ const summaryModel = yield * OpenAiLanguageModel . model ( "gpt-4.1-mini" )
4042
4143 const createGithubIssue = github . wrap ( ( _ ) => _ . issues . create )
4244
@@ -59,13 +61,24 @@ const make = Effect.gen(function*() {
5961 ) ,
6062 AiInput . make
6163 )
62- const summary = yield * ai . generateSummary ( channelName , input )
64+ const summary = yield * AiLanguageModel . generateObject ( {
65+ system :
66+ `You are a helpful assistant that summarizes Discord threads into concise titles and summaries for Github issues.
67+
68+ In the summary, include some key takeaways or important points discussed in the thread.
69+
70+ The title of this conversation is: "${ channelName } "` ,
71+ prompt : input ,
72+ schema : ThreadSummary
73+ } ) . pipe (
74+ Effect . provide ( summaryModel )
75+ )
6376 return yield * createGithubIssue ( {
6477 owner : repo . owner ,
6578 repo : repo . repo ,
66- title : `From Discord: ${ channelName } ` ,
79+ title : `From Discord: ${ summary . value . title } ` ,
6780 body : `# Summary
68- ${ summary }
81+ ${ summary . value . summary }
6982
7083# Discord thread
7184
@@ -175,9 +188,21 @@ https://discord.com/channels/${channel.guild_id}/${channel.id}
175188} )
176189
177190export const IssueifierLive = Layer . scopedDiscard ( make ) . pipe (
178- Layer . provide ( AiHelpers . Default ) ,
191+ Layer . provide ( OpenAiLive ) ,
179192 Layer . provide ( ChannelsCache . Default ) ,
180193 Layer . provide ( DiscordGatewayLayer ) ,
181194 Layer . provide ( Messages . Default ) ,
182195 Layer . provide ( Github . Default )
183196)
197+
198+ class ThreadSummary extends Schema . Class < ThreadSummary > ( "ThreadSummary" ) ( {
199+ title : Schema . String . annotations ( {
200+ description : "A short title summarizing the messages"
201+ } ) ,
202+ summary : Schema . String . annotations ( {
203+ description :
204+ "A summary of the messages for a Github issue bug report or feature request"
205+ } )
206+ } , {
207+ description : "A summary of a Discord thread"
208+ } ) { }
0 commit comments