symbolicai 0.20.2__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- symai/__init__.py +96 -64
- symai/backend/base.py +93 -80
- symai/backend/engines/drawing/engine_bfl.py +12 -11
- symai/backend/engines/drawing/engine_gpt_image.py +108 -87
- symai/backend/engines/embedding/engine_llama_cpp.py +25 -28
- symai/backend/engines/embedding/engine_openai.py +3 -5
- symai/backend/engines/execute/engine_python.py +6 -5
- symai/backend/engines/files/engine_io.py +74 -67
- symai/backend/engines/imagecaptioning/engine_blip2.py +3 -3
- symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +54 -38
- symai/backend/engines/index/engine_pinecone.py +23 -24
- symai/backend/engines/index/engine_vectordb.py +16 -14
- symai/backend/engines/lean/engine_lean4.py +38 -34
- symai/backend/engines/neurosymbolic/__init__.py +41 -13
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +262 -182
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +263 -191
- symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +53 -49
- symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +212 -211
- symai/backend/engines/neurosymbolic/engine_groq.py +87 -63
- symai/backend/engines/neurosymbolic/engine_huggingface.py +21 -24
- symai/backend/engines/neurosymbolic/engine_llama_cpp.py +117 -48
- symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +256 -229
- symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +270 -150
- symai/backend/engines/ocr/engine_apilayer.py +6 -8
- symai/backend/engines/output/engine_stdout.py +1 -4
- symai/backend/engines/search/engine_openai.py +7 -7
- symai/backend/engines/search/engine_perplexity.py +5 -5
- symai/backend/engines/search/engine_serpapi.py +12 -14
- symai/backend/engines/speech_to_text/engine_local_whisper.py +20 -27
- symai/backend/engines/symbolic/engine_wolframalpha.py +3 -3
- symai/backend/engines/text_to_speech/engine_openai.py +5 -7
- symai/backend/engines/text_vision/engine_clip.py +7 -11
- symai/backend/engines/userinput/engine_console.py +3 -3
- symai/backend/engines/webscraping/engine_requests.py +81 -48
- symai/backend/mixin/__init__.py +13 -0
- symai/backend/mixin/anthropic.py +4 -2
- symai/backend/mixin/deepseek.py +2 -0
- symai/backend/mixin/google.py +2 -0
- symai/backend/mixin/openai.py +11 -3
- symai/backend/settings.py +83 -16
- symai/chat.py +101 -78
- symai/collect/__init__.py +7 -1
- symai/collect/dynamic.py +77 -69
- symai/collect/pipeline.py +35 -27
- symai/collect/stats.py +75 -63
- symai/components.py +198 -169
- symai/constraints.py +15 -12
- symai/core.py +698 -359
- symai/core_ext.py +32 -34
- symai/endpoints/api.py +80 -73
- symai/extended/.DS_Store +0 -0
- symai/extended/__init__.py +46 -12
- symai/extended/api_builder.py +11 -8
- symai/extended/arxiv_pdf_parser.py +13 -12
- symai/extended/bibtex_parser.py +2 -3
- symai/extended/conversation.py +101 -90
- symai/extended/document.py +17 -10
- symai/extended/file_merger.py +18 -13
- symai/extended/graph.py +18 -13
- symai/extended/html_style_template.py +2 -4
- symai/extended/interfaces/blip_2.py +1 -2
- symai/extended/interfaces/clip.py +1 -2
- symai/extended/interfaces/console.py +7 -1
- symai/extended/interfaces/dall_e.py +1 -1
- symai/extended/interfaces/flux.py +1 -1
- symai/extended/interfaces/gpt_image.py +1 -1
- symai/extended/interfaces/input.py +1 -1
- symai/extended/interfaces/llava.py +0 -1
- symai/extended/interfaces/naive_vectordb.py +7 -8
- symai/extended/interfaces/naive_webscraping.py +1 -1
- symai/extended/interfaces/ocr.py +1 -1
- symai/extended/interfaces/pinecone.py +6 -5
- symai/extended/interfaces/serpapi.py +1 -1
- symai/extended/interfaces/terminal.py +2 -3
- symai/extended/interfaces/tts.py +1 -1
- symai/extended/interfaces/whisper.py +1 -1
- symai/extended/interfaces/wolframalpha.py +1 -1
- symai/extended/metrics/__init__.py +11 -1
- symai/extended/metrics/similarity.py +11 -13
- symai/extended/os_command.py +17 -16
- symai/extended/packages/__init__.py +29 -3
- symai/extended/packages/symdev.py +19 -16
- symai/extended/packages/sympkg.py +12 -9
- symai/extended/packages/symrun.py +21 -19
- symai/extended/repo_cloner.py +11 -10
- symai/extended/seo_query_optimizer.py +1 -2
- symai/extended/solver.py +20 -23
- symai/extended/summarizer.py +4 -3
- symai/extended/taypan_interpreter.py +10 -12
- symai/extended/vectordb.py +99 -82
- symai/formatter/__init__.py +9 -1
- symai/formatter/formatter.py +12 -16
- symai/formatter/regex.py +62 -63
- symai/functional.py +176 -122
- symai/imports.py +136 -127
- symai/interfaces.py +56 -27
- symai/memory.py +14 -13
- symai/misc/console.py +49 -39
- symai/misc/loader.py +5 -3
- symai/models/__init__.py +17 -1
- symai/models/base.py +269 -181
- symai/models/errors.py +0 -1
- symai/ops/__init__.py +32 -22
- symai/ops/measures.py +11 -15
- symai/ops/primitives.py +348 -228
- symai/post_processors.py +32 -28
- symai/pre_processors.py +39 -41
- symai/processor.py +6 -4
- symai/prompts.py +59 -45
- symai/server/huggingface_server.py +23 -20
- symai/server/llama_cpp_server.py +7 -5
- symai/shell.py +3 -4
- symai/shellsv.py +499 -375
- symai/strategy.py +517 -287
- symai/symbol.py +111 -116
- symai/utils.py +42 -36
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/METADATA +4 -2
- symbolicai-1.0.0.dist-info/RECORD +163 -0
- symbolicai-0.20.2.dist-info/RECORD +0 -162
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/WHEEL +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/entry_points.txt +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/top_level.txt +0 -0
symai/core.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import functools
|
|
2
|
-
from
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from typing import Any
|
|
3
4
|
|
|
4
5
|
from box import Box
|
|
5
6
|
|
|
@@ -9,6 +10,44 @@ from . import prompts as prm
|
|
|
9
10
|
from .functional import EngineRepository
|
|
10
11
|
from .symbol import Expression, Metadata
|
|
11
12
|
|
|
13
|
+
# Module-level singletons used to provide default prompt and processor instances.
|
|
14
|
+
_PREPROCESSOR_EXPAND_FUNCTION = pre.ExpandFunctionPreProcessor()
|
|
15
|
+
_PROMPT_CLEAN_TEXT = prm.CleanText()
|
|
16
|
+
_PROMPT_COMBINE_TEXT = prm.CombineText()
|
|
17
|
+
_PROMPT_COMPARE_VALUES = prm.CompareValues()
|
|
18
|
+
_PROMPT_CONTAINS_VALUE = prm.ContainsValue()
|
|
19
|
+
_PROMPT_ENDS_WITH = prm.EndsWith()
|
|
20
|
+
_PROMPT_EXCEPTION_MAPPING = prm.ExceptionMapping()
|
|
21
|
+
_PROMPT_EXPAND_FUNCTION = prm.ExpandFunction()
|
|
22
|
+
_PROMPT_EXTRACT_PATTERN = prm.ExtractPattern()
|
|
23
|
+
_PROMPT_FILTER = prm.Filter()
|
|
24
|
+
_PROMPT_FOR_EACH = prm.ForEach()
|
|
25
|
+
_PROMPT_FORMAT = prm.Format()
|
|
26
|
+
_PROMPT_FUZZY_EQUALS = prm.FuzzyEquals()
|
|
27
|
+
_PROMPT_GENERATE_CODE = prm.GenerateCode()
|
|
28
|
+
_PROMPT_INCLUDE_TEXT = prm.IncludeText()
|
|
29
|
+
_PROMPT_INDEX = prm.Index()
|
|
30
|
+
_PROMPT_INVERT_EXPRESSION = prm.InvertExpression()
|
|
31
|
+
_PROMPT_IS_INSTANCE_OF = prm.IsInstanceOf()
|
|
32
|
+
_PROMPT_LIST_OBJECTS = prm.ListObjects()
|
|
33
|
+
_PROMPT_LOGIC_EXPRESSION = prm.LogicExpression()
|
|
34
|
+
_PROMPT_MAP_CONTENT = prm.MapContent()
|
|
35
|
+
_PROMPT_MAP_EXPRESSION = prm.MapExpression()
|
|
36
|
+
_PROMPT_MODIFY = prm.Modify()
|
|
37
|
+
_PROMPT_NEGATE_STATEMENT = prm.NegateStatement()
|
|
38
|
+
_PROMPT_RANK_LIST = prm.RankList()
|
|
39
|
+
_PROMPT_REMOVE_INDEX = prm.RemoveIndex()
|
|
40
|
+
_PROMPT_REPLACE_TEXT = prm.ReplaceText()
|
|
41
|
+
_PROMPT_SEMANTIC_MAPPING = prm.SemanticMapping()
|
|
42
|
+
_PROMPT_SET_INDEX = prm.SetIndex()
|
|
43
|
+
_PROMPT_SIMPLE_SYMBOLIC_EXPRESSION = prm.SimpleSymbolicExpression()
|
|
44
|
+
_PROMPT_SIMULATE_CODE = prm.SimulateCode()
|
|
45
|
+
_PROMPT_STARTS_WITH = prm.StartsWith()
|
|
46
|
+
_PROMPT_SUFFICIENT_INFORMATION = prm.SufficientInformation()
|
|
47
|
+
_PROMPT_TEXT_TO_OUTLINE = prm.TextToOutline()
|
|
48
|
+
_PROMPT_TRANSCRIPTION = prm.Transcription()
|
|
49
|
+
_PROMPT_UNIQUE_KEY = prm.UniqueKey()
|
|
50
|
+
|
|
12
51
|
|
|
13
52
|
class Argument(Expression):
|
|
14
53
|
_default_suppress_verbose_output = False
|
|
@@ -24,51 +63,41 @@ class Argument(Expression):
|
|
|
24
63
|
decorator_kwargs=decorator_kwargs)
|
|
25
64
|
self.prop = Metadata()
|
|
26
65
|
self._set_all_kwargs_as_properties()
|
|
27
|
-
|
|
28
|
-
# Reserved keywords
|
|
29
|
-
if 'preview' not in self.kwargs: # used for previewing the input (also for operators)
|
|
30
|
-
self.prop.preview = Argument._default_preview_value
|
|
31
|
-
if 'raw_input' not in self.kwargs:
|
|
32
|
-
self.prop.raw_input = False
|
|
33
|
-
if 'raw_output' not in self.kwargs:
|
|
34
|
-
self.prop.raw_output = False
|
|
35
|
-
if 'return_metadata' not in self.kwargs:
|
|
36
|
-
self.prop.return_metadata = False
|
|
37
|
-
if 'logging' not in self.kwargs:
|
|
38
|
-
self.prop.logging = False
|
|
39
|
-
if 'verbose' not in self.kwargs:
|
|
40
|
-
self.prop.verbose = False
|
|
41
|
-
if 'self_prompt' not in self.kwargs:
|
|
42
|
-
self.prop.self_prompt = False
|
|
43
|
-
if 'truncation_percentage' not in self.kwargs:
|
|
44
|
-
self.prop.truncation_percentage = None
|
|
45
|
-
if 'truncation_type' not in self.kwargs:
|
|
46
|
-
self.prop.truncation_type = 'tail'
|
|
47
|
-
if 'response_format' not in self.kwargs:
|
|
48
|
-
self.prop.response_format = None
|
|
49
|
-
if 'log_level' not in self.kwargs:
|
|
50
|
-
self.prop.log_level = None
|
|
51
|
-
if 'time_clock' not in self.kwargs:
|
|
52
|
-
self.prop.time_clock = None
|
|
53
|
-
if 'payload' not in self.kwargs:
|
|
54
|
-
self.prop.payload = None
|
|
55
|
-
if 'processed_input' not in self.kwargs:
|
|
56
|
-
self.prop.processed_input = None
|
|
57
|
-
if 'template_suffix' not in self.kwargs:
|
|
58
|
-
self.prop.template_suffix = None
|
|
59
|
-
if 'input_handler' not in self.kwargs:
|
|
60
|
-
self.prop.input_handler = None
|
|
61
|
-
if 'output_handler' not in self.kwargs:
|
|
62
|
-
self.prop.output_handler = None
|
|
63
|
-
if 'suppress_verbose_output' not in self.kwargs:
|
|
64
|
-
self.prop.suppress_verbose_output = Argument._default_suppress_verbose_output
|
|
65
|
-
if 'parse_system_instructions' not in self.kwargs:
|
|
66
|
-
self.prop.parse_system_instructions = Argument._default_parse_system_instructions
|
|
66
|
+
self._apply_default_properties()
|
|
67
67
|
|
|
68
68
|
def _set_all_kwargs_as_properties(self):
|
|
69
69
|
for key, value in self.kwargs.items():
|
|
70
70
|
setattr(self.prop, key, value)
|
|
71
71
|
|
|
72
|
+
def _apply_default_properties(self):
|
|
73
|
+
# Set default values if not specified for backend processing
|
|
74
|
+
# Reserved keywords
|
|
75
|
+
default_properties = {
|
|
76
|
+
# used for previewing the input (also for operators)
|
|
77
|
+
'preview': Argument._default_preview_value,
|
|
78
|
+
'raw_input': False,
|
|
79
|
+
'raw_output': False,
|
|
80
|
+
'return_metadata': False,
|
|
81
|
+
'logging': False,
|
|
82
|
+
'verbose': False,
|
|
83
|
+
'self_prompt': False,
|
|
84
|
+
'truncation_percentage': None,
|
|
85
|
+
'truncation_type': 'tail',
|
|
86
|
+
'response_format': None,
|
|
87
|
+
'log_level': None,
|
|
88
|
+
'time_clock': None,
|
|
89
|
+
'payload': None,
|
|
90
|
+
'processed_input': None,
|
|
91
|
+
'template_suffix': None,
|
|
92
|
+
'input_handler': None,
|
|
93
|
+
'output_handler': None,
|
|
94
|
+
'suppress_verbose_output': Argument._default_suppress_verbose_output,
|
|
95
|
+
'parse_system_instructions': Argument._default_parse_system_instructions,
|
|
96
|
+
}
|
|
97
|
+
for key, default_value in default_properties.items():
|
|
98
|
+
if key not in self.kwargs:
|
|
99
|
+
setattr(self.prop, key, default_value)
|
|
100
|
+
|
|
72
101
|
@property
|
|
73
102
|
def value(self):
|
|
74
103
|
return Box({
|
|
@@ -99,14 +128,18 @@ class Argument(Expression):
|
|
|
99
128
|
|
|
100
129
|
|
|
101
130
|
def few_shot(prompt: str = '',
|
|
102
|
-
examples: prm.Prompt =
|
|
103
|
-
constraints:
|
|
131
|
+
examples: prm.Prompt = None,
|
|
132
|
+
constraints: list[Callable] | None = None,
|
|
104
133
|
default: Any = None,
|
|
105
134
|
limit: int = 1,
|
|
106
|
-
pre_processors:
|
|
107
|
-
post_processors:
|
|
135
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
136
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
108
137
|
**decorator_kwargs):
|
|
109
138
|
""""General decorator for the neural processing engine."""
|
|
139
|
+
if constraints is None:
|
|
140
|
+
constraints = []
|
|
141
|
+
if examples is None:
|
|
142
|
+
examples = []
|
|
110
143
|
def decorator(func):
|
|
111
144
|
@functools.wraps(func)
|
|
112
145
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -129,13 +162,15 @@ def few_shot(prompt: str = '',
|
|
|
129
162
|
|
|
130
163
|
|
|
131
164
|
def zero_shot(prompt: str = '',
|
|
132
|
-
constraints:
|
|
133
|
-
default:
|
|
165
|
+
constraints: list[Callable] | None = None,
|
|
166
|
+
default: object | None = None,
|
|
134
167
|
limit: int = 1,
|
|
135
|
-
pre_processors:
|
|
136
|
-
post_processors:
|
|
168
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
169
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
137
170
|
**decorator_kwargs):
|
|
138
171
|
""""General decorator for the neural processing engine."""
|
|
172
|
+
if constraints is None:
|
|
173
|
+
constraints = []
|
|
139
174
|
return few_shot(prompt,
|
|
140
175
|
examples=[],
|
|
141
176
|
constraints=constraints,
|
|
@@ -155,15 +190,21 @@ def prompt(message: str,
|
|
|
155
190
|
|
|
156
191
|
|
|
157
192
|
def summarize(prompt: str = 'Summarize the content of the following text:\n',
|
|
158
|
-
context:
|
|
159
|
-
constraints:
|
|
160
|
-
default:
|
|
193
|
+
context: str | None = None,
|
|
194
|
+
constraints: list[Callable] | None = None,
|
|
195
|
+
default: object | None = None,
|
|
161
196
|
limit: int = 1,
|
|
162
|
-
stop: str |
|
|
163
|
-
pre_processors:
|
|
164
|
-
post_processors:
|
|
197
|
+
stop: str | list[str] = '',
|
|
198
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
199
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
165
200
|
**decorator_kwargs):
|
|
166
201
|
"""Summarizes the content of a text."""
|
|
202
|
+
if post_processors is None:
|
|
203
|
+
post_processors = [post.StripPostProcessor()]
|
|
204
|
+
if pre_processors is None:
|
|
205
|
+
pre_processors = [pre.SummaryPreProcessing()]
|
|
206
|
+
if constraints is None:
|
|
207
|
+
constraints = []
|
|
167
208
|
return few_shot(prompt,
|
|
168
209
|
context=context,
|
|
169
210
|
examples=[],
|
|
@@ -179,14 +220,20 @@ def summarize(prompt: str = 'Summarize the content of the following text:\n',
|
|
|
179
220
|
def equals(context: str = 'contextually',
|
|
180
221
|
default: bool = False,
|
|
181
222
|
prompt: str = "Make a fuzzy equals comparison; are the following objects {} the same?\n",
|
|
182
|
-
examples: prm.Prompt =
|
|
183
|
-
constraints:
|
|
223
|
+
examples: prm.Prompt = _PROMPT_FUZZY_EQUALS,
|
|
224
|
+
constraints: list[Callable] | None = None,
|
|
184
225
|
limit: int = 1,
|
|
185
|
-
stop: str |
|
|
186
|
-
pre_processors:
|
|
187
|
-
post_processors:
|
|
226
|
+
stop: str | list[str] = '',
|
|
227
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
228
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
188
229
|
**decorator_kwargs):
|
|
189
230
|
"""Equality function for two objects."""
|
|
231
|
+
if post_processors is None:
|
|
232
|
+
post_processors = [post.StripPostProcessor()]
|
|
233
|
+
if pre_processors is None:
|
|
234
|
+
pre_processors = [pre.EqualsPreProcessor()]
|
|
235
|
+
if constraints is None:
|
|
236
|
+
constraints = []
|
|
190
237
|
return few_shot(prompt=prompt.format(context),
|
|
191
238
|
examples=examples,
|
|
192
239
|
constraints=constraints,
|
|
@@ -202,14 +249,20 @@ def equals(context: str = 'contextually',
|
|
|
202
249
|
def sufficient(query: str,
|
|
203
250
|
prompt: str = "Consider if there is sufficient information to answer the query:\n",
|
|
204
251
|
default: bool = False,
|
|
205
|
-
examples: prm.Prompt =
|
|
206
|
-
constraints:
|
|
252
|
+
examples: prm.Prompt = _PROMPT_SUFFICIENT_INFORMATION,
|
|
253
|
+
constraints: list[Callable] | None = None,
|
|
207
254
|
limit: int = 1,
|
|
208
|
-
stop: str |
|
|
209
|
-
pre_processors:
|
|
210
|
-
post_processors:
|
|
255
|
+
stop: str | list[str] = '',
|
|
256
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
257
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
211
258
|
**decorator_kwargs) -> bool:
|
|
212
259
|
"""Determines if there is sufficient information to answer the given query."""
|
|
260
|
+
if post_processors is None:
|
|
261
|
+
post_processors = [post.StripPostProcessor()]
|
|
262
|
+
if pre_processors is None:
|
|
263
|
+
pre_processors = [pre.SufficientInformationPreProcessor()]
|
|
264
|
+
if constraints is None:
|
|
265
|
+
constraints = []
|
|
213
266
|
return few_shot(prompt=prompt,
|
|
214
267
|
query=query,
|
|
215
268
|
examples=examples,
|
|
@@ -223,16 +276,22 @@ def sufficient(query: str,
|
|
|
223
276
|
**decorator_kwargs)
|
|
224
277
|
|
|
225
278
|
|
|
226
|
-
def delitem(default:
|
|
279
|
+
def delitem(default: str | None = None,
|
|
227
280
|
prompt: str = "Delete the items at the index position:\n",
|
|
228
|
-
examples: prm.Prompt =
|
|
229
|
-
constraints:
|
|
281
|
+
examples: prm.Prompt = _PROMPT_REMOVE_INDEX,
|
|
282
|
+
constraints: list[Callable] | None = None,
|
|
230
283
|
limit: int = 1,
|
|
231
|
-
stop: str |
|
|
232
|
-
pre_processors:
|
|
233
|
-
post_processors:
|
|
284
|
+
stop: str | list[str] = '',
|
|
285
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
286
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
234
287
|
**decorator_kwargs):
|
|
235
288
|
"""Deletes the items at the specified index position."""
|
|
289
|
+
if post_processors is None:
|
|
290
|
+
post_processors = [post.StripPostProcessor()]
|
|
291
|
+
if pre_processors is None:
|
|
292
|
+
pre_processors = [pre.DeleteIndexPreProcessor()]
|
|
293
|
+
if constraints is None:
|
|
294
|
+
constraints = []
|
|
236
295
|
return few_shot(prompt=prompt,
|
|
237
296
|
examples=examples,
|
|
238
297
|
constraints=constraints,
|
|
@@ -244,16 +303,22 @@ def delitem(default: Optional[str] = None,
|
|
|
244
303
|
**decorator_kwargs)
|
|
245
304
|
|
|
246
305
|
|
|
247
|
-
def setitem(default:
|
|
306
|
+
def setitem(default: str | None = None,
|
|
248
307
|
prompt: str = "Set item at index position:\n",
|
|
249
|
-
examples: prm.Prompt =
|
|
250
|
-
constraints:
|
|
308
|
+
examples: prm.Prompt = _PROMPT_SET_INDEX,
|
|
309
|
+
constraints: list[Callable] | None = None,
|
|
251
310
|
limit: int = 1,
|
|
252
|
-
stop: str |
|
|
253
|
-
pre_processors:
|
|
254
|
-
post_processors:
|
|
311
|
+
stop: str | list[str] = '',
|
|
312
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
313
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
255
314
|
**decorator_kwargs):
|
|
256
315
|
"""Sets an item at a given index position in a sequence."""
|
|
316
|
+
if post_processors is None:
|
|
317
|
+
post_processors = [post.StripPostProcessor()]
|
|
318
|
+
if pre_processors is None:
|
|
319
|
+
pre_processors = [pre.SetIndexPreProcessor()]
|
|
320
|
+
if constraints is None:
|
|
321
|
+
constraints = []
|
|
257
322
|
return few_shot(prompt=prompt,
|
|
258
323
|
examples=examples,
|
|
259
324
|
constraints=constraints,
|
|
@@ -265,16 +330,22 @@ def setitem(default: Optional[str] = None,
|
|
|
265
330
|
**decorator_kwargs)
|
|
266
331
|
|
|
267
332
|
|
|
268
|
-
def getitem(default:
|
|
333
|
+
def getitem(default: str | None = None,
|
|
269
334
|
prompt: str = "Get item at index position:\n",
|
|
270
|
-
examples: prm.Prompt =
|
|
271
|
-
constraints:
|
|
335
|
+
examples: prm.Prompt = _PROMPT_INDEX,
|
|
336
|
+
constraints: list[Callable] | None = None,
|
|
272
337
|
limit: int = 1,
|
|
273
|
-
stop: str |
|
|
274
|
-
pre_processors:
|
|
275
|
-
post_processors:
|
|
338
|
+
stop: str | list[str] = '',
|
|
339
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
340
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
276
341
|
**decorator_kwargs):
|
|
277
342
|
"""Retrieves the item at the given index position."""
|
|
343
|
+
if post_processors is None:
|
|
344
|
+
post_processors = [post.StripPostProcessor()]
|
|
345
|
+
if pre_processors is None:
|
|
346
|
+
pre_processors = [pre.IndexPreProcessor()]
|
|
347
|
+
if constraints is None:
|
|
348
|
+
constraints = []
|
|
278
349
|
return few_shot(prompt=prompt,
|
|
279
350
|
examples=examples,
|
|
280
351
|
constraints=constraints,
|
|
@@ -287,16 +358,22 @@ def getitem(default: Optional[str] = None,
|
|
|
287
358
|
|
|
288
359
|
|
|
289
360
|
def modify(changes: str,
|
|
290
|
-
default:
|
|
361
|
+
default: str | None = None,
|
|
291
362
|
prompt: str = "Modify the text to match the criteria:\n",
|
|
292
|
-
examples: prm.Prompt =
|
|
293
|
-
constraints:
|
|
363
|
+
examples: prm.Prompt = _PROMPT_MODIFY,
|
|
364
|
+
constraints: list[Callable] | None = None,
|
|
294
365
|
limit: int = 1,
|
|
295
|
-
stop: str |
|
|
296
|
-
pre_processors:
|
|
297
|
-
post_processors:
|
|
366
|
+
stop: str | list[str] = '',
|
|
367
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
368
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
298
369
|
**decorator_kwargs):
|
|
299
370
|
"""A function to modify a text based on a set of criteria."""
|
|
371
|
+
if post_processors is None:
|
|
372
|
+
post_processors = [post.StripPostProcessor()]
|
|
373
|
+
if pre_processors is None:
|
|
374
|
+
pre_processors = [pre.ModifyPreProcessor()]
|
|
375
|
+
if constraints is None:
|
|
376
|
+
constraints = []
|
|
300
377
|
return few_shot(prompt=prompt,
|
|
301
378
|
changes=changes,
|
|
302
379
|
examples=examples,
|
|
@@ -311,16 +388,22 @@ def modify(changes: str,
|
|
|
311
388
|
|
|
312
389
|
def filtering(criteria: str,
|
|
313
390
|
include: bool = False,
|
|
314
|
-
default:
|
|
391
|
+
default: str | None = None,
|
|
315
392
|
prompt: str = "Filter the information from the text based on the filter criteria. Leave sentences unchanged if they are unrelated to the filter criteria:\n",
|
|
316
|
-
examples: prm.Prompt =
|
|
317
|
-
constraints:
|
|
393
|
+
examples: prm.Prompt = _PROMPT_FILTER,
|
|
394
|
+
constraints: list[Callable] | None = None,
|
|
318
395
|
limit: int = 1,
|
|
319
|
-
stop: str |
|
|
320
|
-
pre_processors:
|
|
321
|
-
post_processors:
|
|
396
|
+
stop: str | list[str] = '',
|
|
397
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
398
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
322
399
|
**decorator_kwargs):
|
|
323
400
|
"""Filter information from a text based on a set of criteria."""
|
|
401
|
+
if post_processors is None:
|
|
402
|
+
post_processors = [post.StripPostProcessor()]
|
|
403
|
+
if pre_processors is None:
|
|
404
|
+
pre_processors = [pre.FilterPreProcessor()]
|
|
405
|
+
if constraints is None:
|
|
406
|
+
constraints = []
|
|
324
407
|
return few_shot(prompt=prompt,
|
|
325
408
|
criteria=criteria,
|
|
326
409
|
include=include,
|
|
@@ -334,17 +417,24 @@ def filtering(criteria: str,
|
|
|
334
417
|
**decorator_kwargs)
|
|
335
418
|
|
|
336
419
|
|
|
337
|
-
def map(
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
420
|
+
def map( # noqa: A001
|
|
421
|
+
instruction: str,
|
|
422
|
+
default: str | None = None,
|
|
423
|
+
prompt: str = "Transform each element in the input based on the instruction. Preserve container type and elements that don't match the instruction:\n",
|
|
424
|
+
examples: prm.Prompt = _PROMPT_MAP_EXPRESSION,
|
|
425
|
+
constraints: list[Callable] | None = None,
|
|
426
|
+
limit: int | None = 1,
|
|
427
|
+
stop: str | list[str] = '',
|
|
428
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
429
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
430
|
+
**decorator_kwargs):
|
|
347
431
|
"""Semantic mapping operation that applies an instruction to each element in an iterable."""
|
|
432
|
+
if post_processors is None:
|
|
433
|
+
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
434
|
+
if pre_processors is None:
|
|
435
|
+
pre_processors = [pre.MapExpressionPreProcessor()]
|
|
436
|
+
if constraints is None:
|
|
437
|
+
constraints = []
|
|
348
438
|
return few_shot(prompt=prompt,
|
|
349
439
|
examples=examples,
|
|
350
440
|
constraints=constraints,
|
|
@@ -357,17 +447,23 @@ def map(instruction: str,
|
|
|
357
447
|
**decorator_kwargs)
|
|
358
448
|
|
|
359
449
|
|
|
360
|
-
def notify(subscriber:
|
|
361
|
-
default:
|
|
450
|
+
def notify(subscriber: dict[str, Callable],
|
|
451
|
+
default: object | None = None,
|
|
362
452
|
prompt: str = "List the semantically related topics:\n",
|
|
363
|
-
examples: prm.Prompt =
|
|
364
|
-
constraints:
|
|
453
|
+
examples: prm.Prompt = _PROMPT_SEMANTIC_MAPPING,
|
|
454
|
+
constraints: list[Callable] | None = None,
|
|
365
455
|
limit: int | None = 1,
|
|
366
|
-
stop: str |
|
|
367
|
-
pre_processors:
|
|
368
|
-
post_processors:
|
|
456
|
+
stop: str | list[str] = '',
|
|
457
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
458
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
369
459
|
**decorator_kwargs):
|
|
370
460
|
"""Notify subscribers based on a set of topics if detected in the input text and matching the key of the subscriber."""
|
|
461
|
+
if post_processors is None:
|
|
462
|
+
post_processors = [post.SplitPipePostProcessor(), post.NotifySubscriberPostProcessor()]
|
|
463
|
+
if pre_processors is None:
|
|
464
|
+
pre_processors = [pre.SemanticMappingPreProcessor()]
|
|
465
|
+
if constraints is None:
|
|
466
|
+
constraints = []
|
|
371
467
|
return few_shot(prompt=prompt,
|
|
372
468
|
subscriber=subscriber,
|
|
373
469
|
examples=examples,
|
|
@@ -383,14 +479,20 @@ def notify(subscriber: Dict[str, Callable],
|
|
|
383
479
|
def compare(default: bool = False,
|
|
384
480
|
operator: str = '>',
|
|
385
481
|
prompt: str = "Compare 'A' and 'B' based on the operator:\n",
|
|
386
|
-
examples: prm.Prompt =
|
|
387
|
-
constraints:
|
|
482
|
+
examples: prm.Prompt = _PROMPT_COMPARE_VALUES,
|
|
483
|
+
constraints: list[Callable] | None = None,
|
|
388
484
|
limit: int | None = 1,
|
|
389
|
-
stop: str |
|
|
390
|
-
pre_processors:
|
|
391
|
-
post_processors:
|
|
485
|
+
stop: str | list[str] = '',
|
|
486
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
487
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
392
488
|
**decorator_kwargs):
|
|
393
489
|
"""Compare two objects based on the specified operator."""
|
|
490
|
+
if post_processors is None:
|
|
491
|
+
post_processors = [post.StripPostProcessor()]
|
|
492
|
+
if pre_processors is None:
|
|
493
|
+
pre_processors = [pre.ComparePreProcessor()]
|
|
494
|
+
if constraints is None:
|
|
495
|
+
constraints = []
|
|
394
496
|
return few_shot(prompt=prompt,
|
|
395
497
|
examples=examples,
|
|
396
498
|
constraints=constraints,
|
|
@@ -404,17 +506,24 @@ def compare(default: bool = False,
|
|
|
404
506
|
**decorator_kwargs)
|
|
405
507
|
|
|
406
508
|
|
|
407
|
-
def convert(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
509
|
+
def convert(
|
|
510
|
+
format: str,
|
|
511
|
+
default: str | None = None,
|
|
512
|
+
prompt: str = "Translate the following text into {} format.\n",
|
|
513
|
+
examples: prm.Prompt = _PROMPT_FORMAT,
|
|
514
|
+
constraints: list[Callable] | None = None,
|
|
515
|
+
limit: int | None = 1,
|
|
516
|
+
stop: str | list[str] = '',
|
|
517
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
518
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
519
|
+
**decorator_kwargs):
|
|
417
520
|
"""Transformation operation from one format to another."""
|
|
521
|
+
if post_processors is None:
|
|
522
|
+
post_processors = [post.StripPostProcessor()]
|
|
523
|
+
if pre_processors is None:
|
|
524
|
+
pre_processors = [pre.TextFormatPreProcessor()]
|
|
525
|
+
if constraints is None:
|
|
526
|
+
constraints = []
|
|
418
527
|
return few_shot(prompt=prompt,
|
|
419
528
|
examples=examples,
|
|
420
529
|
constraints=constraints,
|
|
@@ -428,16 +537,22 @@ def convert(format: str,
|
|
|
428
537
|
|
|
429
538
|
|
|
430
539
|
def transcribe(modify: str,
|
|
431
|
-
default:
|
|
540
|
+
default: str | None = None,
|
|
432
541
|
prompt: str = "Transcribe the following text by only modifying the text by the provided instruction.\n",
|
|
433
|
-
examples: prm.Prompt =
|
|
434
|
-
constraints:
|
|
542
|
+
examples: prm.Prompt = _PROMPT_TRANSCRIPTION,
|
|
543
|
+
constraints: list[Callable] | None = None,
|
|
435
544
|
limit: int | None = 1,
|
|
436
|
-
stop: str |
|
|
437
|
-
pre_processors:
|
|
438
|
-
post_processors:
|
|
545
|
+
stop: str | list[str] = '',
|
|
546
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
547
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
439
548
|
**decorator_kwargs):
|
|
440
549
|
"""Transcription operation of a text to another styled text."""
|
|
550
|
+
if post_processors is None:
|
|
551
|
+
post_processors = [post.StripPostProcessor()]
|
|
552
|
+
if pre_processors is None:
|
|
553
|
+
pre_processors = [pre.TranscriptionPreProcessor()]
|
|
554
|
+
if constraints is None:
|
|
555
|
+
constraints = []
|
|
441
556
|
return few_shot(prompt=prompt,
|
|
442
557
|
examples=examples,
|
|
443
558
|
constraints=constraints,
|
|
@@ -451,16 +566,24 @@ def transcribe(modify: str,
|
|
|
451
566
|
|
|
452
567
|
|
|
453
568
|
def style(description: str,
|
|
454
|
-
libraries:
|
|
455
|
-
default:
|
|
569
|
+
libraries: list[str] | None = None,
|
|
570
|
+
default: str | None = None,
|
|
456
571
|
prompt: str = "Style the [DATA] based on best practices and the descriptions in [...] brackets. Do not remove content from the data! Do not add libraries or other descriptions. \n",
|
|
457
|
-
constraints:
|
|
572
|
+
constraints: list[Callable] | None = None,
|
|
458
573
|
limit: int | None = 1,
|
|
459
|
-
stop: str |
|
|
460
|
-
pre_processors:
|
|
461
|
-
post_processors:
|
|
574
|
+
stop: str | list[str] = '',
|
|
575
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
576
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
462
577
|
**decorator_kwargs):
|
|
463
578
|
"""Styles a given text based on best practices and a given description."""
|
|
579
|
+
if post_processors is None:
|
|
580
|
+
post_processors = [post.StripPostProcessor()]
|
|
581
|
+
if pre_processors is None:
|
|
582
|
+
pre_processors = [pre.StylePreProcessor()]
|
|
583
|
+
if constraints is None:
|
|
584
|
+
constraints = []
|
|
585
|
+
if libraries is None:
|
|
586
|
+
libraries = []
|
|
464
587
|
return few_shot(prompt=prompt,
|
|
465
588
|
libraries=libraries,
|
|
466
589
|
examples=None,
|
|
@@ -476,16 +599,22 @@ def style(description: str,
|
|
|
476
599
|
|
|
477
600
|
def analyze(query: str,
|
|
478
601
|
exception: Exception,
|
|
479
|
-
default:
|
|
602
|
+
default: str | None = None,
|
|
480
603
|
prompt: str = "Only analyze the error message and suggest a potential correction, however, do NOT provide the code!\n",
|
|
481
|
-
examples: prm.Prompt =
|
|
482
|
-
constraints:
|
|
604
|
+
examples: prm.Prompt = _PROMPT_EXCEPTION_MAPPING,
|
|
605
|
+
constraints: list[Callable] | None = None,
|
|
483
606
|
limit: int | None = 1,
|
|
484
|
-
stop: str |
|
|
485
|
-
pre_processors:
|
|
486
|
-
post_processors:
|
|
607
|
+
stop: str | list[str] = '',
|
|
608
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
609
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
487
610
|
**decorator_kwargs):
|
|
488
611
|
"""Analyses an Exception and proposes a correction."""
|
|
612
|
+
if post_processors is None:
|
|
613
|
+
post_processors = [post.StripPostProcessor()]
|
|
614
|
+
if pre_processors is None:
|
|
615
|
+
pre_processors = [pre.ExceptionPreProcessor()]
|
|
616
|
+
if constraints is None:
|
|
617
|
+
constraints = []
|
|
489
618
|
return few_shot(prompt=prompt,
|
|
490
619
|
query=query,
|
|
491
620
|
exception=exception,
|
|
@@ -501,16 +630,22 @@ def analyze(query: str,
|
|
|
501
630
|
|
|
502
631
|
def correct(context: str,
|
|
503
632
|
exception: Exception,
|
|
504
|
-
default:
|
|
633
|
+
default: str | None = None,
|
|
505
634
|
prompt: str = "Correct the code according to the context description. Use markdown syntax to format the code; do not provide any other text.\n",
|
|
506
|
-
examples:
|
|
507
|
-
constraints:
|
|
635
|
+
examples: prm.Prompt | None = None,
|
|
636
|
+
constraints: list[Callable] | None = None,
|
|
508
637
|
limit: int | None = 1,
|
|
509
|
-
stop: str |
|
|
510
|
-
pre_processors:
|
|
511
|
-
post_processors:
|
|
638
|
+
stop: str | list[str] = '',
|
|
639
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
640
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
512
641
|
**decorator_kwargs):
|
|
513
642
|
"""Analyses an Exception and proposes a correction."""
|
|
643
|
+
if post_processors is None:
|
|
644
|
+
post_processors = [post.StripPostProcessor(), post.CodeExtractPostProcessor()]
|
|
645
|
+
if pre_processors is None:
|
|
646
|
+
pre_processors = [pre.CorrectionPreProcessor()]
|
|
647
|
+
if constraints is None:
|
|
648
|
+
constraints = []
|
|
514
649
|
return few_shot(prompt=prompt,
|
|
515
650
|
context=context,
|
|
516
651
|
exception=exception,
|
|
@@ -527,14 +662,20 @@ def correct(context: str,
|
|
|
527
662
|
def translate(language: str = 'English',
|
|
528
663
|
default: str = "Sorry, I do not understand the given language.",
|
|
529
664
|
prompt: str = "Your task is to translate and **only** translate the text into {}:\n",
|
|
530
|
-
examples:
|
|
531
|
-
constraints:
|
|
665
|
+
examples: prm.Prompt | None = None,
|
|
666
|
+
constraints: list[Callable] | None = None,
|
|
532
667
|
limit: int | None = 1,
|
|
533
|
-
stop: str |
|
|
534
|
-
pre_processors:
|
|
535
|
-
post_processors:
|
|
668
|
+
stop: str | list[str] = '',
|
|
669
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
670
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
536
671
|
**decorator_kwargs):
|
|
537
672
|
"""Translates a given text into a specified language."""
|
|
673
|
+
if post_processors is None:
|
|
674
|
+
post_processors = [post.StripPostProcessor()]
|
|
675
|
+
if pre_processors is None:
|
|
676
|
+
pre_processors = [pre.LanguagePreProcessor()]
|
|
677
|
+
if constraints is None:
|
|
678
|
+
constraints = []
|
|
538
679
|
return few_shot(prompt=prompt,
|
|
539
680
|
examples=examples,
|
|
540
681
|
constraints=constraints,
|
|
@@ -547,17 +688,23 @@ def translate(language: str = 'English',
|
|
|
547
688
|
**decorator_kwargs)
|
|
548
689
|
|
|
549
690
|
|
|
550
|
-
def rank(default:
|
|
691
|
+
def rank(default: object | None = None,
|
|
551
692
|
order: str = 'desc',
|
|
552
693
|
prompt: str = "Order the list of objects based on their quality measure and oder literal:\n",
|
|
553
|
-
examples: prm.Prompt =
|
|
554
|
-
constraints:
|
|
694
|
+
examples: prm.Prompt = _PROMPT_RANK_LIST,
|
|
695
|
+
constraints: list[Callable] | None = None,
|
|
555
696
|
limit: int | None = 1,
|
|
556
|
-
stop: str |
|
|
557
|
-
pre_processors:
|
|
558
|
-
post_processors:
|
|
697
|
+
stop: str | list[str] = '',
|
|
698
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
699
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
559
700
|
**decorator_kwargs):
|
|
560
701
|
"""Ranks a list of objects based on their quality measure and order literal."""
|
|
702
|
+
if post_processors is None:
|
|
703
|
+
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
704
|
+
if pre_processors is None:
|
|
705
|
+
pre_processors = [pre.RankPreProcessor()]
|
|
706
|
+
if constraints is None:
|
|
707
|
+
constraints = []
|
|
561
708
|
return few_shot(prompt=prompt,
|
|
562
709
|
examples=examples,
|
|
563
710
|
constraints=constraints,
|
|
@@ -571,15 +718,21 @@ def rank(default: Optional[object] = None,
|
|
|
571
718
|
|
|
572
719
|
|
|
573
720
|
def replace(prompt: str = "Replace text parts by string pattern.\n",
|
|
574
|
-
default:
|
|
575
|
-
examples: prm.Prompt =
|
|
576
|
-
constraints:
|
|
721
|
+
default: str | None = None,
|
|
722
|
+
examples: prm.Prompt = _PROMPT_REPLACE_TEXT,
|
|
723
|
+
constraints: list[Callable] | None = None,
|
|
577
724
|
limit: int | None = 1,
|
|
578
|
-
stop: str |
|
|
579
|
-
pre_processors:
|
|
580
|
-
post_processors:
|
|
725
|
+
stop: str | list[str] = '',
|
|
726
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
727
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
581
728
|
**decorator_kwargs):
|
|
582
729
|
"""Replaces text parts by a given string pattern."""
|
|
730
|
+
if post_processors is None:
|
|
731
|
+
post_processors = [post.StripPostProcessor()]
|
|
732
|
+
if pre_processors is None:
|
|
733
|
+
pre_processors = [pre.ReplacePreProcessor()]
|
|
734
|
+
if constraints is None:
|
|
735
|
+
constraints = []
|
|
583
736
|
return few_shot(prompt=prompt,
|
|
584
737
|
examples=examples,
|
|
585
738
|
constraints=constraints,
|
|
@@ -592,15 +745,21 @@ def replace(prompt: str = "Replace text parts by string pattern.\n",
|
|
|
592
745
|
|
|
593
746
|
|
|
594
747
|
def include(prompt: str = "Include information based on description.\n",
|
|
595
|
-
default:
|
|
596
|
-
examples: prm.Prompt =
|
|
597
|
-
constraints:
|
|
748
|
+
default: str | None = None,
|
|
749
|
+
examples: prm.Prompt = _PROMPT_INCLUDE_TEXT,
|
|
750
|
+
constraints: list[Callable] | None = None,
|
|
598
751
|
limit: int | None = 1,
|
|
599
|
-
stop: str |
|
|
600
|
-
pre_processors:
|
|
601
|
-
post_processors:
|
|
752
|
+
stop: str | list[str] = '',
|
|
753
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
754
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
602
755
|
**decorator_kwargs):
|
|
603
756
|
"""Include information from a description."""
|
|
757
|
+
if post_processors is None:
|
|
758
|
+
post_processors = [post.StripPostProcessor()]
|
|
759
|
+
if pre_processors is None:
|
|
760
|
+
pre_processors = [pre.IncludePreProcessor()]
|
|
761
|
+
if constraints is None:
|
|
762
|
+
constraints = []
|
|
604
763
|
return few_shot(prompt=prompt,
|
|
605
764
|
examples=examples,
|
|
606
765
|
constraints=constraints,
|
|
@@ -613,15 +772,21 @@ def include(prompt: str = "Include information based on description.\n",
|
|
|
613
772
|
|
|
614
773
|
|
|
615
774
|
def combine(prompt: str = "Add the two data types in a logical way:\n",
|
|
616
|
-
default:
|
|
617
|
-
examples: prm.Prompt =
|
|
618
|
-
constraints:
|
|
775
|
+
default: str | None = None,
|
|
776
|
+
examples: prm.Prompt = _PROMPT_COMBINE_TEXT,
|
|
777
|
+
constraints: list[Callable] | None = None,
|
|
619
778
|
limit: int | None = 1,
|
|
620
|
-
stop: str |
|
|
621
|
-
pre_processors:
|
|
622
|
-
post_processors:
|
|
779
|
+
stop: str | list[str] = '',
|
|
780
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
781
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
623
782
|
**decorator_kwargs):
|
|
624
783
|
"""Combines two data types in a logical way."""
|
|
784
|
+
if post_processors is None:
|
|
785
|
+
post_processors = [post.StripPostProcessor()]
|
|
786
|
+
if pre_processors is None:
|
|
787
|
+
pre_processors = [pre.CombinePreProcessor()]
|
|
788
|
+
if constraints is None:
|
|
789
|
+
constraints = []
|
|
625
790
|
return few_shot(prompt=prompt,
|
|
626
791
|
examples=examples,
|
|
627
792
|
constraints=constraints,
|
|
@@ -634,15 +799,21 @@ def combine(prompt: str = "Add the two data types in a logical way:\n",
|
|
|
634
799
|
|
|
635
800
|
|
|
636
801
|
def negate(prompt: str = "Negate the following statement:\n",
|
|
637
|
-
default:
|
|
638
|
-
examples: prm.Prompt =
|
|
639
|
-
constraints:
|
|
802
|
+
default: str | None = None,
|
|
803
|
+
examples: prm.Prompt = _PROMPT_NEGATE_STATEMENT,
|
|
804
|
+
constraints: list[Callable] | None = None,
|
|
640
805
|
limit: int | None = 1,
|
|
641
|
-
stop: str |
|
|
642
|
-
pre_processors:
|
|
643
|
-
post_processors:
|
|
806
|
+
stop: str | list[str] = '',
|
|
807
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
808
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
644
809
|
**decorator_kwargs):
|
|
645
810
|
"""Negates a given statement."""
|
|
811
|
+
if post_processors is None:
|
|
812
|
+
post_processors = [post.StripPostProcessor()]
|
|
813
|
+
if pre_processors is None:
|
|
814
|
+
pre_processors = [pre.NegatePreProcessor()]
|
|
815
|
+
if constraints is None:
|
|
816
|
+
constraints = []
|
|
646
817
|
return few_shot(prompt=prompt,
|
|
647
818
|
examples=examples,
|
|
648
819
|
constraints=constraints,
|
|
@@ -656,14 +827,20 @@ def negate(prompt: str = "Negate the following statement:\n",
|
|
|
656
827
|
|
|
657
828
|
def contains(default: bool = False,
|
|
658
829
|
prompt: str = "Is semantically the information of 'A' contained in 'B'?\n",
|
|
659
|
-
examples: prm.Prompt =
|
|
660
|
-
constraints:
|
|
830
|
+
examples: prm.Prompt = _PROMPT_CONTAINS_VALUE,
|
|
831
|
+
constraints: list[Callable] | None = None,
|
|
661
832
|
limit: int | None = 1,
|
|
662
|
-
stop: str |
|
|
663
|
-
pre_processors:
|
|
664
|
-
post_processors:
|
|
833
|
+
stop: str | list[str] = '',
|
|
834
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
835
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
665
836
|
**decorator_kwargs):
|
|
666
837
|
"""Determines whether a given string contains another string."""
|
|
838
|
+
if post_processors is None:
|
|
839
|
+
post_processors = [post.StripPostProcessor()]
|
|
840
|
+
if pre_processors is None:
|
|
841
|
+
pre_processors = [pre.ContainsPreProcessor()]
|
|
842
|
+
if constraints is None:
|
|
843
|
+
constraints = []
|
|
667
844
|
return few_shot(prompt=prompt,
|
|
668
845
|
examples=examples,
|
|
669
846
|
constraints=constraints,
|
|
@@ -678,14 +855,20 @@ def contains(default: bool = False,
|
|
|
678
855
|
|
|
679
856
|
def isinstanceof(default: bool = False,
|
|
680
857
|
prompt: str = "Is 'A' an instance of 'B'?\n",
|
|
681
|
-
examples: prm.Prompt =
|
|
682
|
-
constraints:
|
|
858
|
+
examples: prm.Prompt = _PROMPT_IS_INSTANCE_OF,
|
|
859
|
+
constraints: list[Callable] | None = None,
|
|
683
860
|
limit: int | None = 1,
|
|
684
|
-
stop: str |
|
|
685
|
-
pre_processors:
|
|
686
|
-
post_processors:
|
|
861
|
+
stop: str | list[str] = '',
|
|
862
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
863
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
687
864
|
**decorator_kwargs):
|
|
688
865
|
"""Detects if one object is an instance of another."""
|
|
866
|
+
if post_processors is None:
|
|
867
|
+
post_processors = [post.StripPostProcessor()]
|
|
868
|
+
if pre_processors is None:
|
|
869
|
+
pre_processors = [pre.IsInstanceOfPreProcessor()]
|
|
870
|
+
if constraints is None:
|
|
871
|
+
constraints = []
|
|
689
872
|
return few_shot(prompt=prompt,
|
|
690
873
|
examples=examples,
|
|
691
874
|
constraints=constraints,
|
|
@@ -700,14 +883,20 @@ def isinstanceof(default: bool = False,
|
|
|
700
883
|
|
|
701
884
|
def startswith(default: bool = False,
|
|
702
885
|
prompt: str = "Does 'A' start with 'B'?\n",
|
|
703
|
-
examples: prm.Prompt =
|
|
704
|
-
constraints:
|
|
886
|
+
examples: prm.Prompt = _PROMPT_STARTS_WITH,
|
|
887
|
+
constraints: list[Callable] | None = None,
|
|
705
888
|
limit: int | None = 1,
|
|
706
|
-
stop: str |
|
|
707
|
-
pre_processors:
|
|
708
|
-
post_processors:
|
|
889
|
+
stop: str | list[str] = '',
|
|
890
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
891
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
709
892
|
**decorator_kwargs):
|
|
710
893
|
"""Determines whether a string starts with a specified prefix."""
|
|
894
|
+
if post_processors is None:
|
|
895
|
+
post_processors = [post.StripPostProcessor()]
|
|
896
|
+
if pre_processors is None:
|
|
897
|
+
pre_processors = [pre.StartsWithPreProcessor()]
|
|
898
|
+
if constraints is None:
|
|
899
|
+
constraints = []
|
|
711
900
|
return few_shot(prompt=prompt,
|
|
712
901
|
examples=examples,
|
|
713
902
|
constraints=constraints,
|
|
@@ -722,14 +911,20 @@ def startswith(default: bool = False,
|
|
|
722
911
|
|
|
723
912
|
def endswith(default: bool = False,
|
|
724
913
|
prompt: str = "Does 'A' end with 'B'?\n",
|
|
725
|
-
examples: prm.Prompt =
|
|
726
|
-
constraints:
|
|
914
|
+
examples: prm.Prompt = _PROMPT_ENDS_WITH,
|
|
915
|
+
constraints: list[Callable] | None = None,
|
|
727
916
|
limit: int | None = 1,
|
|
728
|
-
stop: str |
|
|
729
|
-
pre_processors:
|
|
730
|
-
post_processors:
|
|
917
|
+
stop: str | list[str] = '',
|
|
918
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
919
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
731
920
|
**decorator_kwargs):
|
|
732
921
|
"""Determines whether a string ends with a specified suffix."""
|
|
922
|
+
if post_processors is None:
|
|
923
|
+
post_processors = [post.StripPostProcessor()]
|
|
924
|
+
if pre_processors is None:
|
|
925
|
+
pre_processors = [pre.EndsWithPreProcessor()]
|
|
926
|
+
if constraints is None:
|
|
927
|
+
constraints = []
|
|
733
928
|
return few_shot(prompt=prompt,
|
|
734
929
|
examples=examples,
|
|
735
930
|
constraints=constraints,
|
|
@@ -742,16 +937,20 @@ def endswith(default: bool = False,
|
|
|
742
937
|
**decorator_kwargs)
|
|
743
938
|
|
|
744
939
|
|
|
745
|
-
def case(enum:
|
|
940
|
+
def case(enum: list[str],
|
|
746
941
|
default: str,
|
|
747
942
|
prompt: str = "Classify the text according to one of the following categories and return only the category name: ",
|
|
748
|
-
examples:
|
|
943
|
+
examples: prm.Prompt | None = None,
|
|
749
944
|
limit: int | None = 1,
|
|
750
|
-
stop: str |
|
|
751
|
-
pre_processors:
|
|
752
|
-
post_processors:
|
|
945
|
+
stop: str | list[str] = '',
|
|
946
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
947
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
753
948
|
**decorator_kwargs):
|
|
754
949
|
"""Classifies a text according to one of the given categories."""
|
|
950
|
+
if post_processors is None:
|
|
951
|
+
post_processors = [post.StripPostProcessor(), post.CaseInsensitivePostProcessor()]
|
|
952
|
+
if pre_processors is None:
|
|
953
|
+
pre_processors = [pre.EnumPreProcessor(), pre.TextMessagePreProcessor(), pre.PredictionMessagePreProcessor()]
|
|
755
954
|
return few_shot(prompt=prompt,
|
|
756
955
|
examples=examples,
|
|
757
956
|
default=default,
|
|
@@ -764,15 +963,21 @@ def case(enum: List[str],
|
|
|
764
963
|
|
|
765
964
|
|
|
766
965
|
def extract(prompt: str = "Extract a pattern from text:\n",
|
|
767
|
-
default:
|
|
768
|
-
examples: prm.Prompt =
|
|
769
|
-
constraints:
|
|
966
|
+
default: str | None = None,
|
|
967
|
+
examples: prm.Prompt = _PROMPT_EXTRACT_PATTERN,
|
|
968
|
+
constraints: list[Callable] | None = None,
|
|
770
969
|
limit: int | None = 1,
|
|
771
|
-
stop: str |
|
|
772
|
-
pre_processors:
|
|
773
|
-
post_processors:
|
|
970
|
+
stop: str | list[str] = '',
|
|
971
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
972
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
774
973
|
**decorator_kwargs):
|
|
775
974
|
"""Extracts a pattern from text."""
|
|
975
|
+
if post_processors is None:
|
|
976
|
+
post_processors = [post.StripPostProcessor()]
|
|
977
|
+
if pre_processors is None:
|
|
978
|
+
pre_processors = [pre.ExtractPatternPreProcessor()]
|
|
979
|
+
if constraints is None:
|
|
980
|
+
constraints = []
|
|
776
981
|
return few_shot(prompt=prompt,
|
|
777
982
|
examples=examples,
|
|
778
983
|
constraints=constraints,
|
|
@@ -784,11 +989,15 @@ def extract(prompt: str = "Extract a pattern from text:\n",
|
|
|
784
989
|
**decorator_kwargs)
|
|
785
990
|
|
|
786
991
|
def expression(prompt: str = "Evaluate the symbolic expressions:\n",
|
|
787
|
-
default:
|
|
788
|
-
pre_processors:
|
|
789
|
-
post_processors:
|
|
992
|
+
default: str | None = None,
|
|
993
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
994
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
790
995
|
**decorator_kwargs):
|
|
791
996
|
"""Evaluates the symbolic expressions."""
|
|
997
|
+
if post_processors is None:
|
|
998
|
+
post_processors = [post.WolframAlphaPostProcessor()]
|
|
999
|
+
if pre_processors is None:
|
|
1000
|
+
pre_processors = []
|
|
792
1001
|
def decorator(func):
|
|
793
1002
|
@functools.wraps(func)
|
|
794
1003
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -808,15 +1017,21 @@ def expression(prompt: str = "Evaluate the symbolic expressions:\n",
|
|
|
808
1017
|
|
|
809
1018
|
|
|
810
1019
|
def interpret(prompt: str = "Evaluate the symbolic expressions and return only the result:\n",
|
|
811
|
-
default:
|
|
812
|
-
examples: prm.Prompt =
|
|
813
|
-
constraints:
|
|
1020
|
+
default: str | None = None,
|
|
1021
|
+
examples: prm.Prompt = _PROMPT_SIMPLE_SYMBOLIC_EXPRESSION,
|
|
1022
|
+
constraints: list[Callable] | None = None,
|
|
814
1023
|
limit: int | None = 1,
|
|
815
|
-
stop: str |
|
|
816
|
-
pre_processors:
|
|
817
|
-
post_processors:
|
|
1024
|
+
stop: str | list[str] = '',
|
|
1025
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1026
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
818
1027
|
**decorator_kwargs):
|
|
819
1028
|
"""Evaluates the symbolic expressions by interpreting the semantic meaning."""
|
|
1029
|
+
if post_processors is None:
|
|
1030
|
+
post_processors = [post.StripPostProcessor()]
|
|
1031
|
+
if pre_processors is None:
|
|
1032
|
+
pre_processors = [pre.InterpretExpressionPreProcessor()]
|
|
1033
|
+
if constraints is None:
|
|
1034
|
+
constraints = []
|
|
820
1035
|
return few_shot(prompt=prompt,
|
|
821
1036
|
examples=examples,
|
|
822
1037
|
constraints=constraints,
|
|
@@ -830,15 +1045,21 @@ def interpret(prompt: str = "Evaluate the symbolic expressions and return only t
|
|
|
830
1045
|
|
|
831
1046
|
def logic(prompt: str = "Evaluate the logic expressions:\n",
|
|
832
1047
|
operator: str = 'and',
|
|
833
|
-
default:
|
|
834
|
-
examples: prm.Prompt =
|
|
835
|
-
constraints:
|
|
1048
|
+
default: str | None = None,
|
|
1049
|
+
examples: prm.Prompt = _PROMPT_LOGIC_EXPRESSION,
|
|
1050
|
+
constraints: list[Callable] | None = None,
|
|
836
1051
|
limit: int | None = 1,
|
|
837
|
-
stop: str |
|
|
838
|
-
pre_processors:
|
|
839
|
-
post_processors:
|
|
1052
|
+
stop: str | list[str] = '',
|
|
1053
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1054
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
840
1055
|
**decorator_kwargs):
|
|
841
1056
|
"""Evaluates a logic expression."""
|
|
1057
|
+
if post_processors is None:
|
|
1058
|
+
post_processors = [post.StripPostProcessor()]
|
|
1059
|
+
if pre_processors is None:
|
|
1060
|
+
pre_processors = [pre.LogicExpressionPreProcessor()]
|
|
1061
|
+
if constraints is None:
|
|
1062
|
+
constraints = []
|
|
842
1063
|
return few_shot(prompt=prompt,
|
|
843
1064
|
examples=examples,
|
|
844
1065
|
operator=operator,
|
|
@@ -852,15 +1073,21 @@ def logic(prompt: str = "Evaluate the logic expressions:\n",
|
|
|
852
1073
|
|
|
853
1074
|
|
|
854
1075
|
def invert(prompt: str = "Invert the logic of the content:\n",
|
|
855
|
-
default:
|
|
856
|
-
examples: prm.Prompt =
|
|
857
|
-
constraints:
|
|
1076
|
+
default: str | None = None,
|
|
1077
|
+
examples: prm.Prompt = _PROMPT_INVERT_EXPRESSION,
|
|
1078
|
+
constraints: list[Callable] | None = None,
|
|
858
1079
|
limit: int | None = 1,
|
|
859
|
-
stop: str |
|
|
860
|
-
pre_processors:
|
|
861
|
-
post_processors:
|
|
1080
|
+
stop: str | list[str] = '',
|
|
1081
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1082
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
862
1083
|
**decorator_kwargs):
|
|
863
1084
|
"""Inverts the logic of a statement."""
|
|
1085
|
+
if post_processors is None:
|
|
1086
|
+
post_processors = [post.StripPostProcessor()]
|
|
1087
|
+
if pre_processors is None:
|
|
1088
|
+
pre_processors = [pre.ArrowMessagePreProcessor()]
|
|
1089
|
+
if constraints is None:
|
|
1090
|
+
constraints = []
|
|
864
1091
|
return few_shot(prompt=prompt,
|
|
865
1092
|
examples=examples,
|
|
866
1093
|
constraints=constraints,
|
|
@@ -873,15 +1100,21 @@ def invert(prompt: str = "Invert the logic of the content:\n",
|
|
|
873
1100
|
|
|
874
1101
|
|
|
875
1102
|
def simulate(prompt: str = "Simulate the following code:\n",
|
|
876
|
-
default:
|
|
877
|
-
examples: prm.Prompt =
|
|
878
|
-
constraints:
|
|
1103
|
+
default: str | None = None,
|
|
1104
|
+
examples: prm.Prompt = _PROMPT_SIMULATE_CODE,
|
|
1105
|
+
constraints: list[Callable] | None = None,
|
|
879
1106
|
limit: int | None = 1,
|
|
880
|
-
stop: str |
|
|
881
|
-
pre_processors:
|
|
882
|
-
post_processors:
|
|
1107
|
+
stop: str | list[str] = '',
|
|
1108
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1109
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
883
1110
|
**decorator_kwargs):
|
|
884
1111
|
"""Simulates code and returns the result."""
|
|
1112
|
+
if post_processors is None:
|
|
1113
|
+
post_processors = [post.SplitPipePostProcessor(), post.TakeLastPostProcessor()]
|
|
1114
|
+
if pre_processors is None:
|
|
1115
|
+
pre_processors = [pre.SimulateCodePreProcessor()]
|
|
1116
|
+
if constraints is None:
|
|
1117
|
+
constraints = []
|
|
885
1118
|
return few_shot(prompt=prompt,
|
|
886
1119
|
examples=examples,
|
|
887
1120
|
constraints=constraints,
|
|
@@ -894,15 +1127,21 @@ def simulate(prompt: str = "Simulate the following code:\n",
|
|
|
894
1127
|
|
|
895
1128
|
|
|
896
1129
|
def code(prompt: str = "Generate code that solves the following problems:\n",
|
|
897
|
-
default:
|
|
898
|
-
examples: prm.Prompt =
|
|
899
|
-
constraints:
|
|
1130
|
+
default: str | None = None,
|
|
1131
|
+
examples: prm.Prompt = _PROMPT_GENERATE_CODE,
|
|
1132
|
+
constraints: list[Callable] | None = None,
|
|
900
1133
|
limit: int | None = 1,
|
|
901
|
-
stop: str |
|
|
902
|
-
pre_processors:
|
|
903
|
-
post_processors:
|
|
1134
|
+
stop: str | list[str] = '',
|
|
1135
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1136
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
904
1137
|
**decorator_kwargs):
|
|
905
1138
|
"""Generates code that solves a given problem."""
|
|
1139
|
+
if post_processors is None:
|
|
1140
|
+
post_processors = [post.StripPostProcessor()]
|
|
1141
|
+
if pre_processors is None:
|
|
1142
|
+
pre_processors = [pre.GenerateCodePreProcessor()]
|
|
1143
|
+
if constraints is None:
|
|
1144
|
+
constraints = []
|
|
906
1145
|
return few_shot(prompt=prompt,
|
|
907
1146
|
examples=examples,
|
|
908
1147
|
constraints=constraints,
|
|
@@ -915,15 +1154,21 @@ def code(prompt: str = "Generate code that solves the following problems:\n",
|
|
|
915
1154
|
|
|
916
1155
|
|
|
917
1156
|
def outline(prompt: str = "Outline only the essential content as a short list of bullets. Each bullet is in a new line:\n",
|
|
918
|
-
default:
|
|
919
|
-
examples: prm.Prompt =
|
|
920
|
-
constraints:
|
|
1157
|
+
default: list[str] | None = None,
|
|
1158
|
+
examples: prm.Prompt = _PROMPT_TEXT_TO_OUTLINE,
|
|
1159
|
+
constraints: list[Callable] | None = None,
|
|
921
1160
|
limit: int | None = 1,
|
|
922
|
-
stop: str |
|
|
923
|
-
pre_processors:
|
|
924
|
-
post_processors:
|
|
1161
|
+
stop: str | list[str] = '',
|
|
1162
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1163
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
925
1164
|
**decorator_kwargs):
|
|
926
1165
|
"""Outlines the essential content as a short list of bullets."""
|
|
1166
|
+
if post_processors is None:
|
|
1167
|
+
post_processors = [post.StripPostProcessor(), post.SplitNewLinePostProcessor()]
|
|
1168
|
+
if pre_processors is None:
|
|
1169
|
+
pre_processors = [pre.TextToOutlinePreProcessor()]
|
|
1170
|
+
if constraints is None:
|
|
1171
|
+
constraints = []
|
|
927
1172
|
return few_shot(prompt=prompt,
|
|
928
1173
|
examples=examples,
|
|
929
1174
|
constraints=constraints,
|
|
@@ -936,16 +1181,22 @@ def outline(prompt: str = "Outline only the essential content as a short list of
|
|
|
936
1181
|
|
|
937
1182
|
|
|
938
1183
|
def unique(prompt: str = "Create a short unique key that captures the essential topic from the following statements and does not collide with the list of keys:\n",
|
|
939
|
-
keys:
|
|
940
|
-
default:
|
|
941
|
-
examples: prm.Prompt =
|
|
942
|
-
constraints:
|
|
1184
|
+
keys: list[str] | None = None,
|
|
1185
|
+
default: list[str] | None = None,
|
|
1186
|
+
examples: prm.Prompt = _PROMPT_UNIQUE_KEY,
|
|
1187
|
+
constraints: list[Callable] | None = None,
|
|
943
1188
|
limit: int | None = 1,
|
|
944
|
-
stop: str |
|
|
945
|
-
pre_processors:
|
|
946
|
-
post_processors:
|
|
1189
|
+
stop: str | list[str] = '',
|
|
1190
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1191
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
947
1192
|
**decorator_kwargs):
|
|
948
1193
|
"""Creates a short, unique key that captures the essential topic from the given statements and does not collide with the list of keys."""
|
|
1194
|
+
if post_processors is None:
|
|
1195
|
+
post_processors = [post.StripPostProcessor()]
|
|
1196
|
+
if pre_processors is None:
|
|
1197
|
+
pre_processors = [pre.UniquePreProcessor()]
|
|
1198
|
+
if constraints is None:
|
|
1199
|
+
constraints = []
|
|
949
1200
|
return few_shot(prompt=prompt,
|
|
950
1201
|
keys=keys,
|
|
951
1202
|
examples=examples,
|
|
@@ -959,15 +1210,21 @@ def unique(prompt: str = "Create a short unique key that captures the essential
|
|
|
959
1210
|
|
|
960
1211
|
|
|
961
1212
|
def clean(prompt: str = "Clean up the text from special characters or escape sequences. DO NOT change any words or sentences! Keep original semantics:\n",
|
|
962
|
-
default:
|
|
963
|
-
examples: prm.Prompt =
|
|
964
|
-
constraints:
|
|
1213
|
+
default: list[str] | None = None,
|
|
1214
|
+
examples: prm.Prompt = _PROMPT_CLEAN_TEXT,
|
|
1215
|
+
constraints: list[Callable] | None = None,
|
|
965
1216
|
limit: int | None = 1,
|
|
966
|
-
stop: str |
|
|
967
|
-
pre_processors:
|
|
968
|
-
post_processors:
|
|
1217
|
+
stop: str | list[str] = '',
|
|
1218
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1219
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
969
1220
|
**decorator_kwargs):
|
|
970
1221
|
"""Cleans up a text from special characters and escape sequences."""
|
|
1222
|
+
if post_processors is None:
|
|
1223
|
+
post_processors = [post.StripPostProcessor()]
|
|
1224
|
+
if pre_processors is None:
|
|
1225
|
+
pre_processors = [pre.CleanTextMessagePreProcessor()]
|
|
1226
|
+
if constraints is None:
|
|
1227
|
+
constraints = []
|
|
971
1228
|
return few_shot(prompt=prompt,
|
|
972
1229
|
examples=examples,
|
|
973
1230
|
constraints=constraints,
|
|
@@ -980,15 +1237,21 @@ def clean(prompt: str = "Clean up the text from special characters or escape seq
|
|
|
980
1237
|
|
|
981
1238
|
|
|
982
1239
|
def compose(prompt: str = "Create a coherent text based on the facts listed in the outline:\n",
|
|
983
|
-
default:
|
|
984
|
-
examples:
|
|
985
|
-
constraints:
|
|
1240
|
+
default: str | None = None,
|
|
1241
|
+
examples: prm.Prompt | None = None,
|
|
1242
|
+
constraints: list[Callable] | None = None,
|
|
986
1243
|
limit: int | None = 1,
|
|
987
|
-
stop: str |
|
|
988
|
-
pre_processors:
|
|
989
|
-
post_processors:
|
|
1244
|
+
stop: str | list[str] = '',
|
|
1245
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1246
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
990
1247
|
**decorator_kwargs):
|
|
991
1248
|
"""Compose a coherent text based on an outline."""
|
|
1249
|
+
if post_processors is None:
|
|
1250
|
+
post_processors = [post.StripPostProcessor()]
|
|
1251
|
+
if pre_processors is None:
|
|
1252
|
+
pre_processors = [pre.GenerateTextPreProcessor()]
|
|
1253
|
+
if constraints is None:
|
|
1254
|
+
constraints = []
|
|
992
1255
|
return few_shot(prompt=prompt,
|
|
993
1256
|
examples=examples,
|
|
994
1257
|
constraints=constraints,
|
|
@@ -1003,15 +1266,21 @@ def compose(prompt: str = "Create a coherent text based on the facts listed in t
|
|
|
1003
1266
|
def foreach(condition: str,
|
|
1004
1267
|
apply: str,
|
|
1005
1268
|
prompt: str = "Iterate over each element and apply operation based on condition:\n",
|
|
1006
|
-
default:
|
|
1007
|
-
examples: prm.Prompt =
|
|
1008
|
-
constraints:
|
|
1269
|
+
default: str | None = None,
|
|
1270
|
+
examples: prm.Prompt = _PROMPT_FOR_EACH,
|
|
1271
|
+
constraints: list[Callable] | None = None,
|
|
1009
1272
|
limit: int | None = 1,
|
|
1010
|
-
stop: str |
|
|
1011
|
-
pre_processors:
|
|
1012
|
-
post_processors:
|
|
1273
|
+
stop: str | list[str] = '',
|
|
1274
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1275
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1013
1276
|
**decorator_kwargs):
|
|
1014
1277
|
"""Applies an operation based on a given condition to each element in a list."""
|
|
1278
|
+
if post_processors is None:
|
|
1279
|
+
post_processors = [post.StripPostProcessor()]
|
|
1280
|
+
if pre_processors is None:
|
|
1281
|
+
pre_processors = [pre.ForEachPreProcessor()]
|
|
1282
|
+
if constraints is None:
|
|
1283
|
+
constraints = []
|
|
1015
1284
|
return few_shot(prompt=prompt,
|
|
1016
1285
|
condition=condition,
|
|
1017
1286
|
apply=apply,
|
|
@@ -1027,15 +1296,21 @@ def foreach(condition: str,
|
|
|
1027
1296
|
|
|
1028
1297
|
def dictionary(context: str,
|
|
1029
1298
|
prompt: str = "Map related content together under a common abstract topic. Do not remove content:\n",
|
|
1030
|
-
default:
|
|
1031
|
-
examples: prm.Prompt =
|
|
1032
|
-
constraints:
|
|
1299
|
+
default: str | None = None,
|
|
1300
|
+
examples: prm.Prompt = _PROMPT_MAP_CONTENT,
|
|
1301
|
+
constraints: list[Callable] | None = None,
|
|
1033
1302
|
limit: int | None = 1,
|
|
1034
|
-
stop: str |
|
|
1035
|
-
pre_processors:
|
|
1036
|
-
post_processors:
|
|
1303
|
+
stop: str | list[str] = '',
|
|
1304
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1305
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1037
1306
|
**decorator_kwargs):
|
|
1038
1307
|
"""Maps related content together under a common abstract topic."""
|
|
1308
|
+
if post_processors is None:
|
|
1309
|
+
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
1310
|
+
if pre_processors is None:
|
|
1311
|
+
pre_processors = [pre.MapPreProcessor()]
|
|
1312
|
+
if constraints is None:
|
|
1313
|
+
constraints = []
|
|
1039
1314
|
return few_shot(prompt=prompt,
|
|
1040
1315
|
context=context,
|
|
1041
1316
|
examples=examples,
|
|
@@ -1049,15 +1324,21 @@ def dictionary(context: str,
|
|
|
1049
1324
|
|
|
1050
1325
|
def listing(condition: str,
|
|
1051
1326
|
prompt: str = "List each element contained in the text or list based on condition:\n",
|
|
1052
|
-
default:
|
|
1053
|
-
examples: prm.Prompt =
|
|
1054
|
-
constraints:
|
|
1055
|
-
stop: str |
|
|
1327
|
+
default: str | None = None,
|
|
1328
|
+
examples: prm.Prompt = _PROMPT_LIST_OBJECTS,
|
|
1329
|
+
constraints: list[Callable] | None = None,
|
|
1330
|
+
stop: str | list[str] = '',
|
|
1056
1331
|
limit: int | None = 1,
|
|
1057
|
-
pre_processors:
|
|
1058
|
-
post_processors:
|
|
1332
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1333
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1059
1334
|
**decorator_kwargs):
|
|
1060
1335
|
"""Lists each element contained in the text or list based on the given condition."""
|
|
1336
|
+
if post_processors is None:
|
|
1337
|
+
post_processors = [post.StripPostProcessor()]
|
|
1338
|
+
if pre_processors is None:
|
|
1339
|
+
pre_processors = [pre.ListPreProcessor()]
|
|
1340
|
+
if constraints is None:
|
|
1341
|
+
constraints = []
|
|
1061
1342
|
return few_shot(prompt=prompt,
|
|
1062
1343
|
condition=condition,
|
|
1063
1344
|
examples=examples,
|
|
@@ -1071,16 +1352,22 @@ def listing(condition: str,
|
|
|
1071
1352
|
|
|
1072
1353
|
|
|
1073
1354
|
def query(context: str,
|
|
1074
|
-
prompt:
|
|
1075
|
-
examples:
|
|
1076
|
-
constraints:
|
|
1077
|
-
default:
|
|
1078
|
-
stop: str |
|
|
1355
|
+
prompt: str | None = None,
|
|
1356
|
+
examples: prm.Prompt | None = None,
|
|
1357
|
+
constraints: list[Callable] | None = None,
|
|
1358
|
+
default: object | None = None,
|
|
1359
|
+
stop: str | list[str] = '',
|
|
1079
1360
|
limit: int | None = 1,
|
|
1080
|
-
pre_processors:
|
|
1081
|
-
post_processors:
|
|
1361
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1362
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1082
1363
|
**decorator_kwargs):
|
|
1083
1364
|
"""Performs a query given a context."""
|
|
1365
|
+
if post_processors is None:
|
|
1366
|
+
post_processors = [post.StripPostProcessor()]
|
|
1367
|
+
if pre_processors is None:
|
|
1368
|
+
pre_processors = [pre.QueryPreProcessor()]
|
|
1369
|
+
if constraints is None:
|
|
1370
|
+
constraints = []
|
|
1084
1371
|
return few_shot(prompt=prompt,
|
|
1085
1372
|
context=context,
|
|
1086
1373
|
examples=examples,
|
|
@@ -1093,16 +1380,20 @@ def query(context: str,
|
|
|
1093
1380
|
**decorator_kwargs)
|
|
1094
1381
|
|
|
1095
1382
|
|
|
1096
|
-
def expand(prompt:
|
|
1097
|
-
examples:
|
|
1098
|
-
constraints:
|
|
1099
|
-
default:
|
|
1100
|
-
stop: str |
|
|
1383
|
+
def expand(prompt: str | None = 'Write a self-contained function (with all imports) to solve a specific user problem task. Label the function with a name that describes the task.',
|
|
1384
|
+
examples: prm.Prompt | None = _PROMPT_EXPAND_FUNCTION,
|
|
1385
|
+
constraints: list[Callable] | None = None,
|
|
1386
|
+
default: object | None = None,
|
|
1387
|
+
stop: str | list[str] = '',
|
|
1101
1388
|
limit: int | None = 1,
|
|
1102
|
-
pre_processors:
|
|
1103
|
-
post_processors:
|
|
1389
|
+
pre_processors: list[pre.PreProcessor] | None = _PREPROCESSOR_EXPAND_FUNCTION,
|
|
1390
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1104
1391
|
**decorator_kwargs):
|
|
1105
1392
|
"""Performs a expand command given a context to generate new prompts."""
|
|
1393
|
+
if post_processors is None:
|
|
1394
|
+
post_processors = [post.StripPostProcessor(), post.ExpandFunctionPostProcessor()]
|
|
1395
|
+
if constraints is None:
|
|
1396
|
+
constraints = []
|
|
1106
1397
|
return few_shot(prompt=prompt,
|
|
1107
1398
|
examples=examples,
|
|
1108
1399
|
constraints=constraints,
|
|
@@ -1115,12 +1406,14 @@ def expand(prompt: Optional[str] = 'Write a self-contained function (with all im
|
|
|
1115
1406
|
|
|
1116
1407
|
|
|
1117
1408
|
def search(query: str,
|
|
1118
|
-
constraints:
|
|
1119
|
-
default:
|
|
1120
|
-
pre_processors:
|
|
1121
|
-
post_processors:
|
|
1409
|
+
constraints: list[Callable] | None = None,
|
|
1410
|
+
default: object | None = None,
|
|
1411
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1412
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1122
1413
|
**decorator_kwargs):
|
|
1123
1414
|
"""Searches for a given query on the internet."""
|
|
1415
|
+
if constraints is None:
|
|
1416
|
+
constraints = []
|
|
1124
1417
|
def decorator(func):
|
|
1125
1418
|
@functools.wraps(func)
|
|
1126
1419
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1141,12 +1434,16 @@ def search(query: str,
|
|
|
1141
1434
|
|
|
1142
1435
|
|
|
1143
1436
|
def opening(path: str,
|
|
1144
|
-
constraints:
|
|
1145
|
-
default:
|
|
1146
|
-
pre_processors:
|
|
1147
|
-
post_processors:
|
|
1437
|
+
constraints: list[Callable] | None = None,
|
|
1438
|
+
default: object | None = None,
|
|
1439
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1440
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1148
1441
|
**decorator_kwargs):
|
|
1149
1442
|
"""Opens a file and applies a given function to it."""
|
|
1443
|
+
if post_processors is None:
|
|
1444
|
+
post_processors = [post.StripPostProcessor()]
|
|
1445
|
+
if constraints is None:
|
|
1446
|
+
constraints = []
|
|
1150
1447
|
def decorator(func):
|
|
1151
1448
|
@functools.wraps(func)
|
|
1152
1449
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1166,11 +1463,13 @@ def opening(path: str,
|
|
|
1166
1463
|
return decorator
|
|
1167
1464
|
|
|
1168
1465
|
|
|
1169
|
-
def embed(entries:
|
|
1170
|
-
pre_processors:
|
|
1171
|
-
post_processors:
|
|
1466
|
+
def embed(entries: list[str],
|
|
1467
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1468
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1172
1469
|
**decorator_kwargs):
|
|
1173
1470
|
"""Embeds the entries provided in a decorated function."""
|
|
1471
|
+
if pre_processors is None:
|
|
1472
|
+
pre_processors = [pre.UnwrapListSymbolsPreProcessor()]
|
|
1174
1473
|
def decorator(func):
|
|
1175
1474
|
@functools.wraps(func)
|
|
1176
1475
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1188,11 +1487,15 @@ def embed(entries: List[str],
|
|
|
1188
1487
|
return decorator
|
|
1189
1488
|
|
|
1190
1489
|
|
|
1191
|
-
def cluster(entries:
|
|
1192
|
-
pre_processors:
|
|
1193
|
-
post_processors:
|
|
1490
|
+
def cluster(entries: list[str],
|
|
1491
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1492
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1194
1493
|
**decorator_kwargs):
|
|
1195
1494
|
"""Embeds and clusters the input entries."""
|
|
1495
|
+
if post_processors is None:
|
|
1496
|
+
post_processors = [post.ClusterPostProcessor()]
|
|
1497
|
+
if pre_processors is None:
|
|
1498
|
+
pre_processors = [pre.UnwrapListSymbolsPreProcessor()]
|
|
1196
1499
|
assert any(isinstance(pr, post.ClusterPostProcessor) for pr in post_processors), "At least one post processor must be a 'ClusterPostProcessor' for clustering!"
|
|
1197
1500
|
for post_pr in post_processors:
|
|
1198
1501
|
if isinstance(post_pr, post.ClusterPostProcessor):
|
|
@@ -1206,10 +1509,12 @@ def cluster(entries: List[str],
|
|
|
1206
1509
|
|
|
1207
1510
|
def draw(operation: str = 'create',
|
|
1208
1511
|
prompt: str = '',
|
|
1209
|
-
pre_processors:
|
|
1210
|
-
post_processors:
|
|
1512
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1513
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1211
1514
|
**decorator_kwargs):
|
|
1212
1515
|
"""Draws an image provided in a decorated function."""
|
|
1516
|
+
if pre_processors is None:
|
|
1517
|
+
pre_processors = [pre.ValuePreProcessor()]
|
|
1213
1518
|
def decorator(func):
|
|
1214
1519
|
@functools.wraps(func)
|
|
1215
1520
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1228,10 +1533,10 @@ def draw(operation: str = 'create',
|
|
|
1228
1533
|
return decorator
|
|
1229
1534
|
|
|
1230
1535
|
|
|
1231
|
-
def text_vision(image:
|
|
1232
|
-
text:
|
|
1233
|
-
pre_processors:
|
|
1234
|
-
post_processors:
|
|
1536
|
+
def text_vision(image: str | bytes | None = None,
|
|
1537
|
+
text: list[str] | None = None,
|
|
1538
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1539
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1235
1540
|
**decorator_kwargs):
|
|
1236
1541
|
"""Performs vision-related associative tasks. Currently limited to CLIP model embeddings."""
|
|
1237
1542
|
def decorator(func):
|
|
@@ -1253,8 +1558,8 @@ def text_vision(image: Optional[str|bytes] = None,
|
|
|
1253
1558
|
|
|
1254
1559
|
|
|
1255
1560
|
def ocr(image: str,
|
|
1256
|
-
pre_processors:
|
|
1257
|
-
post_processors:
|
|
1561
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1562
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1258
1563
|
**decorator_kwargs):
|
|
1259
1564
|
"""Performs Optical Character Recognition (OCR) on an image."""
|
|
1260
1565
|
def decorator(func):
|
|
@@ -1275,8 +1580,8 @@ def ocr(image: str,
|
|
|
1275
1580
|
|
|
1276
1581
|
|
|
1277
1582
|
def speech_to_text(prompt: str = 'decode',
|
|
1278
|
-
pre_processors:
|
|
1279
|
-
post_processors:
|
|
1583
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1584
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1280
1585
|
**decorator_kwargs):
|
|
1281
1586
|
"""Decorates the given function for speech recognition."""
|
|
1282
1587
|
def decorator(func):
|
|
@@ -1299,8 +1604,8 @@ def speech_to_text(prompt: str = 'decode',
|
|
|
1299
1604
|
def text_to_speech(prompt: str,
|
|
1300
1605
|
path: str,
|
|
1301
1606
|
voice: str = 'nova',
|
|
1302
|
-
pre_processors:
|
|
1303
|
-
post_processors:
|
|
1607
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1608
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1304
1609
|
**decorator_kwargs):
|
|
1305
1610
|
"""Decorates the given function for text to speech synthesis."""
|
|
1306
1611
|
def decorator(func):
|
|
@@ -1322,12 +1627,18 @@ def text_to_speech(prompt: str,
|
|
|
1322
1627
|
return decorator
|
|
1323
1628
|
|
|
1324
1629
|
|
|
1325
|
-
def output(constraints:
|
|
1326
|
-
default:
|
|
1327
|
-
pre_processors:
|
|
1328
|
-
post_processors:
|
|
1630
|
+
def output(constraints: list[Callable] | None = None,
|
|
1631
|
+
default: object | None = None,
|
|
1632
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1633
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1329
1634
|
**decorator_kwargs):
|
|
1330
1635
|
"""Offers an output stream for writing results."""
|
|
1636
|
+
if post_processors is None:
|
|
1637
|
+
post_processors = [post.ConsolePostProcessor()]
|
|
1638
|
+
if pre_processors is None:
|
|
1639
|
+
pre_processors = [pre.ConsolePreProcessor()]
|
|
1640
|
+
if constraints is None:
|
|
1641
|
+
constraints = []
|
|
1331
1642
|
def decorator(func):
|
|
1332
1643
|
@functools.wraps(func)
|
|
1333
1644
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1347,12 +1658,18 @@ def output(constraints: List[Callable] = [],
|
|
|
1347
1658
|
|
|
1348
1659
|
|
|
1349
1660
|
def scrape(url: str,
|
|
1350
|
-
constraints:
|
|
1351
|
-
default:
|
|
1352
|
-
pre_processors:
|
|
1353
|
-
post_processors:
|
|
1661
|
+
constraints: list[Callable] | None = None,
|
|
1662
|
+
default: object | None = None,
|
|
1663
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1664
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1354
1665
|
**decorator_kwargs):
|
|
1355
1666
|
"""Fetches data from a given URL and applies the provided post-processors."""
|
|
1667
|
+
if post_processors is None:
|
|
1668
|
+
post_processors = []
|
|
1669
|
+
if pre_processors is None:
|
|
1670
|
+
pre_processors = []
|
|
1671
|
+
if constraints is None:
|
|
1672
|
+
constraints = []
|
|
1356
1673
|
def decorator(func):
|
|
1357
1674
|
@functools.wraps(func)
|
|
1358
1675
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1371,12 +1688,18 @@ def scrape(url: str,
|
|
|
1371
1688
|
return decorator
|
|
1372
1689
|
|
|
1373
1690
|
|
|
1374
|
-
def userinput(constraints:
|
|
1375
|
-
default:
|
|
1376
|
-
pre_processors:
|
|
1377
|
-
post_processors:
|
|
1691
|
+
def userinput(constraints: list[Callable] | None = None,
|
|
1692
|
+
default: object | None = None,
|
|
1693
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1694
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1378
1695
|
**decorator_kwargs):
|
|
1379
1696
|
"""Prompts for user input and returns the user response through a decorator."""
|
|
1697
|
+
if post_processors is None:
|
|
1698
|
+
post_processors = [post.StripPostProcessor()]
|
|
1699
|
+
if pre_processors is None:
|
|
1700
|
+
pre_processors = [pre.ConsoleInputPreProcessor()]
|
|
1701
|
+
if constraints is None:
|
|
1702
|
+
constraints = []
|
|
1380
1703
|
def decorator(func):
|
|
1381
1704
|
@functools.wraps(func)
|
|
1382
1705
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1395,12 +1718,18 @@ def userinput(constraints: List[Callable] = [],
|
|
|
1395
1718
|
return decorator
|
|
1396
1719
|
|
|
1397
1720
|
|
|
1398
|
-
def execute(default:
|
|
1399
|
-
constraints:
|
|
1400
|
-
pre_processors:
|
|
1401
|
-
post_processors:
|
|
1721
|
+
def execute(default: str | None = None,
|
|
1722
|
+
constraints: list[Callable] | None = None,
|
|
1723
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1724
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1402
1725
|
**decorator_kwargs):
|
|
1403
1726
|
"""Executes a given function after applying constraints, pre-processing and post-processing."""
|
|
1727
|
+
if post_processors is None:
|
|
1728
|
+
post_processors = []
|
|
1729
|
+
if pre_processors is None:
|
|
1730
|
+
pre_processors = []
|
|
1731
|
+
if constraints is None:
|
|
1732
|
+
constraints = []
|
|
1404
1733
|
def decorator(func):
|
|
1405
1734
|
@functools.wraps(func)
|
|
1406
1735
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1422,12 +1751,18 @@ def execute(default: Optional[str] = None,
|
|
|
1422
1751
|
def index(prompt: Any,
|
|
1423
1752
|
index_name: str,
|
|
1424
1753
|
operation: str = 'search', # | add | config
|
|
1425
|
-
default:
|
|
1426
|
-
constraints:
|
|
1427
|
-
pre_processors:
|
|
1428
|
-
post_processors:
|
|
1754
|
+
default: str | None = None,
|
|
1755
|
+
constraints: list[Callable] | None = None,
|
|
1756
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1757
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1429
1758
|
**decorator_kwargs):
|
|
1430
1759
|
"""Query for a given index and returns the result through a decorator."""
|
|
1760
|
+
if post_processors is None:
|
|
1761
|
+
post_processors = []
|
|
1762
|
+
if pre_processors is None:
|
|
1763
|
+
pre_processors = []
|
|
1764
|
+
if constraints is None:
|
|
1765
|
+
constraints = []
|
|
1431
1766
|
def decorator(func):
|
|
1432
1767
|
@functools.wraps(func)
|
|
1433
1768
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
@@ -1449,8 +1784,10 @@ def index(prompt: Any,
|
|
|
1449
1784
|
return decorator
|
|
1450
1785
|
|
|
1451
1786
|
|
|
1452
|
-
def command(engines:
|
|
1787
|
+
def command(engines: list[str] | None = None, **decorator_kwargs):
|
|
1453
1788
|
"""Decorates a function to forward commands to the engine backends."""
|
|
1789
|
+
if engines is None:
|
|
1790
|
+
engines = ['all']
|
|
1454
1791
|
def decorator(func):
|
|
1455
1792
|
@functools.wraps(func)
|
|
1456
1793
|
def wrapper(instance):
|
|
@@ -1464,7 +1801,7 @@ def command(engines: List[str] = ['all'], **decorator_kwargs):
|
|
|
1464
1801
|
return decorator
|
|
1465
1802
|
|
|
1466
1803
|
|
|
1467
|
-
def register(engines:
|
|
1804
|
+
def register(engines: dict[str, Any]):
|
|
1468
1805
|
"""Decorates a function to initialize custom engines as backends."""
|
|
1469
1806
|
def decorator(func):
|
|
1470
1807
|
@functools.wraps(func)
|
|
@@ -1480,8 +1817,8 @@ def register(engines: Dict[str, Any]):
|
|
|
1480
1817
|
|
|
1481
1818
|
|
|
1482
1819
|
def tune(operation: str = 'create',
|
|
1483
|
-
pre_processors:
|
|
1484
|
-
post_processors:
|
|
1820
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1821
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1485
1822
|
**decorator_kwargs):
|
|
1486
1823
|
"""Fine tune a LLM."""
|
|
1487
1824
|
def decorator(func):
|
|
@@ -1503,10 +1840,12 @@ def tune(operation: str = 'create',
|
|
|
1503
1840
|
|
|
1504
1841
|
def caption(image: str,
|
|
1505
1842
|
prompt: str,
|
|
1506
|
-
pre_processors:
|
|
1507
|
-
post_processors:
|
|
1843
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1844
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1508
1845
|
**decorator_kwargs):
|
|
1509
1846
|
"""Caption the content of an image."""
|
|
1847
|
+
if pre_processors is None:
|
|
1848
|
+
pre_processors = [pre.ValuePreProcessor()]
|
|
1510
1849
|
def decorator(func):
|
|
1511
1850
|
@functools.wraps(func)
|
|
1512
1851
|
def wrapper(instance, *signature_args, **signature_kwargs):
|