"""Prompts from evaporate repo.
Full credits go to: https://github.com/HazyResearch/evaporate
"""
from llama_index.prompts import PromptTemplate
# deprecated, kept for backward compatibility
"""Pandas PromptTemplate. Convert query to python code.
Required template variables: `chunk`, `topic`.
Args:
template (str): Template for the PromptTemplate.
**prompt_kwargs: Keyword arguments for the PromptTemplate.
"""
SchemaIDPrompt = PromptTemplate
"""Function generation PromptTemplate. Generate a function from existing text.
Required template variables: `context_str`, `query_str`,
`attribute`, `function_field`.
Args:
template (str): Template for the PromptTemplate.
**prompt_kwargs: Keyword arguments for the PromptTemplate.
"""
FnGeneratePrompt = PromptTemplate
# used for schema identification
SCHEMA_ID_PROMPT_TMPL = f"""Sample text:
| Charles III |
| Mary Simon |
Provinces and Territories
- Saskatchewan
- Manitoba
- Ontario
- Quebec
- New Brunswick
- Prince Edward Island
- Nova Scotia
- Newfoundland and Labrador
- Yukon
- Nunavut
- Northwest Territories
Question: List all relevant attributes about 'Canada' that are exactly mentioned in this sample text if any.
Answer:
- Monarch: Charles III
- Governor General: Mary Simon
- Provinces and Territories: Saskatchewan, Manitoba, Ontario, Quebec, New Brunswick, Prince Edward Island, Nova Scotia, Newfoundland and Labrador, Yukon, Nunavut, Northwest Territories
----
Sample text:
Patient birth date: 1990-01-01
Prescribed medication: aspirin, ibuprofen, acetaminophen
Prescribed dosage: 1 tablet, 2 tablets, 3 tablets
Doctor's name: Dr. Burns
Date of discharge: 2020-01-01
Hospital address: 123 Main Street, New York, NY 10001
Question: List all relevant attributes about 'medications' that are exactly mentioned in this sample text if any.
Answer:
- Prescribed medication: aspirin, ibuprofen, acetaminophen
- Prescribed dosage: 1 tablet, 2 tablets, 3 tablets
----
Sample text:
{{chunk:}}
Question: List all relevant attributes about '{{topic:}}' that are exactly mentioned in this sample text if any.
Answer:"""
SCHEMA_ID_PROMPT = PromptTemplate(SCHEMA_ID_PROMPT_TMPL)
# used for function generation
FN_GENERATION_PROMPT_TMPL = f"""Here is a sample of text:
{{context_str:}}
Question: {{query_str:}}
Given the function signature, write Python code to extract the
"{{attribute:}}" field from the text.
Return the result as a single value (string, int, float), and not a list.
Make sure there is a return statement in the code. Do not leave out a return statement.
{{expected_output_str:}}
import re
def get_{{function_field:}}_field(text: str):
\"""
Function to extract the "{{attribute:}} field", and return the result
as a single value.
\"""
"""
FN_GENERATION_PROMPT = PromptTemplate(FN_GENERATION_PROMPT_TMPL)
FN_GENERATION_LIST_PROMPT_TMPL = f"""Here is a sample of text:
{{context_str:}}
Question: {{query_str:}}
Given the function signature, write Python code to extract the
"{{attribute:}}" field from the text.
Return the result as a list of values (if there is just one item, return a single \
element list).
Make sure there is a return statement in the code. Do not leave out a return statement.
{{expected_output_str:}}
import re
def get_{{function_field:}}_field(text: str) -> List:
\"""
Function to extract the "{{attribute:}} field", and return the result
as a single value.
\"""
"""
FN_GENERATION_LIST_PROMPT = PromptTemplate(FN_GENERATION_LIST_PROMPT_TMPL)
DEFAULT_EXPECTED_OUTPUT_PREFIX_TMPL = (
"Here is the expected output on the text after running the function. "
"Please do not write a function that would return a different output. "
"Expected output: "
)
DEFAULT_FIELD_EXTRACT_QUERY_TMPL = (
'Write a python function to extract the entire "{field}" field from text, '
"but not any other metadata. Return the result as a list."
)