You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/backend/approaches/chatreadretrieveread.py
+83-21Lines changed: 83 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,30 @@
1
1
fromtypingimportAny, Sequence
2
2
3
3
importopenai
4
+
importtiktoken
4
5
fromazure.search.documentsimportSearchClient
5
6
fromazure.search.documents.modelsimportQueryType
6
7
fromapproaches.approachimportApproach
7
8
fromtextimportnonewlines
8
9
9
10
classChatReadRetrieveReadApproach(Approach):
11
+
# Chat roles
12
+
SYSTEM="system"
13
+
USER="user"
14
+
ASSISTANT="assistant"
15
+
10
16
"""
11
17
Simple retrieve-then-read implementation, using the Cognitive Search and OpenAI APIs directly. It first retrieves
12
18
top documents from search, then constructs a prompt with them, and then uses OpenAI to generate an completion
13
19
(answer) with that prompt.
14
20
"""
15
-
16
-
prompt_prefix="""<|im_start|>system
17
-
Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.
21
+
system_message_chat_conversation="""Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.
18
22
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.
19
23
For tabular information return it as an html table. Do not return markdown format.
20
24
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].
21
25
{follow_up_questions_prompt}
22
26
{injected_prompt}
23
-
Sources:
24
-
{sources}
25
-
<|im_end|>
26
-
{chat_history}
27
27
"""
28
-
29
28
follow_up_questions_prompt_content="""Generate three very brief follow-up questions that the user would likely ask next about their healthcare plan and employee handbook.
30
29
Use double angle brackets to reference the questions, e.g. <<Are there exclusions for prescriptions?>>.
31
30
Try not to repeat questions that have already been asked.
@@ -46,9 +45,10 @@ class ChatReadRetrieveReadApproach(Approach):
0 commit comments