(
response: LLMPredictionResponse,
{ account, communityName }: { account: accounts; communityName: string }
)
| 147 | } |
| 148 | |
| 149 | export 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) |
no test coverage detected