| 135 | |
| 136 | @measure |
| 137 | private static async askLLM({ |
| 138 | query, |
| 139 | vectorStore, |
| 140 | }: { |
| 141 | query: string; |
| 142 | vectorStore: FaissStore; |
| 143 | }) { |
| 144 | const template = `Use the following pieces of context to answer the question at the end. |
| 145 | If you don't know the answer, just say that you don't know, DON'T try to make up an answer. |
| 146 | Keep the answer as concise as possible. |
| 147 | DON'T crop the answer, ensure the answer is complete. |
| 148 | No need to say "thanks for asking!" in the answer. |
| 149 | Context: {context} |
| 150 | Question: {question} |
| 151 | Helpful Answer:`; |
| 152 | |
| 153 | const chain = RetrievalQAChain.fromLLM( |
| 154 | model, |
| 155 | vectorStore.asRetriever({ k: env.CHUNKS * 2 }), |
| 156 | { |
| 157 | prompt: PromptTemplate.fromTemplate(template), |
| 158 | returnSourceDocuments: true, |
| 159 | } |
| 160 | ); |
| 161 | |
| 162 | const response = await chain.call({ |
| 163 | query, |
| 164 | }); |
| 165 | return response; |
| 166 | } |
| 167 | |
| 168 | @measure |
| 169 | private static async crawl(url: string, options: CrawlOptions) { |