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

Function parseBody

packages/queue/src/tasks/llm/index.ts:149–190  ·  view source on GitHub ↗
(
  response: LLMPredictionResponse,
  { account, communityName }: { account: accounts; communityName: string }
)

Source from the content-addressed store, hash-verified

147}
148
149export async function parseBody(
150 response: LLMPredictionResponse,
151 { account, communityName }: { account: accounts; communityName: string }
152): Promise<string> {
153 // TODO: if is a url, show it, otherwise, it will be a threadId, we should build the url
154 // TODO https urls should not be wrapped by <>
155 const references = getReferences(response.sourceDocuments);
156 const urls = getUrls(references);
157 const threadIds = getThreadIds(references);
158 const threads = await prisma.threads.findMany({
159 where: {
160 id: { in: threadIds },
161 },
162 });
163
164 const threadUrls = threads.map((thread) => {
165 return getThreadUrl({
166 isSubDomainRouting: true,
167 slug: thread.slug,
168 incrementId: thread.incrementId,
169 settings: {
170 communityName,
171 redirectDomain: account.redirectDomain as string | undefined,
172 },
173 LINEN_URL:
174 process.env.NODE_ENV === 'development'
175 ? 'http://localhost:3000'
176 : 'https://www.linen.dev',
177 });
178 });
179
180 const refs = [...urls, ...threadUrls];
181
182 if (refs.length > 0) {
183 return [
184 response.text,
185 'References:',
186 [...urls, ...threadUrls].map((source) => `- ${source}`).join('\n'),
187 ].join('\n\n');
188 }
189 return response.text;
190}
191
192// TODO: follow up (replies)

Callers 2

index.test.tsFile · 0.85
llmQuestionFunction · 0.85

Calls 5

getThreadUrlFunction · 0.90
getReferencesFunction · 0.85
getUrlsFunction · 0.85
getThreadIdsFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected