MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / llmQuestion

Function llmQuestion

packages/queue/src/tasks/llm/index.ts:60–124  ·  view source on GitHub ↗
(payload: any, helpers: JobHelpers)

Source from the content-addressed store, hash-verified

58}
59
60export const llmQuestion = async (payload: any, helpers: JobHelpers) => {
61 const logger = new Logger(helpers.logger);
62
63 logger.info(payload);
64
65 try {
66 const parsedPayload = z
67 .object({
68 accountId: z.string().uuid(),
69 authorId: z.string().uuid(),
70 channelId: z.string().uuid(),
71 threadId: z.string().uuid(),
72 communityName: z.string(),
73 })
74 .parse(payload);
75
76 const { accountId, authorId, channelId, threadId, communityName } =
77 parsedPayload;
78
79 const thread = await prisma.threads.findUniqueOrThrow({
80 include: { messages: true, channel: true },
81 where: { id: threadId },
82 });
83
84 logger.info({ llm: `found thread ${thread.id}` });
85
86 const llmResponse = await llmPredict({
87 communityName,
88 query: thread.messages.map((m) => m.body).join(' '),
89 threadId: thread.id,
90 });
91
92 logger.info({ llm: `llm response ready` });
93
94 const threadAccountId = thread.channel.accountId;
95
96 if (threadAccountId) {
97 const account = await prisma.accounts.findUnique({
98 where: {
99 id: threadAccountId,
100 },
101 });
102
103 if (account) {
104 const body = await parseBody(llmResponse, { account, communityName });
105
106 logger.info({
107 llm: `creating a new linen message for thread ${threadId}`,
108 });
109
110 await linenSdk.createNewMessage({
111 accountId,
112 authorId,
113 body,
114 channelId,
115 externalMessageId: crypto.randomUUID(),
116 threadId,
117 messageFormat: MessageFormat.LINEN,

Callers

nothing calls this directly

Calls 6

infoMethod · 0.95
errorMethod · 0.95
llmPredictFunction · 0.85
parseBodyFunction · 0.85
mapMethod · 0.80
createNewMessageMethod · 0.80

Tested by

no test coverage detected