Skip to content

Commit 2e462c3

Browse files
committed
Split out custom prompts into separate prompts.py
1 parent 4205155 commit 2e462c3

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

app.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import uuid
66
import httpx
77
from datetime import datetime, timezone
8+
from prompts import prompts
89
from quart import (
910
Blueprint,
1011
Quart,
@@ -464,15 +465,16 @@ async def get_search_results(searches):
464465

465466
async def identify_searches(request_body, request_headers, Summaries = None):
466467
if (len(request_body.get("messages")) > 2):
468+
print(f"request_body: {request_body}")
467469
# for now only search on the first message until I can figure this out - apparently we can't just replace the system prompt once the conversation is rolling...
468470
return None
469471
#print(f"on replies now..")
470472
#system_message = "Do you need to do any searching to answer the latest chat message? If so provide a comma delimited list of searches you would like me to perform for you to give you all the background data and links you need. If you can answer with full confidence without any searches, then reply with simply 'No searches required.'.\n\n"
471473
else:
472474
if Summaries is None:
473-
system_preamble = "The Original System Prompt that follows is your primary objective, but for this chat, you just need to provide a list of a few searches you might need me to perform in order to respond to the current user message, while documenting reference links to any claims you make, as specified in the Original System Prompt. If you can answer with full confidence without any searches, then reply with simply 'No searches required.'. Otherwise, send a comma delimited array of searches with one or several searches you would like me to perform for you to give you all the background data and links you need to respond. Do nothing else but provide the array of search strings or the 'No searches required.' message.\nOriginal System Prompt:\n"
475+
system_preamble = prompts["identify_searches"];
474476
else:
475-
system_preamble = "The Original System Prompt that follows is your primary objective, but for this chat, you just need to provide a list of a few additional searches you need me to perform in order to fully research and document your response to the user message. If you can answer with full confidence without any searches, then reply with simply 'No searches required.'. Otherwise, send a comma delimited array with one or several new searches you would like me to perform for you to give you all the background data and links you need. Do nothing else but provide the array of search strings or the 'No searches required.' message. Existing gathered background data that you determined was insufficient so far to answer follows.\n\nExisting Background Data:\n\n" + json.dumps(Summaries, indent=4) + "\n\nOriginal System Prompt:\n"
477+
system_preamble = prompts["identify_additional_searches"] + json.dumps(Summaries, indent=4) + "\n\nOriginal System Prompt:\n"
476478
searches = await send_private_chat(request_body, request_headers, system_preamble)
477479
if isinstance(searches, str):
478480
if searches == "No searches required.":
@@ -492,7 +494,7 @@ async def get_urls_to_browse(request_body, request_headers, searches):
492494
return "Search error."
493495
else:
494496
strsearchresults = json.dumps(searchresults, indent=4)
495-
system_prompt = "You are tasked with helping content developers resolve customer feedback on their content on learn.microsoft.com. Right now, you've searched and identified the following list of potential URLs for further research. Return nothing except an array of strings, with each string being a URL we should browse to research further, so we can fully answer and document sources if necessary. Here is the summary of the possible sites we can browse:\n\n" + strsearchresults
497+
system_prompt = prompts["get_urls_to_browse"] + strsearchresults
496498
URLsToBrowse = await send_private_chat(request_body, request_headers, None, system_prompt)
497499
return URLsToBrowse
498500

@@ -511,7 +513,7 @@ async def get_article_summaries(request_body, request_headers, URLsToBrowse):
511513

512514
async def is_background_info_sufficient(request_body, request_headers, Summaries):
513515
strSummaries = json.dumps(Summaries, indent=4)
514-
system_prompt = "You are tasked with helping content developers resolve customer feedback on their content on learn.microsoft.com. Right now, you've summarized the content of the URLs you've identified for further research. Review the summaries below and determine if you have enough background information to fully address the feedback on the URL provided by the user and document current sources. If you need more information, reply with 'More information needed.' If you have enough information, reply with 'Sufficient information.'\n\n" + strSummaries
516+
system_prompt = prompts["is_background_info_sufficient"] + strSummaries
515517
response = await send_private_chat(request_body, request_headers, None, system_prompt)
516518
if response == "More information needed.":
517519
return False
@@ -546,15 +548,15 @@ async def search_and_add_background_references(request_body, request_headers):
546548
if AreWeDone:
547549
NeedsMoreSummaries = False
548550

549-
return "Use the following background references to thoroughly document your answer for the customer in the Primary System Message at the end.\n\nBackground References:\n\n" + json.dumps(Summaries, indent=4) + "\n\nPrimary System Message:"
551+
return prompts["background_info_preamble"] + json.dumps(Summaries, indent=4) + "\n\nPrimary System Message:"
550552

551553
async def conversation_internal(request_body, request_headers):
552554
try:
553555
system_preamble = await search_and_add_background_references(request_body, request_headers)
554556
if system_preamble != "Search error.":
555557
result = await stream_chat_request(request_body, request_headers, system_preamble)
556558
else:
557-
result = await stream_chat_request(request_body, request_headers, "NOTE: An error occurred while searching for background information. Please inform the user that you were unable to search to validate results, but do your best to answer regardless.\n\nPrimary System Message:\n\n")
559+
result = await stream_chat_request(request_body, request_headers, prompts["search_error_preamble"])
558560
response = await make_response(format_as_ndjson(result))
559561
response.timeout = None
560562
response.mimetype = "application/json-lines"

prompts.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
prompts = {
2+
"identify_searches":
3+
4+
"The Original System Prompt that follows is your primary objective, but for this chat, you just need to provide a list of a few searches you might need me to perform in order to respond to the current user message, while documenting reference links to any claims you make, as specified in the Original System Prompt. If you can answer with full confidence without any searches, then reply with simply 'No searches required.'. Otherwise, send a comma delimited array of searches with one or several searches you would like me to perform for you to give you all the background data and links you need to respond. Do nothing else but provide the array of search strings or the 'No searches required.' message.\nOriginal System Prompt:\n",
5+
6+
"identify_additional_searches":
7+
8+
"The Original System Prompt that follows is your primary objective, but for this chat, you just need to provide a list of a few additional searches you need me to perform in order to fully research and document your response to the user message. If you can answer with full confidence without any searches, then reply with simply 'No searches required.'. Otherwise, send a comma delimited array with one or several new searches you would like me to perform for you to give you all the background data and links you need. Do nothing else but provide the array of search strings or the 'No searches required.' message. Existing gathered background data that you determined was insufficient so far to answer follows.\n\nExisting Background Data:\n\n",
9+
10+
"get_urls_to_browse":
11+
12+
"You are tasked with helping content developers resolve customer feedback on their content on learn.microsoft.com. Right now, you've searched and identified the following list of potential URLs for further research. Return nothing except an array of strings, with each string being a URL we should browse to research further, so we can fully answer and document sources if necessary. Here is the summary of the possible sites we can browse:\n\n",
13+
14+
"get_article_summaries":
15+
16+
"EMPTY_FOR_NOW",
17+
18+
"is_background_info_sufficient":
19+
20+
"You are tasked with helping content developers resolve customer feedback on their content on learn.microsoft.com. Right now, you've summarized the content of the URLs you've identified for further research. Review the summaries below and determine if you have enough background information to fully address the feedback on the URL provided by the user and document current sources. If you need more information, reply with 'More information needed.' If you have enough information, reply with 'Sufficient information.'\n\n",
21+
22+
"background_info_preamble":
23+
"Use the following background references to thoroughly document your answer for the customer as described in the Primary System Message at the end.\n\nBackground References:\n\n",
24+
25+
"search_error_preamble":
26+
27+
"NOTE: An error occurred while searching for background information. Please inform the user that you were unable to search to validate results, but do your best to answer regardless.\n\nPrimary System Message:\n\n"
28+
}

0 commit comments

Comments
 (0)