llama-index

Форк
0
1
"""Prompts from evaporate repo.
2

3

4
Full credits go to: https://github.com/HazyResearch/evaporate
5

6

7
"""
8

9
from llama_index.legacy.prompts import PromptTemplate
10

11
# deprecated, kept for backward compatibility
12

13
"""Pandas PromptTemplate. Convert query to python code.
14

15
Required template variables: `chunk`, `topic`.
16

17
Args:
18
    template (str): Template for the PromptTemplate.
19
    **prompt_kwargs: Keyword arguments for the PromptTemplate.
20

21
"""
22
SchemaIDPrompt = PromptTemplate
23

24
"""Function generation PromptTemplate. Generate a function from existing text.
25

26
Required template variables: `context_str`, `query_str`,
27
    `attribute`, `function_field`.
28

29
Args:
30
    template (str): Template for the PromptTemplate.
31
    **prompt_kwargs: Keyword arguments for the PromptTemplate.
32

33
"""
34
FnGeneratePrompt = PromptTemplate
35

36
# used for schema identification
37
SCHEMA_ID_PROMPT_TMPL = f"""Sample text:
38
<tr class="mergedrow"><th scope="row" class="infobox-label"><div style="text-indent:-0.9em;margin-left:1.2em;font-weight:normal;">•&nbsp;<a href="/wiki/Monarchy_of_Canada" title="Monarchy of Canada">Monarch</a> </div></th><td class="infobox-data"><a href="/wiki/Charles_III" title="Charles III">Charles III</a></td></tr>
39
<tr class="mergedrow"><th scope="row" class="infobox-label"><div style="text-indent:-0.9em;margin-left:1.2em;font-weight:normal;">•&nbsp;<span class="nowrap"><a href="/wiki/Governor_General_of_Canada" title="Governor General of Canada">Governor General</a></span> </div></th><td class="infobox-data"><a href="/wiki/Mary_Simon" title="Mary Simon">Mary Simon</a></td></tr>
40
<b>Provinces and Territories</b class='navlinking countries'>
41
<ul>
42
<li>Saskatchewan</li>
43
<li>Manitoba</li>
44
<li>Ontario</li>
45
<li>Quebec</li>
46
<li>New Brunswick</li>
47
<li>Prince Edward Island</li>
48
<li>Nova Scotia</li>
49
<li>Newfoundland and Labrador</li>
50
<li>Yukon</li>
51
<li>Nunavut</li>
52
<li>Northwest Territories</li>
53
</ul>
54

55
Question: List all relevant attributes about 'Canada' that are exactly mentioned in this sample text if any.
56
Answer:
57
- Monarch: Charles III
58
- Governor General: Mary Simon
59
- Provinces and Territories: Saskatchewan, Manitoba, Ontario, Quebec, New Brunswick, Prince Edward Island, Nova Scotia, Newfoundland and Labrador, Yukon, Nunavut, Northwest Territories
60

61
----
62

63
Sample text:
64
Patient birth date: 1990-01-01
65
Prescribed medication: aspirin, ibuprofen, acetaminophen
66
Prescribed dosage: 1 tablet, 2 tablets, 3 tablets
67
Doctor's name: Dr. Burns
68
Date of discharge: 2020-01-01
69
Hospital address: 123 Main Street, New York, NY 10001
70

71
Question: List all relevant attributes about 'medications' that are exactly mentioned in this sample text if any.
72
Answer:
73
- Prescribed medication: aspirin, ibuprofen, acetaminophen
74
- Prescribed dosage: 1 tablet, 2 tablets, 3 tablets
75

76
----
77

78
Sample text:
79
{{chunk:}}
80

81
Question: List all relevant attributes about '{{topic:}}' that are exactly mentioned in this sample text if any.
82
Answer:"""
83

84
SCHEMA_ID_PROMPT = PromptTemplate(SCHEMA_ID_PROMPT_TMPL)
85

86

87
# used for function generation
88

89
FN_GENERATION_PROMPT_TMPL = f"""Here is a sample of text:
90

91
{{context_str:}}
92

93

94
Question: {{query_str:}}
95

96
Given the function signature, write Python code to extract the
97
"{{attribute:}}" field from the text.
98
Return the result as a single value (string, int, float), and not a list.
99
Make sure there is a return statement in the code. Do not leave out a return statement.
100
{{expected_output_str:}}
101

102
import re
103

104
def get_{{function_field:}}_field(text: str):
105
    \"""
106
    Function to extract the "{{attribute:}} field", and return the result
107
    as a single value.
108
    \"""
109
    """
110

111
FN_GENERATION_PROMPT = PromptTemplate(FN_GENERATION_PROMPT_TMPL)
112

113

114
FN_GENERATION_LIST_PROMPT_TMPL = f"""Here is a sample of text:
115

116
{{context_str:}}
117

118

119
Question: {{query_str:}}
120

121
Given the function signature, write Python code to extract the
122
"{{attribute:}}" field from the text.
123
Return the result as a list of values (if there is just one item, return a single \
124
element list).
125
Make sure there is a return statement in the code. Do not leave out a return statement.
126
{{expected_output_str:}}
127

128
import re
129

130
def get_{{function_field:}}_field(text: str) -> List:
131
    \"""
132
    Function to extract the "{{attribute:}} field", and return the result
133
    as a single value.
134
    \"""
135
    """
136

137
FN_GENERATION_LIST_PROMPT = PromptTemplate(FN_GENERATION_LIST_PROMPT_TMPL)
138

139
DEFAULT_EXPECTED_OUTPUT_PREFIX_TMPL = (
140
    "Here is the expected output on the text after running the function. "
141
    "Please do not write a function that would return a different output. "
142
    "Expected output: "
143
)
144

145

146
DEFAULT_FIELD_EXTRACT_QUERY_TMPL = (
147
    'Write a python function to extract the entire "{field}" field from text, '
148
    "but not any other metadata. Return the result as a list."
149
)
150

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.