Skip to content

Commit

Permalink
Fix ask prompts to allow prompt override/injection (#2277)
Browse files Browse the repository at this point in the history
* Configure Azure Developer Pipeline

* Add prompt override/inject to Ask tab, add to tests
  • Loading branch information
pamelafox authored Jan 16, 2025
1 parent 3629df8 commit a0cbcf5
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 11 deletions.
9 changes: 9 additions & 0 deletions app/backend/approaches/approach.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ async def compute_image_embedding(self, q: str):
image_query_vector = json["vector"]
return VectorizedQuery(vector=image_query_vector, k_nearest_neighbors=50, fields="imageEmbedding")

def get_system_prompt_variables(self, override_prompt: Optional[str]) -> dict[str, str]:
# Allows client to replace the entire prompt, or to inject into the existing prompt using >>>
if override_prompt is None:
return {}
elif override_prompt.startswith(">>>"):
return {"injected_prompt": override_prompt[3:]}
else:
return {"override_prompt": override_prompt}

async def run(
self,
messages: list[ChatCompletionMessageParam],
Expand Down
9 changes: 0 additions & 9 deletions app/backend/approaches/chatapproach.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ class ChatApproach(Approach, ABC):
async def run_until_final_call(self, messages, overrides, auth_claims, should_stream) -> tuple:
pass

def get_system_prompt_variables(self, override_prompt: Optional[str]) -> dict[str, str]:
# Allows client to replace the entire prompt, or to inject into the existing prompt using >>>
if override_prompt is None:
return {}
elif override_prompt.startswith(">>>"):
return {"injected_prompt": override_prompt[3:]}
else:
return {"override_prompt": override_prompt}

def get_search_query(self, chat_completion: ChatCompletion, user_query: str):
response_message = chat_completion.choices[0].message

Expand Down
6 changes: 6 additions & 0 deletions app/backend/approaches/prompts/ask_answer_question.prompty
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ sample:
- "role_library.pdf#page=23: Company: Contoso Electronics Location: Anywhere Job Type: Full-Time Salary: Competitive, commensurate with experience Job Summary: The Senior Manager of Product Management will be responsible for leading the product management team at Contoso Electronics. This role includes developing strategies, plans and objectives for the product management team and managing the day-to-day operations. The Senior Manager of Product Management will be responsible for the successful launch of new products and the optimization of existing products. Responsibilities: · Develop and implement product management strategies, plans and objectives to maximize team performance. · Analyze competitive landscape and market trends to develop product strategies. · Lead the product management team in the development of product plans, roadmaps and launch plans. · Monitor the performance of product management team, analyze results and implement corrective action as needed. · Manage the product lifecycle, including product development, launch, and end of life. · Ensure product features and benefits meet customer requirements. · Establish and maintain relationships with key customers, partners, and vendors."
- "role_library.pdf#page=28: · 7+ years of experience in research and development in the electronics sector. · Proven track record of successfully designing, testing, and optimizing products. · Experience leading a team of researchers and engineers. · Excellent problem-solving and analytical skills. · Ability to work in a fast-paced environment and meet tight deadlines.· Knowledge of industry trends, technologies, and regulations. · Excellent communication and presentation skills. Manager of Product Management Job Title: Manager of Product Management, Contoso Electronics Job Summary: The Manager of Product Management is responsible for overseeing the product management team, driving product development and marketing strategy for Contoso Electronics. This individual will be accountable for the successful launch of new products and the implementation of product life-cycle management processes. The Manager of Product Management will collaborate with internal teams, such as engineering, sales, marketing, and finance, as well as external partners, suppliers, and customers to ensure successful product execution."
---
system:
{% if override_prompt %}
{{ override_prompt }}
{% else %}
You are an intelligent assistant helping Contoso Inc employees with their healthcare plan questions and employee handbook questions.
Use 'you' to refer to the individual asking the questions even if they ask with 'I'.
Answer the following question using only the data provided in the sources below.
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.
If you cannot answer using the sources below, say you don't know. Use below example to answer
{{ injected_prompt }}
{% endif %}

user:
(EXAMPLE) What is the deductible for the employee plan for a visit to Overlake in Bellevue?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ description: Answer a single question (with no chat history) using both text and
model:
api: chat
---
system:
{% if override_prompt %}
{{ override_prompt }}
{% else %}
You are an intelligent assistant helping analyze the Annual Financial Report of Contoso Ltd., The documents contain text, graphs, tables and images.
Each image source has the file name in the top left corner of the image with coordinates (10,10) pixels and is in the format SourceFileName:<file_name>.
Each text source starts in a new line and has the file name followed by colon and the actual information.
Always include the source name from the image or text for each fact you use in the response in the format: [filename].
Answer the following question using only the data provided in the sources below.
The text and image source can be the same file name, don't use the image title when citing the image source, only use the file name as mentioned.
If you cannot answer using the sources below, say you don't know. Return just the answer without any input texts.
{{ injected_prompt }}
{% endif %}

user:
{{ user_query }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sample:
- "role_library.pdf#page=23: Company: Contoso Electronics Location: Anywhere Job Type: Full-Time Salary: Competitive, commensurate with experience Job Summary: The Senior Manager of Product Management will be responsible for leading the product management team at Contoso Electronics. This role includes developing strategies, plans and objectives for the product management team and managing the day-to-day operations. The Senior Manager of Product Management will be responsible for the successful launch of new products and the optimization of existing products. Responsibilities: · Develop and implement product management strategies, plans and objectives to maximize team performance. · Analyze competitive landscape and market trends to develop product strategies. · Lead the product management team in the development of product plans, roadmaps and launch plans. · Monitor the performance of product management team, analyze results and implement corrective action as needed. · Manage the product lifecycle, including product development, launch, and end of life. · Ensure product features and benefits meet customer requirements. · Establish and maintain relationships with key customers, partners, and vendors."
- "role_library.pdf#page=28: · 7+ years of experience in research and development in the electronics sector. · Proven track record of successfully designing, testing, and optimizing products. · Experience leading a team of researchers and engineers. · Excellent problem-solving and analytical skills. · Ability to work in a fast-paced environment and meet tight deadlines.· Knowledge of industry trends, technologies, and regulations. · Excellent communication and presentation skills. Manager of Product Management Job Title: Manager of Product Management, Contoso Electronics Job Summary: The Manager of Product Management is responsible for overseeing the product management team, driving product development and marketing strategy for Contoso Electronics. This individual will be accountable for the successful launch of new products and the implementation of product life-cycle management processes. The Manager of Product Management will collaborate with internal teams, such as engineering, sales, marketing, and finance, as well as external partners, suppliers, and customers to ensure successful product execution."
---
system:
{% if override_prompt %}
{{ override_prompt }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: Answer a question (with chat history) using both text and image sou
model:
api: chat
---
system:
{% if override_prompt %}
{{ override_prompt }}
{% else %}
Expand Down
4 changes: 3 additions & 1 deletion app/backend/approaches/retrievethenread.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ async def run(
# Process results
text_sources = self.get_sources_content(results, use_semantic_captions, use_image_citation=False)
rendered_answer_prompt = self.prompt_manager.render_prompt(
self.answer_prompt, {"user_query": q, "text_sources": text_sources}
self.answer_prompt,
self.get_system_prompt_variables(overrides.get("prompt_template"))
| {"user_query": q, "text_sources": text_sources},
)

chat_completion = await self.openai_client.chat.completions.create(
Expand Down
4 changes: 3 additions & 1 deletion app/backend/approaches/retrievethenreadvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ async def run(
image_sources.append(url)

rendered_answer_prompt = self.prompt_manager.render_prompt(
self.answer_prompt, {"user_query": q, "text_sources": text_sources, "image_sources": image_sources}
self.answer_prompt,
self.get_system_prompt_variables(overrides.get("prompt_template"))
| {"user_query": q, "text_sources": text_sources, "image_sources": image_sources},
)

chat_completion = await self.openai_client.chat.completions.create(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"context": {
"data_points": {
"text": [
"Benefit_Options-2.pdf: There is a whistleblower policy."
]
},
"thoughts": [
{
"description": "What is the capital of France?",
"props": {
"filter": null,
"top": 3,
"use_semantic_captions": false,
"use_semantic_ranker": false,
"use_text_search": true,
"use_vector_search": false
},
"title": "Search using user query"
},
{
"description": [
{
"captions": [
{
"additional_properties": {},
"highlights": [],
"text": "Caption: A whistleblower policy."
}
],
"category": null,
"content": "There is a whistleblower policy.",
"embedding": null,
"groups": null,
"id": "file-Benefit_Options_pdf-42656E656669745F4F7074696F6E732E706466-page-2",
"imageEmbedding": null,
"oids": null,
"reranker_score": 3.4577205181121826,
"score": 0.03279569745063782,
"sourcefile": "Benefit_Options.pdf",
"sourcepage": "Benefit_Options-2.pdf"
}
],
"props": null,
"title": "Search results"
},
{
"description": [
{
"content": "You are a cat.",
"role": "system"
},
{
"content": "What is the deductible for the employee plan for a visit to Overlake in Bellevue?\n\nSources:\ninfo1.txt: deductibles depend on whether you are in-network or out-of-network. In-network deductibles are $500 for employee and $1000 for family. Out-of-network deductibles are $1000 for employee and $2000 for family.\ninfo2.pdf: Overlake is in-network for the employee plan.\ninfo3.pdf: Overlake is the name of the area that includes a park and ride near Bellevue.\ninfo4.pdf: In-network institutions include Overlake, Swedish and others in the region.",
"role": "user"
},
{
"content": "In-network deductibles are $500 for employee and $1000 for family [info1.txt] and Overlake is in-network for the employee plan [info2.pdf][info4.pdf].",
"role": "assistant"
},
{
"content": "What is the capital of France?\nSources:\n\nBenefit_Options-2.pdf: There is a whistleblower policy.",
"role": "user"
}
],
"props": {
"model": "gpt-35-turbo"
},
"title": "Prompt to generate answer"
}
]
},
"message": {
"content": "The capital of France is Paris. [Benefit_Options-2.pdf].",
"role": "assistant"
},
"session_state": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"context": {
"data_points": {
"text": [
"Benefit_Options-2.pdf: There is a whistleblower policy."
]
},
"thoughts": [
{
"description": "What is the capital of France?",
"props": {
"filter": null,
"top": 3,
"use_semantic_captions": false,
"use_semantic_ranker": false,
"use_text_search": true,
"use_vector_search": false
},
"title": "Search using user query"
},
{
"description": [
{
"captions": [
{
"additional_properties": {},
"highlights": [],
"text": "Caption: A whistleblower policy."
}
],
"category": null,
"content": "There is a whistleblower policy.",
"embedding": null,
"groups": null,
"id": "file-Benefit_Options_pdf-42656E656669745F4F7074696F6E732E706466-page-2",
"imageEmbedding": null,
"oids": null,
"reranker_score": 3.4577205181121826,
"score": 0.03279569745063782,
"sourcefile": "Benefit_Options.pdf",
"sourcepage": "Benefit_Options-2.pdf"
}
],
"props": null,
"title": "Search results"
},
{
"description": [
{
"content": "You are a cat.",
"role": "system"
},
{
"content": "What is the deductible for the employee plan for a visit to Overlake in Bellevue?\n\nSources:\ninfo1.txt: deductibles depend on whether you are in-network or out-of-network. In-network deductibles are $500 for employee and $1000 for family. Out-of-network deductibles are $1000 for employee and $2000 for family.\ninfo2.pdf: Overlake is in-network for the employee plan.\ninfo3.pdf: Overlake is the name of the area that includes a park and ride near Bellevue.\ninfo4.pdf: In-network institutions include Overlake, Swedish and others in the region.",
"role": "user"
},
{
"content": "In-network deductibles are $500 for employee and $1000 for family [info1.txt] and Overlake is in-network for the employee plan [info2.pdf][info4.pdf].",
"role": "assistant"
},
{
"content": "What is the capital of France?\nSources:\n\nBenefit_Options-2.pdf: There is a whistleblower policy.",
"role": "user"
}
],
"props": {
"deployment": "test-chatgpt",
"model": "gpt-35-turbo"
},
"title": "Prompt to generate answer"
}
]
},
"message": {
"content": "The capital of France is Paris. [Benefit_Options-2.pdf].",
"role": "assistant"
},
"session_state": null
}
Loading

0 comments on commit a0cbcf5

Please sign in to comment.