Skip to content

Commit 57b1091

Browse files
committed
feat(search): improve chat prompts
1 parent fd8a3bf commit 57b1091

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

packages/search/src/lib/approaches/chat-read-retrieve-read.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ import { getTokenLimit } from '../tokens.js';
1414
const SYSTEM_MESSAGE_CHAT_CONVERSATION = `Assistant helps the Consto Real Estate company customers with support questions regarding terms of service, privacy policy, and questions about support requests. Be brief in your answers.
1515
Answer ONLY with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. Do not generate answers that don't use the sources below. If asking a clarifying question to the user would help, ask the question.
1616
For tabular information return it as an html table. Do not return markdown format. If the question is not in English, answer in the language used in the question.
17-
Each source has a name followed by colon and the actual information, always include the source name for each fact you use in the response. Use square brackets to reference the source, e.g. [info1.txt]. Don't combine sources, list each source separately, e.g. [info1.txt][info2.pdf].
17+
Each source has a name followed by colon and the actual information, always include the source name for each fact you use in the response. Use square brackets to reference the source, for example: [info1.txt]. Don't combine sources, list each source separately, for example: [info1.txt][info2.pdf].
1818
{follow_up_questions_prompt}
1919
{injected_prompt}
2020
`;
2121

22-
const FOLLOW_UP_QUESTIONS_PROMPT_CONTENT = `Generate three very brief follow-up questions that the user would likely ask next about rentals.
23-
Use double angle brackets to reference the questions, e.g. <<Am I allowed to invite friends for a party?>>.
24-
Try not to repeat questions that have already been asked.
25-
Only generate questions and do not generate any text before or after the questions, such as 'Next Questions'`;
22+
const FOLLOW_UP_QUESTIONS_PROMPT_CONTENT = `Generate 3 very brief follow-up questions that the user would likely ask next.
23+
Enclose the follow-up questions in double angle brackets. Example:
24+
<<Am I allowed to invite friends for a party?>>
25+
<<How can I ask for a refund?>>
26+
<<What If I break something?>>
27+
28+
Do no repeat questions that have already been asked.
29+
Make sure the last question ends with ">>".`;
2630

2731
const QUERY_PROMPT_TEMPLATE = `Below is a history of the conversation so far, and a new question asked by the user that needs to be answered by searching in a knowledge base about terms of service, privacy policy, and questions about support requests.
2832
Generate a search query based on the conversation and the new question.
@@ -188,7 +192,15 @@ export class ChatReadRetrieveRead extends ApproachBase implements ChatApproach {
188192
this.chatGptTokenLimit,
189193
);
190194

191-
const messageToDisplay = messagesToString(messages);
195+
const firstQuery = messagesToString(messages);
196+
const secondQuery = messagesToString(finalMessages);
197+
const thoughts = `Search query:
198+
${query}
199+
200+
Conversations:
201+
${firstQuery}
202+
203+
${secondQuery}`.replaceAll('\n', '<br>');
192204

193205
return {
194206
completionRequest: {
@@ -199,7 +211,7 @@ export class ChatReadRetrieveRead extends ApproachBase implements ChatApproach {
199211
n: 1,
200212
},
201213
dataPoints: results,
202-
thoughts: `Searched for:<br>${query}<br><br>Conversations:<br>${messageToDisplay.replace('\n', '<br>')}`,
214+
thoughts,
203215
};
204216
}
205217

0 commit comments

Comments
 (0)