symbolicai 1.0.0__py3-none-any.whl → 1.1.1__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 +198 -134
- symai/backend/base.py +51 -51
- symai/backend/engines/drawing/engine_bfl.py +33 -33
- symai/backend/engines/drawing/engine_gpt_image.py +4 -10
- symai/backend/engines/embedding/engine_llama_cpp.py +50 -35
- symai/backend/engines/embedding/engine_openai.py +22 -16
- symai/backend/engines/execute/engine_python.py +16 -16
- symai/backend/engines/files/engine_io.py +51 -49
- symai/backend/engines/imagecaptioning/engine_blip2.py +27 -23
- symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +53 -46
- symai/backend/engines/index/engine_pinecone.py +116 -88
- symai/backend/engines/index/engine_qdrant.py +1011 -0
- symai/backend/engines/index/engine_vectordb.py +78 -52
- symai/backend/engines/lean/engine_lean4.py +65 -25
- symai/backend/engines/neurosymbolic/__init__.py +35 -28
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +137 -135
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +145 -152
- symai/backend/engines/neurosymbolic/engine_cerebras.py +328 -0
- symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +75 -49
- symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +199 -155
- symai/backend/engines/neurosymbolic/engine_groq.py +106 -72
- symai/backend/engines/neurosymbolic/engine_huggingface.py +100 -67
- symai/backend/engines/neurosymbolic/engine_llama_cpp.py +121 -93
- symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +213 -132
- symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +180 -137
- symai/backend/engines/ocr/engine_apilayer.py +18 -20
- symai/backend/engines/output/engine_stdout.py +9 -9
- symai/backend/engines/{webscraping → scrape}/engine_requests.py +25 -11
- symai/backend/engines/search/engine_openai.py +95 -83
- symai/backend/engines/search/engine_parallel.py +665 -0
- symai/backend/engines/search/engine_perplexity.py +40 -41
- symai/backend/engines/search/engine_serpapi.py +33 -28
- symai/backend/engines/speech_to_text/engine_local_whisper.py +37 -27
- symai/backend/engines/symbolic/engine_wolframalpha.py +14 -8
- symai/backend/engines/text_to_speech/engine_openai.py +15 -19
- symai/backend/engines/text_vision/engine_clip.py +34 -28
- symai/backend/engines/userinput/engine_console.py +3 -4
- symai/backend/mixin/__init__.py +4 -0
- symai/backend/mixin/anthropic.py +48 -40
- symai/backend/mixin/cerebras.py +9 -0
- symai/backend/mixin/deepseek.py +4 -5
- symai/backend/mixin/google.py +5 -4
- symai/backend/mixin/groq.py +2 -4
- symai/backend/mixin/openai.py +132 -110
- symai/backend/settings.py +14 -14
- symai/chat.py +164 -94
- symai/collect/dynamic.py +13 -11
- symai/collect/pipeline.py +39 -31
- symai/collect/stats.py +109 -69
- symai/components.py +578 -238
- symai/constraints.py +14 -5
- symai/core.py +1495 -1210
- symai/core_ext.py +55 -50
- symai/endpoints/api.py +113 -58
- symai/extended/api_builder.py +22 -17
- symai/extended/arxiv_pdf_parser.py +13 -5
- symai/extended/bibtex_parser.py +8 -4
- symai/extended/conversation.py +88 -69
- symai/extended/document.py +40 -27
- symai/extended/file_merger.py +45 -7
- symai/extended/graph.py +38 -24
- symai/extended/html_style_template.py +17 -11
- symai/extended/interfaces/blip_2.py +1 -1
- symai/extended/interfaces/clip.py +4 -2
- symai/extended/interfaces/console.py +5 -3
- symai/extended/interfaces/dall_e.py +3 -1
- symai/extended/interfaces/file.py +2 -0
- symai/extended/interfaces/flux.py +3 -1
- symai/extended/interfaces/gpt_image.py +15 -6
- symai/extended/interfaces/input.py +2 -1
- symai/extended/interfaces/llava.py +1 -1
- symai/extended/interfaces/{naive_webscraping.py → naive_scrape.py} +3 -2
- symai/extended/interfaces/naive_vectordb.py +2 -2
- symai/extended/interfaces/ocr.py +4 -2
- symai/extended/interfaces/openai_search.py +2 -0
- symai/extended/interfaces/parallel.py +30 -0
- symai/extended/interfaces/perplexity.py +2 -0
- symai/extended/interfaces/pinecone.py +6 -4
- symai/extended/interfaces/python.py +2 -0
- symai/extended/interfaces/serpapi.py +2 -0
- symai/extended/interfaces/terminal.py +0 -1
- symai/extended/interfaces/tts.py +2 -1
- symai/extended/interfaces/whisper.py +2 -1
- symai/extended/interfaces/wolframalpha.py +1 -0
- symai/extended/metrics/__init__.py +1 -1
- symai/extended/metrics/similarity.py +5 -2
- symai/extended/os_command.py +31 -22
- symai/extended/packages/symdev.py +39 -34
- symai/extended/packages/sympkg.py +30 -27
- symai/extended/packages/symrun.py +46 -35
- symai/extended/repo_cloner.py +10 -9
- symai/extended/seo_query_optimizer.py +15 -12
- symai/extended/solver.py +104 -76
- symai/extended/summarizer.py +8 -7
- symai/extended/taypan_interpreter.py +10 -9
- symai/extended/vectordb.py +28 -15
- symai/formatter/formatter.py +39 -31
- symai/formatter/regex.py +46 -44
- symai/functional.py +184 -86
- symai/imports.py +85 -51
- symai/interfaces.py +1 -1
- symai/memory.py +33 -24
- symai/menu/screen.py +28 -19
- symai/misc/console.py +27 -27
- symai/misc/loader.py +4 -3
- symai/models/base.py +147 -76
- symai/models/errors.py +1 -1
- symai/ops/__init__.py +1 -1
- symai/ops/measures.py +17 -14
- symai/ops/primitives.py +933 -635
- symai/post_processors.py +28 -24
- symai/pre_processors.py +58 -52
- symai/processor.py +15 -9
- symai/prompts.py +714 -649
- symai/server/huggingface_server.py +115 -32
- symai/server/llama_cpp_server.py +14 -6
- symai/server/qdrant_server.py +206 -0
- symai/shell.py +98 -39
- symai/shellsv.py +307 -223
- symai/strategy.py +135 -81
- symai/symbol.py +276 -225
- symai/utils.py +62 -46
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/METADATA +19 -9
- symbolicai-1.1.1.dist-info/RECORD +169 -0
- symbolicai-1.0.0.dist-info/RECORD +0 -163
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/WHEEL +0 -0
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/entry_points.txt +0 -0
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/licenses/LICENSE +0 -0
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/top_level.txt +0 -0
symai/core.py
CHANGED
|
@@ -50,18 +50,19 @@ _PROMPT_UNIQUE_KEY = prm.UniqueKey()
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
class Argument(Expression):
|
|
53
|
-
_default_suppress_verbose_output
|
|
54
|
-
_default_parse_system_instructions
|
|
55
|
-
_default_preview_value
|
|
53
|
+
_default_suppress_verbose_output = False
|
|
54
|
+
_default_parse_system_instructions = False
|
|
55
|
+
_default_preview_value = False
|
|
56
56
|
|
|
57
57
|
def __init__(self, args, signature_kwargs, decorator_kwargs, **kwargs):
|
|
58
58
|
super().__init__(**kwargs)
|
|
59
|
-
self.args
|
|
59
|
+
self.args = args # there is only signature args
|
|
60
60
|
self.signature_kwargs = signature_kwargs.copy()
|
|
61
61
|
self.decorator_kwargs = decorator_kwargs.copy()
|
|
62
|
-
self.kwargs
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
self.kwargs = self._construct_kwargs(
|
|
63
|
+
signature_kwargs=signature_kwargs, decorator_kwargs=decorator_kwargs
|
|
64
|
+
)
|
|
65
|
+
self.prop = Metadata()
|
|
65
66
|
self._set_all_kwargs_as_properties()
|
|
66
67
|
self._apply_default_properties()
|
|
67
68
|
|
|
@@ -74,25 +75,25 @@ class Argument(Expression):
|
|
|
74
75
|
# Reserved keywords
|
|
75
76
|
default_properties = {
|
|
76
77
|
# used for previewing the input (also for operators)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
"preview": Argument._default_preview_value,
|
|
79
|
+
"raw_input": False,
|
|
80
|
+
"raw_output": False,
|
|
81
|
+
"return_metadata": False,
|
|
82
|
+
"logging": False,
|
|
83
|
+
"verbose": False,
|
|
84
|
+
"self_prompt": False,
|
|
85
|
+
"truncation_percentage": None,
|
|
86
|
+
"truncation_type": "tail",
|
|
87
|
+
"response_format": None,
|
|
88
|
+
"log_level": None,
|
|
89
|
+
"time_clock": None,
|
|
90
|
+
"payload": None,
|
|
91
|
+
"processed_input": None,
|
|
92
|
+
"template_suffix": None,
|
|
93
|
+
"input_handler": None,
|
|
94
|
+
"output_handler": None,
|
|
95
|
+
"suppress_verbose_output": Argument._default_suppress_verbose_output,
|
|
96
|
+
"parse_system_instructions": Argument._default_parse_system_instructions,
|
|
96
97
|
}
|
|
97
98
|
for key, default_value in default_properties.items():
|
|
98
99
|
if key not in self.kwargs:
|
|
@@ -100,16 +101,18 @@ class Argument(Expression):
|
|
|
100
101
|
|
|
101
102
|
@property
|
|
102
103
|
def value(self):
|
|
103
|
-
return Box(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
return Box(
|
|
105
|
+
{
|
|
106
|
+
"args": self.args,
|
|
107
|
+
"signature_kwargs": self.signature_kwargs,
|
|
108
|
+
"decorator_kwargs": self.decorator_kwargs,
|
|
109
|
+
"kwargs": self.kwargs,
|
|
110
|
+
"prop": self.prop,
|
|
111
|
+
}
|
|
112
|
+
)
|
|
110
113
|
|
|
111
114
|
def _construct_kwargs(self, signature_kwargs, decorator_kwargs):
|
|
112
|
-
|
|
115
|
+
"""
|
|
113
116
|
Combines and overrides the decorator args and kwargs with the runtime signature args and kwargs.
|
|
114
117
|
|
|
115
118
|
Args:
|
|
@@ -118,7 +121,7 @@ class Argument(Expression):
|
|
|
118
121
|
|
|
119
122
|
Returns:
|
|
120
123
|
Dict: The combined and overridden kwargs.
|
|
121
|
-
|
|
124
|
+
"""
|
|
122
125
|
# Initialize with the decorator kwargs
|
|
123
126
|
kwargs = {**decorator_kwargs}
|
|
124
127
|
# Override the decorator kwargs with the signature kwargs
|
|
@@ -127,77 +130,86 @@ class Argument(Expression):
|
|
|
127
130
|
return kwargs
|
|
128
131
|
|
|
129
132
|
|
|
130
|
-
def few_shot(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
def few_shot(
|
|
134
|
+
prompt: str = "",
|
|
135
|
+
examples: prm.Prompt = None,
|
|
136
|
+
constraints: list[Callable] | None = None,
|
|
137
|
+
default: Any = None,
|
|
138
|
+
limit: int = 1,
|
|
139
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
140
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
141
|
+
**decorator_kwargs,
|
|
142
|
+
):
|
|
143
|
+
""" "General decorator for the neural processing engine."""
|
|
139
144
|
if constraints is None:
|
|
140
145
|
constraints = []
|
|
141
146
|
if examples is None:
|
|
142
147
|
examples = []
|
|
148
|
+
|
|
143
149
|
def decorator(func):
|
|
144
150
|
@functools.wraps(func)
|
|
145
151
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
146
152
|
# Construct container object for the arguments and kwargs
|
|
147
|
-
decorator_kwargs[
|
|
148
|
-
decorator_kwargs[
|
|
153
|
+
decorator_kwargs["prompt"] = prompt
|
|
154
|
+
decorator_kwargs["examples"] = examples
|
|
149
155
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
150
156
|
return EngineRepository.query(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
engine="neurosymbolic",
|
|
158
|
+
instance=instance,
|
|
159
|
+
func=func,
|
|
160
|
+
constraints=constraints,
|
|
161
|
+
default=default,
|
|
162
|
+
limit=limit,
|
|
163
|
+
pre_processors=pre_processors,
|
|
164
|
+
post_processors=post_processors,
|
|
165
|
+
argument=argument,
|
|
166
|
+
)
|
|
167
|
+
|
|
160
168
|
return wrapper
|
|
169
|
+
|
|
161
170
|
return decorator
|
|
162
171
|
|
|
163
172
|
|
|
164
|
-
def zero_shot(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
def zero_shot(
|
|
174
|
+
prompt: str = "",
|
|
175
|
+
constraints: list[Callable] | None = None,
|
|
176
|
+
default: object | None = None,
|
|
177
|
+
limit: int = 1,
|
|
178
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
179
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
180
|
+
**decorator_kwargs,
|
|
181
|
+
):
|
|
182
|
+
""" "General decorator for the neural processing engine."""
|
|
172
183
|
if constraints is None:
|
|
173
184
|
constraints = []
|
|
174
|
-
return few_shot(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
return few_shot(
|
|
186
|
+
prompt,
|
|
187
|
+
examples=[],
|
|
188
|
+
constraints=constraints,
|
|
189
|
+
default=default,
|
|
190
|
+
limit=limit,
|
|
191
|
+
pre_processors=pre_processors,
|
|
192
|
+
post_processors=post_processors,
|
|
193
|
+
**decorator_kwargs,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def prompt(message: str, **decorator_kwargs):
|
|
186
198
|
"""General decorator for the neural processing engine."""
|
|
187
|
-
return few_shot(processed_input=message,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
return few_shot(processed_input=message, raw_input=True, **decorator_kwargs)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def summarize(
|
|
203
|
+
prompt: str = "Summarize the content of the following text:\n",
|
|
204
|
+
context: str | None = None,
|
|
205
|
+
constraints: list[Callable] | None = None,
|
|
206
|
+
default: object | None = None,
|
|
207
|
+
limit: int = 1,
|
|
208
|
+
stop: str | list[str] = "",
|
|
209
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
210
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
211
|
+
**decorator_kwargs,
|
|
212
|
+
):
|
|
201
213
|
"""Summarizes the content of a text."""
|
|
202
214
|
if post_processors is None:
|
|
203
215
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -205,28 +217,32 @@ def summarize(prompt: str = 'Summarize the content of the following text:\n',
|
|
|
205
217
|
pre_processors = [pre.SummaryPreProcessing()]
|
|
206
218
|
if constraints is None:
|
|
207
219
|
constraints = []
|
|
208
|
-
return few_shot(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
220
|
+
return few_shot(
|
|
221
|
+
prompt,
|
|
222
|
+
context=context,
|
|
223
|
+
examples=[],
|
|
224
|
+
constraints=constraints,
|
|
225
|
+
default=default,
|
|
226
|
+
limit=limit,
|
|
227
|
+
stop=stop,
|
|
228
|
+
pre_processors=pre_processors,
|
|
229
|
+
post_processors=post_processors,
|
|
230
|
+
**decorator_kwargs,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def equals(
|
|
235
|
+
context: str = "contextually",
|
|
236
|
+
default: bool = False,
|
|
237
|
+
prompt: str = "Make a fuzzy equals comparison; are the following objects {} the same?\n",
|
|
238
|
+
examples: prm.Prompt = _PROMPT_FUZZY_EQUALS,
|
|
239
|
+
constraints: list[Callable] | None = None,
|
|
240
|
+
limit: int = 1,
|
|
241
|
+
stop: str | list[str] = "",
|
|
242
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
243
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
244
|
+
**decorator_kwargs,
|
|
245
|
+
):
|
|
230
246
|
"""Equality function for two objects."""
|
|
231
247
|
if post_processors is None:
|
|
232
248
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -234,28 +250,32 @@ def equals(context: str = 'contextually',
|
|
|
234
250
|
pre_processors = [pre.EqualsPreProcessor()]
|
|
235
251
|
if constraints is None:
|
|
236
252
|
constraints = []
|
|
237
|
-
return few_shot(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
return few_shot(
|
|
254
|
+
prompt=prompt.format(context),
|
|
255
|
+
examples=examples,
|
|
256
|
+
constraints=constraints,
|
|
257
|
+
default=default,
|
|
258
|
+
limit=limit,
|
|
259
|
+
stop=stop,
|
|
260
|
+
max_tokens=None,
|
|
261
|
+
pre_processors=pre_processors,
|
|
262
|
+
post_processors=post_processors,
|
|
263
|
+
**decorator_kwargs,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def sufficient(
|
|
268
|
+
query: str,
|
|
269
|
+
prompt: str = "Consider if there is sufficient information to answer the query:\n",
|
|
270
|
+
default: bool = False,
|
|
271
|
+
examples: prm.Prompt = _PROMPT_SUFFICIENT_INFORMATION,
|
|
272
|
+
constraints: list[Callable] | None = None,
|
|
273
|
+
limit: int = 1,
|
|
274
|
+
stop: str | list[str] = "",
|
|
275
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
276
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
277
|
+
**decorator_kwargs,
|
|
278
|
+
) -> bool:
|
|
259
279
|
"""Determines if there is sufficient information to answer the given query."""
|
|
260
280
|
if post_processors is None:
|
|
261
281
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -263,28 +283,32 @@ def sufficient(query: str,
|
|
|
263
283
|
pre_processors = [pre.SufficientInformationPreProcessor()]
|
|
264
284
|
if constraints is None:
|
|
265
285
|
constraints = []
|
|
266
|
-
return few_shot(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
return few_shot(
|
|
287
|
+
prompt=prompt,
|
|
288
|
+
query=query,
|
|
289
|
+
examples=examples,
|
|
290
|
+
constraints=constraints,
|
|
291
|
+
default=default,
|
|
292
|
+
limit=limit,
|
|
293
|
+
stop=stop,
|
|
294
|
+
max_tokens=None,
|
|
295
|
+
pre_processors=pre_processors,
|
|
296
|
+
post_processors=post_processors,
|
|
297
|
+
**decorator_kwargs,
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def delitem(
|
|
302
|
+
default: str | None = None,
|
|
303
|
+
prompt: str = "Delete the items at the index position:\n",
|
|
304
|
+
examples: prm.Prompt = _PROMPT_REMOVE_INDEX,
|
|
305
|
+
constraints: list[Callable] | None = None,
|
|
306
|
+
limit: int = 1,
|
|
307
|
+
stop: str | list[str] = "",
|
|
308
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
309
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
310
|
+
**decorator_kwargs,
|
|
311
|
+
):
|
|
288
312
|
"""Deletes the items at the specified index position."""
|
|
289
313
|
if post_processors is None:
|
|
290
314
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -292,26 +316,30 @@ def delitem(default: str | None = None,
|
|
|
292
316
|
pre_processors = [pre.DeleteIndexPreProcessor()]
|
|
293
317
|
if constraints is None:
|
|
294
318
|
constraints = []
|
|
295
|
-
return few_shot(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
return few_shot(
|
|
320
|
+
prompt=prompt,
|
|
321
|
+
examples=examples,
|
|
322
|
+
constraints=constraints,
|
|
323
|
+
default=default,
|
|
324
|
+
limit=limit,
|
|
325
|
+
stop=stop,
|
|
326
|
+
pre_processors=pre_processors,
|
|
327
|
+
post_processors=post_processors,
|
|
328
|
+
**decorator_kwargs,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def setitem(
|
|
333
|
+
default: str | None = None,
|
|
334
|
+
prompt: str = "Set item at index position:\n",
|
|
335
|
+
examples: prm.Prompt = _PROMPT_SET_INDEX,
|
|
336
|
+
constraints: list[Callable] | None = None,
|
|
337
|
+
limit: int = 1,
|
|
338
|
+
stop: str | list[str] = "",
|
|
339
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
340
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
341
|
+
**decorator_kwargs,
|
|
342
|
+
):
|
|
315
343
|
"""Sets an item at a given index position in a sequence."""
|
|
316
344
|
if post_processors is None:
|
|
317
345
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -319,26 +347,30 @@ def setitem(default: str | None = None,
|
|
|
319
347
|
pre_processors = [pre.SetIndexPreProcessor()]
|
|
320
348
|
if constraints is None:
|
|
321
349
|
constraints = []
|
|
322
|
-
return few_shot(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
350
|
+
return few_shot(
|
|
351
|
+
prompt=prompt,
|
|
352
|
+
examples=examples,
|
|
353
|
+
constraints=constraints,
|
|
354
|
+
default=default,
|
|
355
|
+
limit=limit,
|
|
356
|
+
stop=stop,
|
|
357
|
+
pre_processors=pre_processors,
|
|
358
|
+
post_processors=post_processors,
|
|
359
|
+
**decorator_kwargs,
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def getitem(
|
|
364
|
+
default: str | None = None,
|
|
365
|
+
prompt: str = "Get item at index position:\n",
|
|
366
|
+
examples: prm.Prompt = _PROMPT_INDEX,
|
|
367
|
+
constraints: list[Callable] | None = None,
|
|
368
|
+
limit: int = 1,
|
|
369
|
+
stop: str | list[str] = "",
|
|
370
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
371
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
372
|
+
**decorator_kwargs,
|
|
373
|
+
):
|
|
342
374
|
"""Retrieves the item at the given index position."""
|
|
343
375
|
if post_processors is None:
|
|
344
376
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -346,27 +378,31 @@ def getitem(default: str | None = None,
|
|
|
346
378
|
pre_processors = [pre.IndexPreProcessor()]
|
|
347
379
|
if constraints is None:
|
|
348
380
|
constraints = []
|
|
349
|
-
return few_shot(
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
381
|
+
return few_shot(
|
|
382
|
+
prompt=prompt,
|
|
383
|
+
examples=examples,
|
|
384
|
+
constraints=constraints,
|
|
385
|
+
default=default,
|
|
386
|
+
limit=limit,
|
|
387
|
+
stop=stop,
|
|
388
|
+
pre_processors=pre_processors,
|
|
389
|
+
post_processors=post_processors,
|
|
390
|
+
**decorator_kwargs,
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def modify(
|
|
395
|
+
changes: str,
|
|
396
|
+
default: str | None = None,
|
|
397
|
+
prompt: str = "Modify the text to match the criteria:\n",
|
|
398
|
+
examples: prm.Prompt = _PROMPT_MODIFY,
|
|
399
|
+
constraints: list[Callable] | None = None,
|
|
400
|
+
limit: int = 1,
|
|
401
|
+
stop: str | list[str] = "",
|
|
402
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
403
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
404
|
+
**decorator_kwargs,
|
|
405
|
+
):
|
|
370
406
|
"""A function to modify a text based on a set of criteria."""
|
|
371
407
|
if post_processors is None:
|
|
372
408
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -374,29 +410,33 @@ def modify(changes: str,
|
|
|
374
410
|
pre_processors = [pre.ModifyPreProcessor()]
|
|
375
411
|
if constraints is None:
|
|
376
412
|
constraints = []
|
|
377
|
-
return few_shot(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
413
|
+
return few_shot(
|
|
414
|
+
prompt=prompt,
|
|
415
|
+
changes=changes,
|
|
416
|
+
examples=examples,
|
|
417
|
+
constraints=constraints,
|
|
418
|
+
default=default,
|
|
419
|
+
limit=limit,
|
|
420
|
+
stop=stop,
|
|
421
|
+
pre_processors=pre_processors,
|
|
422
|
+
post_processors=post_processors,
|
|
423
|
+
**decorator_kwargs,
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def filtering(
|
|
428
|
+
criteria: str,
|
|
429
|
+
include: bool = False,
|
|
430
|
+
default: str | None = None,
|
|
431
|
+
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",
|
|
432
|
+
examples: prm.Prompt = _PROMPT_FILTER,
|
|
433
|
+
constraints: list[Callable] | None = None,
|
|
434
|
+
limit: int = 1,
|
|
435
|
+
stop: str | list[str] = "",
|
|
436
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
437
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
438
|
+
**decorator_kwargs,
|
|
439
|
+
):
|
|
400
440
|
"""Filter information from a text based on a set of criteria."""
|
|
401
441
|
if post_processors is None:
|
|
402
442
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -404,30 +444,33 @@ def filtering(criteria: str,
|
|
|
404
444
|
pre_processors = [pre.FilterPreProcessor()]
|
|
405
445
|
if constraints is None:
|
|
406
446
|
constraints = []
|
|
407
|
-
return few_shot(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
447
|
+
return few_shot(
|
|
448
|
+
prompt=prompt,
|
|
449
|
+
criteria=criteria,
|
|
450
|
+
include=include,
|
|
451
|
+
examples=examples,
|
|
452
|
+
constraints=constraints,
|
|
453
|
+
default=default,
|
|
454
|
+
limit=limit,
|
|
455
|
+
stop=stop,
|
|
456
|
+
pre_processors=pre_processors,
|
|
457
|
+
post_processors=post_processors,
|
|
458
|
+
**decorator_kwargs,
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def map( # noqa: A001
|
|
463
|
+
instruction: str,
|
|
464
|
+
default: str | None = None,
|
|
465
|
+
prompt: str = "Transform each element in the input based on the instruction. Preserve container type and elements that don't match the instruction:\n",
|
|
466
|
+
examples: prm.Prompt = _PROMPT_MAP_EXPRESSION,
|
|
467
|
+
constraints: list[Callable] | None = None,
|
|
468
|
+
limit: int | None = 1,
|
|
469
|
+
stop: str | list[str] = "",
|
|
470
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
471
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
472
|
+
**decorator_kwargs,
|
|
473
|
+
):
|
|
431
474
|
"""Semantic mapping operation that applies an instruction to each element in an iterable."""
|
|
432
475
|
if post_processors is None:
|
|
433
476
|
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
@@ -435,28 +478,32 @@ def map( # noqa: A001
|
|
|
435
478
|
pre_processors = [pre.MapExpressionPreProcessor()]
|
|
436
479
|
if constraints is None:
|
|
437
480
|
constraints = []
|
|
438
|
-
return few_shot(
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
481
|
+
return few_shot(
|
|
482
|
+
prompt=prompt,
|
|
483
|
+
examples=examples,
|
|
484
|
+
constraints=constraints,
|
|
485
|
+
default=default,
|
|
486
|
+
limit=limit,
|
|
487
|
+
stop=stop,
|
|
488
|
+
context=instruction,
|
|
489
|
+
pre_processors=pre_processors,
|
|
490
|
+
post_processors=post_processors,
|
|
491
|
+
**decorator_kwargs,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def notify(
|
|
496
|
+
subscriber: dict[str, Callable],
|
|
497
|
+
default: object | None = None,
|
|
498
|
+
prompt: str = "List the semantically related topics:\n",
|
|
499
|
+
examples: prm.Prompt = _PROMPT_SEMANTIC_MAPPING,
|
|
500
|
+
constraints: list[Callable] | None = None,
|
|
501
|
+
limit: int | None = 1,
|
|
502
|
+
stop: str | list[str] = "",
|
|
503
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
504
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
505
|
+
**decorator_kwargs,
|
|
506
|
+
):
|
|
460
507
|
"""Notify subscribers based on a set of topics if detected in the input text and matching the key of the subscriber."""
|
|
461
508
|
if post_processors is None:
|
|
462
509
|
post_processors = [post.SplitPipePostProcessor(), post.NotifySubscriberPostProcessor()]
|
|
@@ -464,28 +511,32 @@ def notify(subscriber: dict[str, Callable],
|
|
|
464
511
|
pre_processors = [pre.SemanticMappingPreProcessor()]
|
|
465
512
|
if constraints is None:
|
|
466
513
|
constraints = []
|
|
467
|
-
return few_shot(
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
514
|
+
return few_shot(
|
|
515
|
+
prompt=prompt,
|
|
516
|
+
subscriber=subscriber,
|
|
517
|
+
examples=examples,
|
|
518
|
+
constraints=constraints,
|
|
519
|
+
default=default,
|
|
520
|
+
limit=limit,
|
|
521
|
+
stop=stop,
|
|
522
|
+
pre_processors=pre_processors,
|
|
523
|
+
post_processors=post_processors,
|
|
524
|
+
**decorator_kwargs,
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def compare(
|
|
529
|
+
default: bool = False,
|
|
530
|
+
operator: str = ">",
|
|
531
|
+
prompt: str = "Compare 'A' and 'B' based on the operator:\n",
|
|
532
|
+
examples: prm.Prompt = _PROMPT_COMPARE_VALUES,
|
|
533
|
+
constraints: list[Callable] | None = None,
|
|
534
|
+
limit: int | None = 1,
|
|
535
|
+
stop: str | list[str] = "",
|
|
536
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
537
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
538
|
+
**decorator_kwargs,
|
|
539
|
+
):
|
|
489
540
|
"""Compare two objects based on the specified operator."""
|
|
490
541
|
if post_processors is None:
|
|
491
542
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -493,30 +544,33 @@ def compare(default: bool = False,
|
|
|
493
544
|
pre_processors = [pre.ComparePreProcessor()]
|
|
494
545
|
if constraints is None:
|
|
495
546
|
constraints = []
|
|
496
|
-
return few_shot(
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
547
|
+
return few_shot(
|
|
548
|
+
prompt=prompt,
|
|
549
|
+
examples=examples,
|
|
550
|
+
constraints=constraints,
|
|
551
|
+
default=default,
|
|
552
|
+
limit=limit,
|
|
553
|
+
stop=stop,
|
|
554
|
+
max_tokens=None,
|
|
555
|
+
operator=operator,
|
|
556
|
+
pre_processors=pre_processors,
|
|
557
|
+
post_processors=post_processors,
|
|
558
|
+
**decorator_kwargs,
|
|
559
|
+
)
|
|
507
560
|
|
|
508
561
|
|
|
509
562
|
def convert(
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
563
|
+
format: str,
|
|
564
|
+
default: str | None = None,
|
|
565
|
+
prompt: str = "Translate the following text into {} format.\n",
|
|
566
|
+
examples: prm.Prompt = _PROMPT_FORMAT,
|
|
567
|
+
constraints: list[Callable] | None = None,
|
|
568
|
+
limit: int | None = 1,
|
|
569
|
+
stop: str | list[str] = "",
|
|
570
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
571
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
572
|
+
**decorator_kwargs,
|
|
573
|
+
):
|
|
520
574
|
"""Transformation operation from one format to another."""
|
|
521
575
|
if post_processors is None:
|
|
522
576
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -524,28 +578,32 @@ def convert(
|
|
|
524
578
|
pre_processors = [pre.TextFormatPreProcessor()]
|
|
525
579
|
if constraints is None:
|
|
526
580
|
constraints = []
|
|
527
|
-
return few_shot(
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
581
|
+
return few_shot(
|
|
582
|
+
prompt=prompt,
|
|
583
|
+
examples=examples,
|
|
584
|
+
constraints=constraints,
|
|
585
|
+
default=default,
|
|
586
|
+
limit=limit,
|
|
587
|
+
stop=stop,
|
|
588
|
+
format=format,
|
|
589
|
+
pre_processors=pre_processors,
|
|
590
|
+
post_processors=post_processors,
|
|
591
|
+
**decorator_kwargs,
|
|
592
|
+
)
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def transcribe(
|
|
596
|
+
modify: str,
|
|
597
|
+
default: str | None = None,
|
|
598
|
+
prompt: str = "Transcribe the following text by only modifying the text by the provided instruction.\n",
|
|
599
|
+
examples: prm.Prompt = _PROMPT_TRANSCRIPTION,
|
|
600
|
+
constraints: list[Callable] | None = None,
|
|
601
|
+
limit: int | None = 1,
|
|
602
|
+
stop: str | list[str] = "",
|
|
603
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
604
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
605
|
+
**decorator_kwargs,
|
|
606
|
+
):
|
|
549
607
|
"""Transcription operation of a text to another styled text."""
|
|
550
608
|
if post_processors is None:
|
|
551
609
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -553,28 +611,32 @@ def transcribe(modify: str,
|
|
|
553
611
|
pre_processors = [pre.TranscriptionPreProcessor()]
|
|
554
612
|
if constraints is None:
|
|
555
613
|
constraints = []
|
|
556
|
-
return few_shot(
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
614
|
+
return few_shot(
|
|
615
|
+
prompt=prompt,
|
|
616
|
+
examples=examples,
|
|
617
|
+
constraints=constraints,
|
|
618
|
+
default=default,
|
|
619
|
+
limit=limit,
|
|
620
|
+
stop=stop,
|
|
621
|
+
modify=modify,
|
|
622
|
+
pre_processors=pre_processors,
|
|
623
|
+
post_processors=post_processors,
|
|
624
|
+
**decorator_kwargs,
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def style(
|
|
629
|
+
description: str,
|
|
630
|
+
libraries: list[str] | None = None,
|
|
631
|
+
default: str | None = None,
|
|
632
|
+
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",
|
|
633
|
+
constraints: list[Callable] | None = None,
|
|
634
|
+
limit: int | None = 1,
|
|
635
|
+
stop: str | list[str] = "",
|
|
636
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
637
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
638
|
+
**decorator_kwargs,
|
|
639
|
+
):
|
|
578
640
|
"""Styles a given text based on best practices and a given description."""
|
|
579
641
|
if post_processors is None:
|
|
580
642
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -584,30 +646,34 @@ def style(description: str,
|
|
|
584
646
|
constraints = []
|
|
585
647
|
if libraries is None:
|
|
586
648
|
libraries = []
|
|
587
|
-
return few_shot(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
649
|
+
return few_shot(
|
|
650
|
+
prompt=prompt,
|
|
651
|
+
libraries=libraries,
|
|
652
|
+
examples=None,
|
|
653
|
+
constraints=constraints,
|
|
654
|
+
default=default,
|
|
655
|
+
limit=limit,
|
|
656
|
+
stop=stop,
|
|
657
|
+
description=description,
|
|
658
|
+
pre_processors=pre_processors,
|
|
659
|
+
post_processors=post_processors,
|
|
660
|
+
**decorator_kwargs,
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def analyze(
|
|
665
|
+
query: str,
|
|
666
|
+
exception: Exception,
|
|
667
|
+
default: str | None = None,
|
|
668
|
+
prompt: str = "Only analyze the error message and suggest a potential correction, however, do NOT provide the code!\n",
|
|
669
|
+
examples: prm.Prompt = _PROMPT_EXCEPTION_MAPPING,
|
|
670
|
+
constraints: list[Callable] | None = None,
|
|
671
|
+
limit: int | None = 1,
|
|
672
|
+
stop: str | list[str] = "",
|
|
673
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
674
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
675
|
+
**decorator_kwargs,
|
|
676
|
+
):
|
|
611
677
|
"""Analyses an Exception and proposes a correction."""
|
|
612
678
|
if post_processors is None:
|
|
613
679
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -615,30 +681,34 @@ def analyze(query: str,
|
|
|
615
681
|
pre_processors = [pre.ExceptionPreProcessor()]
|
|
616
682
|
if constraints is None:
|
|
617
683
|
constraints = []
|
|
618
|
-
return few_shot(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
684
|
+
return few_shot(
|
|
685
|
+
prompt=prompt,
|
|
686
|
+
query=query,
|
|
687
|
+
exception=exception,
|
|
688
|
+
examples=examples,
|
|
689
|
+
constraints=constraints,
|
|
690
|
+
default=default,
|
|
691
|
+
limit=limit,
|
|
692
|
+
stop=stop,
|
|
693
|
+
pre_processors=pre_processors,
|
|
694
|
+
post_processors=post_processors,
|
|
695
|
+
**decorator_kwargs,
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def correct(
|
|
700
|
+
context: str,
|
|
701
|
+
exception: Exception,
|
|
702
|
+
default: str | None = None,
|
|
703
|
+
prompt: str = "Correct the code according to the context description. Use markdown syntax to format the code; do not provide any other text.\n",
|
|
704
|
+
examples: prm.Prompt | None = None,
|
|
705
|
+
constraints: list[Callable] | None = None,
|
|
706
|
+
limit: int | None = 1,
|
|
707
|
+
stop: str | list[str] = "",
|
|
708
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
709
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
710
|
+
**decorator_kwargs,
|
|
711
|
+
):
|
|
642
712
|
"""Analyses an Exception and proposes a correction."""
|
|
643
713
|
if post_processors is None:
|
|
644
714
|
post_processors = [post.StripPostProcessor(), post.CodeExtractPostProcessor()]
|
|
@@ -646,29 +716,33 @@ def correct(context: str,
|
|
|
646
716
|
pre_processors = [pre.CorrectionPreProcessor()]
|
|
647
717
|
if constraints is None:
|
|
648
718
|
constraints = []
|
|
649
|
-
return few_shot(
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
719
|
+
return few_shot(
|
|
720
|
+
prompt=prompt,
|
|
721
|
+
context=context,
|
|
722
|
+
exception=exception,
|
|
723
|
+
examples=examples,
|
|
724
|
+
constraints=constraints,
|
|
725
|
+
default=default,
|
|
726
|
+
limit=limit,
|
|
727
|
+
stop=stop,
|
|
728
|
+
pre_processors=pre_processors,
|
|
729
|
+
post_processors=post_processors,
|
|
730
|
+
**decorator_kwargs,
|
|
731
|
+
)
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
def translate(
|
|
735
|
+
language: str = "English",
|
|
736
|
+
default: str = "Sorry, I do not understand the given language.",
|
|
737
|
+
prompt: str = "Your task is to translate and **only** translate the text into {}:\n",
|
|
738
|
+
examples: prm.Prompt | None = None,
|
|
739
|
+
constraints: list[Callable] | None = None,
|
|
740
|
+
limit: int | None = 1,
|
|
741
|
+
stop: str | list[str] = "",
|
|
742
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
743
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
744
|
+
**decorator_kwargs,
|
|
745
|
+
):
|
|
672
746
|
"""Translates a given text into a specified language."""
|
|
673
747
|
if post_processors is None:
|
|
674
748
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -676,28 +750,32 @@ def translate(language: str = 'English',
|
|
|
676
750
|
pre_processors = [pre.LanguagePreProcessor()]
|
|
677
751
|
if constraints is None:
|
|
678
752
|
constraints = []
|
|
679
|
-
return few_shot(
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
753
|
+
return few_shot(
|
|
754
|
+
prompt=prompt,
|
|
755
|
+
examples=examples,
|
|
756
|
+
constraints=constraints,
|
|
757
|
+
default=default,
|
|
758
|
+
limit=limit,
|
|
759
|
+
stop=stop,
|
|
760
|
+
language=language,
|
|
761
|
+
pre_processors=pre_processors,
|
|
762
|
+
post_processors=post_processors,
|
|
763
|
+
**decorator_kwargs,
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
def rank(
|
|
768
|
+
default: object | None = None,
|
|
769
|
+
order: str = "desc",
|
|
770
|
+
prompt: str = "Order the list of objects based on their quality measure and oder literal:\n",
|
|
771
|
+
examples: prm.Prompt = _PROMPT_RANK_LIST,
|
|
772
|
+
constraints: list[Callable] | None = None,
|
|
773
|
+
limit: int | None = 1,
|
|
774
|
+
stop: str | list[str] = "",
|
|
775
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
776
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
777
|
+
**decorator_kwargs,
|
|
778
|
+
):
|
|
701
779
|
"""Ranks a list of objects based on their quality measure and order literal."""
|
|
702
780
|
if post_processors is None:
|
|
703
781
|
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
@@ -705,27 +783,31 @@ def rank(default: object | None = None,
|
|
|
705
783
|
pre_processors = [pre.RankPreProcessor()]
|
|
706
784
|
if constraints is None:
|
|
707
785
|
constraints = []
|
|
708
|
-
return few_shot(
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
786
|
+
return few_shot(
|
|
787
|
+
prompt=prompt,
|
|
788
|
+
examples=examples,
|
|
789
|
+
constraints=constraints,
|
|
790
|
+
default=default,
|
|
791
|
+
limit=limit,
|
|
792
|
+
stop=stop,
|
|
793
|
+
order=order,
|
|
794
|
+
pre_processors=pre_processors,
|
|
795
|
+
post_processors=post_processors,
|
|
796
|
+
**decorator_kwargs,
|
|
797
|
+
)
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
def replace(
|
|
801
|
+
prompt: str = "Replace text parts by string pattern.\n",
|
|
802
|
+
default: str | None = None,
|
|
803
|
+
examples: prm.Prompt = _PROMPT_REPLACE_TEXT,
|
|
804
|
+
constraints: list[Callable] | None = None,
|
|
805
|
+
limit: int | None = 1,
|
|
806
|
+
stop: str | list[str] = "",
|
|
807
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
808
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
809
|
+
**decorator_kwargs,
|
|
810
|
+
):
|
|
729
811
|
"""Replaces text parts by a given string pattern."""
|
|
730
812
|
if post_processors is None:
|
|
731
813
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -733,26 +815,30 @@ def replace(prompt: str = "Replace text parts by string pattern.\n",
|
|
|
733
815
|
pre_processors = [pre.ReplacePreProcessor()]
|
|
734
816
|
if constraints is None:
|
|
735
817
|
constraints = []
|
|
736
|
-
return few_shot(
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
818
|
+
return few_shot(
|
|
819
|
+
prompt=prompt,
|
|
820
|
+
examples=examples,
|
|
821
|
+
constraints=constraints,
|
|
822
|
+
default=default,
|
|
823
|
+
limit=limit,
|
|
824
|
+
stop=stop,
|
|
825
|
+
pre_processors=pre_processors,
|
|
826
|
+
post_processors=post_processors,
|
|
827
|
+
**decorator_kwargs,
|
|
828
|
+
)
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
def include(
|
|
832
|
+
prompt: str = "Include information based on description.\n",
|
|
833
|
+
default: str | None = None,
|
|
834
|
+
examples: prm.Prompt = _PROMPT_INCLUDE_TEXT,
|
|
835
|
+
constraints: list[Callable] | None = None,
|
|
836
|
+
limit: int | None = 1,
|
|
837
|
+
stop: str | list[str] = "",
|
|
838
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
839
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
840
|
+
**decorator_kwargs,
|
|
841
|
+
):
|
|
756
842
|
"""Include information from a description."""
|
|
757
843
|
if post_processors is None:
|
|
758
844
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -760,26 +846,30 @@ def include(prompt: str = "Include information based on description.\n",
|
|
|
760
846
|
pre_processors = [pre.IncludePreProcessor()]
|
|
761
847
|
if constraints is None:
|
|
762
848
|
constraints = []
|
|
763
|
-
return few_shot(
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
849
|
+
return few_shot(
|
|
850
|
+
prompt=prompt,
|
|
851
|
+
examples=examples,
|
|
852
|
+
constraints=constraints,
|
|
853
|
+
default=default,
|
|
854
|
+
limit=limit,
|
|
855
|
+
stop=stop,
|
|
856
|
+
pre_processors=pre_processors,
|
|
857
|
+
post_processors=post_processors,
|
|
858
|
+
**decorator_kwargs,
|
|
859
|
+
)
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
def combine(
|
|
863
|
+
prompt: str = "Add the two data types in a logical way:\n",
|
|
864
|
+
default: str | None = None,
|
|
865
|
+
examples: prm.Prompt = _PROMPT_COMBINE_TEXT,
|
|
866
|
+
constraints: list[Callable] | None = None,
|
|
867
|
+
limit: int | None = 1,
|
|
868
|
+
stop: str | list[str] = "",
|
|
869
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
870
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
871
|
+
**decorator_kwargs,
|
|
872
|
+
):
|
|
783
873
|
"""Combines two data types in a logical way."""
|
|
784
874
|
if post_processors is None:
|
|
785
875
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -787,26 +877,30 @@ def combine(prompt: str = "Add the two data types in a logical way:\n",
|
|
|
787
877
|
pre_processors = [pre.CombinePreProcessor()]
|
|
788
878
|
if constraints is None:
|
|
789
879
|
constraints = []
|
|
790
|
-
return few_shot(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
880
|
+
return few_shot(
|
|
881
|
+
prompt=prompt,
|
|
882
|
+
examples=examples,
|
|
883
|
+
constraints=constraints,
|
|
884
|
+
default=default,
|
|
885
|
+
limit=limit,
|
|
886
|
+
stop=stop,
|
|
887
|
+
pre_processors=pre_processors,
|
|
888
|
+
post_processors=post_processors,
|
|
889
|
+
**decorator_kwargs,
|
|
890
|
+
)
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
def negate(
|
|
894
|
+
prompt: str = "Negate the following statement:\n",
|
|
895
|
+
default: str | None = None,
|
|
896
|
+
examples: prm.Prompt = _PROMPT_NEGATE_STATEMENT,
|
|
897
|
+
constraints: list[Callable] | None = None,
|
|
898
|
+
limit: int | None = 1,
|
|
899
|
+
stop: str | list[str] = "",
|
|
900
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
901
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
902
|
+
**decorator_kwargs,
|
|
903
|
+
):
|
|
810
904
|
"""Negates a given statement."""
|
|
811
905
|
if post_processors is None:
|
|
812
906
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -814,26 +908,30 @@ def negate(prompt: str = "Negate the following statement:\n",
|
|
|
814
908
|
pre_processors = [pre.NegatePreProcessor()]
|
|
815
909
|
if constraints is None:
|
|
816
910
|
constraints = []
|
|
817
|
-
return few_shot(
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
911
|
+
return few_shot(
|
|
912
|
+
prompt=prompt,
|
|
913
|
+
examples=examples,
|
|
914
|
+
constraints=constraints,
|
|
915
|
+
default=default,
|
|
916
|
+
limit=limit,
|
|
917
|
+
stop=stop,
|
|
918
|
+
pre_processors=pre_processors,
|
|
919
|
+
post_processors=post_processors,
|
|
920
|
+
**decorator_kwargs,
|
|
921
|
+
)
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
def contains(
|
|
925
|
+
default: bool = False,
|
|
926
|
+
prompt: str = "Is semantically the information of 'A' contained in 'B'?\n",
|
|
927
|
+
examples: prm.Prompt = _PROMPT_CONTAINS_VALUE,
|
|
928
|
+
constraints: list[Callable] | None = None,
|
|
929
|
+
limit: int | None = 1,
|
|
930
|
+
stop: str | list[str] = "",
|
|
931
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
932
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
933
|
+
**decorator_kwargs,
|
|
934
|
+
):
|
|
837
935
|
"""Determines whether a given string contains another string."""
|
|
838
936
|
if post_processors is None:
|
|
839
937
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -841,27 +939,31 @@ def contains(default: bool = False,
|
|
|
841
939
|
pre_processors = [pre.ContainsPreProcessor()]
|
|
842
940
|
if constraints is None:
|
|
843
941
|
constraints = []
|
|
844
|
-
return few_shot(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
942
|
+
return few_shot(
|
|
943
|
+
prompt=prompt,
|
|
944
|
+
examples=examples,
|
|
945
|
+
constraints=constraints,
|
|
946
|
+
default=default,
|
|
947
|
+
limit=limit,
|
|
948
|
+
stop=stop,
|
|
949
|
+
max_tokens=None,
|
|
950
|
+
pre_processors=pre_processors,
|
|
951
|
+
post_processors=post_processors,
|
|
952
|
+
**decorator_kwargs,
|
|
953
|
+
)
|
|
954
|
+
|
|
955
|
+
|
|
956
|
+
def isinstanceof(
|
|
957
|
+
default: bool = False,
|
|
958
|
+
prompt: str = "Is 'A' an instance of 'B'?\n",
|
|
959
|
+
examples: prm.Prompt = _PROMPT_IS_INSTANCE_OF,
|
|
960
|
+
constraints: list[Callable] | None = None,
|
|
961
|
+
limit: int | None = 1,
|
|
962
|
+
stop: str | list[str] = "",
|
|
963
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
964
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
965
|
+
**decorator_kwargs,
|
|
966
|
+
):
|
|
865
967
|
"""Detects if one object is an instance of another."""
|
|
866
968
|
if post_processors is None:
|
|
867
969
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -869,27 +971,31 @@ def isinstanceof(default: bool = False,
|
|
|
869
971
|
pre_processors = [pre.IsInstanceOfPreProcessor()]
|
|
870
972
|
if constraints is None:
|
|
871
973
|
constraints = []
|
|
872
|
-
return few_shot(
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
974
|
+
return few_shot(
|
|
975
|
+
prompt=prompt,
|
|
976
|
+
examples=examples,
|
|
977
|
+
constraints=constraints,
|
|
978
|
+
default=default,
|
|
979
|
+
limit=limit,
|
|
980
|
+
stop=stop,
|
|
981
|
+
max_tokens=None,
|
|
982
|
+
pre_processors=pre_processors,
|
|
983
|
+
post_processors=post_processors,
|
|
984
|
+
**decorator_kwargs,
|
|
985
|
+
)
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
def startswith(
|
|
989
|
+
default: bool = False,
|
|
990
|
+
prompt: str = "Does 'A' start with 'B'?\n",
|
|
991
|
+
examples: prm.Prompt = _PROMPT_STARTS_WITH,
|
|
992
|
+
constraints: list[Callable] | None = None,
|
|
993
|
+
limit: int | None = 1,
|
|
994
|
+
stop: str | list[str] = "",
|
|
995
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
996
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
997
|
+
**decorator_kwargs,
|
|
998
|
+
):
|
|
893
999
|
"""Determines whether a string starts with a specified prefix."""
|
|
894
1000
|
if post_processors is None:
|
|
895
1001
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -897,27 +1003,31 @@ def startswith(default: bool = False,
|
|
|
897
1003
|
pre_processors = [pre.StartsWithPreProcessor()]
|
|
898
1004
|
if constraints is None:
|
|
899
1005
|
constraints = []
|
|
900
|
-
return few_shot(
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1006
|
+
return few_shot(
|
|
1007
|
+
prompt=prompt,
|
|
1008
|
+
examples=examples,
|
|
1009
|
+
constraints=constraints,
|
|
1010
|
+
default=default,
|
|
1011
|
+
limit=limit,
|
|
1012
|
+
stop=stop,
|
|
1013
|
+
max_tokens=None,
|
|
1014
|
+
pre_processors=pre_processors,
|
|
1015
|
+
post_processors=post_processors,
|
|
1016
|
+
**decorator_kwargs,
|
|
1017
|
+
)
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
def endswith(
|
|
1021
|
+
default: bool = False,
|
|
1022
|
+
prompt: str = "Does 'A' end with 'B'?\n",
|
|
1023
|
+
examples: prm.Prompt = _PROMPT_ENDS_WITH,
|
|
1024
|
+
constraints: list[Callable] | None = None,
|
|
1025
|
+
limit: int | None = 1,
|
|
1026
|
+
stop: str | list[str] = "",
|
|
1027
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1028
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1029
|
+
**decorator_kwargs,
|
|
1030
|
+
):
|
|
921
1031
|
"""Determines whether a string ends with a specified suffix."""
|
|
922
1032
|
if post_processors is None:
|
|
923
1033
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -925,52 +1035,64 @@ def endswith(default: bool = False,
|
|
|
925
1035
|
pre_processors = [pre.EndsWithPreProcessor()]
|
|
926
1036
|
if constraints is None:
|
|
927
1037
|
constraints = []
|
|
928
|
-
return few_shot(
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1038
|
+
return few_shot(
|
|
1039
|
+
prompt=prompt,
|
|
1040
|
+
examples=examples,
|
|
1041
|
+
constraints=constraints,
|
|
1042
|
+
default=default,
|
|
1043
|
+
limit=limit,
|
|
1044
|
+
stop=stop,
|
|
1045
|
+
max_tokens=None,
|
|
1046
|
+
pre_processors=pre_processors,
|
|
1047
|
+
post_processors=post_processors,
|
|
1048
|
+
**decorator_kwargs,
|
|
1049
|
+
)
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
def case(
|
|
1053
|
+
enum: list[str],
|
|
1054
|
+
default: str,
|
|
1055
|
+
prompt: str = "Classify the text according to one of the following categories and return only the category name: ",
|
|
1056
|
+
examples: prm.Prompt | None = None,
|
|
1057
|
+
limit: int | None = 1,
|
|
1058
|
+
stop: str | list[str] = "",
|
|
1059
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1060
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1061
|
+
**decorator_kwargs,
|
|
1062
|
+
):
|
|
949
1063
|
"""Classifies a text according to one of the given categories."""
|
|
950
1064
|
if post_processors is None:
|
|
951
1065
|
post_processors = [post.StripPostProcessor(), post.CaseInsensitivePostProcessor()]
|
|
952
1066
|
if pre_processors is None:
|
|
953
|
-
pre_processors = [
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1067
|
+
pre_processors = [
|
|
1068
|
+
pre.EnumPreProcessor(),
|
|
1069
|
+
pre.TextMessagePreProcessor(),
|
|
1070
|
+
pre.PredictionMessagePreProcessor(),
|
|
1071
|
+
]
|
|
1072
|
+
return few_shot(
|
|
1073
|
+
prompt=prompt,
|
|
1074
|
+
examples=examples,
|
|
1075
|
+
default=default,
|
|
1076
|
+
limit=limit,
|
|
1077
|
+
stop=stop,
|
|
1078
|
+
pre_processors=pre_processors,
|
|
1079
|
+
post_processors=post_processors,
|
|
1080
|
+
enum=enum,
|
|
1081
|
+
**decorator_kwargs,
|
|
1082
|
+
)
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
def extract(
|
|
1086
|
+
prompt: str = "Extract a pattern from text:\n",
|
|
1087
|
+
default: str | None = None,
|
|
1088
|
+
examples: prm.Prompt = _PROMPT_EXTRACT_PATTERN,
|
|
1089
|
+
constraints: list[Callable] | None = None,
|
|
1090
|
+
limit: int | None = 1,
|
|
1091
|
+
stop: str | list[str] = "",
|
|
1092
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1093
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1094
|
+
**decorator_kwargs,
|
|
1095
|
+
):
|
|
974
1096
|
"""Extracts a pattern from text."""
|
|
975
1097
|
if post_processors is None:
|
|
976
1098
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -978,53 +1100,64 @@ def extract(prompt: str = "Extract a pattern from text:\n",
|
|
|
978
1100
|
pre_processors = [pre.ExtractPatternPreProcessor()]
|
|
979
1101
|
if constraints is None:
|
|
980
1102
|
constraints = []
|
|
981
|
-
return few_shot(
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1103
|
+
return few_shot(
|
|
1104
|
+
prompt=prompt,
|
|
1105
|
+
examples=examples,
|
|
1106
|
+
constraints=constraints,
|
|
1107
|
+
default=default,
|
|
1108
|
+
limit=limit,
|
|
1109
|
+
stop=stop,
|
|
1110
|
+
pre_processors=pre_processors,
|
|
1111
|
+
post_processors=post_processors,
|
|
1112
|
+
**decorator_kwargs,
|
|
1113
|
+
)
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
def expression(
|
|
1117
|
+
prompt: str = "Evaluate the symbolic expressions:\n",
|
|
1118
|
+
default: str | None = None,
|
|
1119
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1120
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1121
|
+
**decorator_kwargs,
|
|
1122
|
+
):
|
|
996
1123
|
"""Evaluates the symbolic expressions."""
|
|
997
1124
|
if post_processors is None:
|
|
998
1125
|
post_processors = [post.WolframAlphaPostProcessor()]
|
|
999
1126
|
if pre_processors is None:
|
|
1000
1127
|
pre_processors = []
|
|
1128
|
+
|
|
1001
1129
|
def decorator(func):
|
|
1002
1130
|
@functools.wraps(func)
|
|
1003
1131
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1004
1132
|
# Construct container object for the arguments and kwargs
|
|
1005
|
-
decorator_kwargs[
|
|
1133
|
+
decorator_kwargs["prompt"] = prompt
|
|
1006
1134
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1007
1135
|
return EngineRepository.query(
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1136
|
+
engine="symbolic",
|
|
1137
|
+
instance=instance,
|
|
1138
|
+
func=func,
|
|
1139
|
+
default=default,
|
|
1140
|
+
pre_processors=pre_processors,
|
|
1141
|
+
post_processors=post_processors,
|
|
1142
|
+
argument=argument,
|
|
1143
|
+
)
|
|
1144
|
+
|
|
1015
1145
|
return wrapper
|
|
1146
|
+
|
|
1016
1147
|
return decorator
|
|
1017
1148
|
|
|
1018
1149
|
|
|
1019
|
-
def interpret(
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1150
|
+
def interpret(
|
|
1151
|
+
prompt: str = "Evaluate the symbolic expressions and return only the result:\n",
|
|
1152
|
+
default: str | None = None,
|
|
1153
|
+
examples: prm.Prompt = _PROMPT_SIMPLE_SYMBOLIC_EXPRESSION,
|
|
1154
|
+
constraints: list[Callable] | None = None,
|
|
1155
|
+
limit: int | None = 1,
|
|
1156
|
+
stop: str | list[str] = "",
|
|
1157
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1158
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1159
|
+
**decorator_kwargs,
|
|
1160
|
+
):
|
|
1028
1161
|
"""Evaluates the symbolic expressions by interpreting the semantic meaning."""
|
|
1029
1162
|
if post_processors is None:
|
|
1030
1163
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1032,27 +1165,31 @@ def interpret(prompt: str = "Evaluate the symbolic expressions and return only t
|
|
|
1032
1165
|
pre_processors = [pre.InterpretExpressionPreProcessor()]
|
|
1033
1166
|
if constraints is None:
|
|
1034
1167
|
constraints = []
|
|
1035
|
-
return few_shot(
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1168
|
+
return few_shot(
|
|
1169
|
+
prompt=prompt,
|
|
1170
|
+
examples=examples,
|
|
1171
|
+
constraints=constraints,
|
|
1172
|
+
default=default,
|
|
1173
|
+
limit=limit,
|
|
1174
|
+
stop=stop,
|
|
1175
|
+
pre_processors=pre_processors,
|
|
1176
|
+
post_processors=post_processors,
|
|
1177
|
+
**decorator_kwargs,
|
|
1178
|
+
)
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
def logic(
|
|
1182
|
+
prompt: str = "Evaluate the logic expressions:\n",
|
|
1183
|
+
operator: str = "and",
|
|
1184
|
+
default: str | None = None,
|
|
1185
|
+
examples: prm.Prompt = _PROMPT_LOGIC_EXPRESSION,
|
|
1186
|
+
constraints: list[Callable] | None = None,
|
|
1187
|
+
limit: int | None = 1,
|
|
1188
|
+
stop: str | list[str] = "",
|
|
1189
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1190
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1191
|
+
**decorator_kwargs,
|
|
1192
|
+
):
|
|
1056
1193
|
"""Evaluates a logic expression."""
|
|
1057
1194
|
if post_processors is None:
|
|
1058
1195
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1060,27 +1197,31 @@ def logic(prompt: str = "Evaluate the logic expressions:\n",
|
|
|
1060
1197
|
pre_processors = [pre.LogicExpressionPreProcessor()]
|
|
1061
1198
|
if constraints is None:
|
|
1062
1199
|
constraints = []
|
|
1063
|
-
return few_shot(
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1200
|
+
return few_shot(
|
|
1201
|
+
prompt=prompt,
|
|
1202
|
+
examples=examples,
|
|
1203
|
+
operator=operator,
|
|
1204
|
+
constraints=constraints,
|
|
1205
|
+
default=default,
|
|
1206
|
+
limit=limit,
|
|
1207
|
+
stop=stop,
|
|
1208
|
+
pre_processors=pre_processors,
|
|
1209
|
+
post_processors=post_processors,
|
|
1210
|
+
**decorator_kwargs,
|
|
1211
|
+
)
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
def invert(
|
|
1215
|
+
prompt: str = "Invert the logic of the content:\n",
|
|
1216
|
+
default: str | None = None,
|
|
1217
|
+
examples: prm.Prompt = _PROMPT_INVERT_EXPRESSION,
|
|
1218
|
+
constraints: list[Callable] | None = None,
|
|
1219
|
+
limit: int | None = 1,
|
|
1220
|
+
stop: str | list[str] = "",
|
|
1221
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1222
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1223
|
+
**decorator_kwargs,
|
|
1224
|
+
):
|
|
1084
1225
|
"""Inverts the logic of a statement."""
|
|
1085
1226
|
if post_processors is None:
|
|
1086
1227
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1088,26 +1229,30 @@ def invert(prompt: str = "Invert the logic of the content:\n",
|
|
|
1088
1229
|
pre_processors = [pre.ArrowMessagePreProcessor()]
|
|
1089
1230
|
if constraints is None:
|
|
1090
1231
|
constraints = []
|
|
1091
|
-
return few_shot(
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1232
|
+
return few_shot(
|
|
1233
|
+
prompt=prompt,
|
|
1234
|
+
examples=examples,
|
|
1235
|
+
constraints=constraints,
|
|
1236
|
+
default=default,
|
|
1237
|
+
limit=limit,
|
|
1238
|
+
stop=stop,
|
|
1239
|
+
pre_processors=pre_processors,
|
|
1240
|
+
post_processors=post_processors,
|
|
1241
|
+
**decorator_kwargs,
|
|
1242
|
+
)
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
def simulate(
|
|
1246
|
+
prompt: str = "Simulate the following code:\n",
|
|
1247
|
+
default: str | None = None,
|
|
1248
|
+
examples: prm.Prompt = _PROMPT_SIMULATE_CODE,
|
|
1249
|
+
constraints: list[Callable] | None = None,
|
|
1250
|
+
limit: int | None = 1,
|
|
1251
|
+
stop: str | list[str] = "",
|
|
1252
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1253
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1254
|
+
**decorator_kwargs,
|
|
1255
|
+
):
|
|
1111
1256
|
"""Simulates code and returns the result."""
|
|
1112
1257
|
if post_processors is None:
|
|
1113
1258
|
post_processors = [post.SplitPipePostProcessor(), post.TakeLastPostProcessor()]
|
|
@@ -1115,26 +1260,30 @@ def simulate(prompt: str = "Simulate the following code:\n",
|
|
|
1115
1260
|
pre_processors = [pre.SimulateCodePreProcessor()]
|
|
1116
1261
|
if constraints is None:
|
|
1117
1262
|
constraints = []
|
|
1118
|
-
return few_shot(
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1263
|
+
return few_shot(
|
|
1264
|
+
prompt=prompt,
|
|
1265
|
+
examples=examples,
|
|
1266
|
+
constraints=constraints,
|
|
1267
|
+
default=default,
|
|
1268
|
+
limit=limit,
|
|
1269
|
+
stop=stop,
|
|
1270
|
+
pre_processors=pre_processors,
|
|
1271
|
+
post_processors=post_processors,
|
|
1272
|
+
**decorator_kwargs,
|
|
1273
|
+
)
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
def code(
|
|
1277
|
+
prompt: str = "Generate code that solves the following problems:\n",
|
|
1278
|
+
default: str | None = None,
|
|
1279
|
+
examples: prm.Prompt = _PROMPT_GENERATE_CODE,
|
|
1280
|
+
constraints: list[Callable] | None = None,
|
|
1281
|
+
limit: int | None = 1,
|
|
1282
|
+
stop: str | list[str] = "",
|
|
1283
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1284
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1285
|
+
**decorator_kwargs,
|
|
1286
|
+
):
|
|
1138
1287
|
"""Generates code that solves a given problem."""
|
|
1139
1288
|
if post_processors is None:
|
|
1140
1289
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1142,26 +1291,30 @@ def code(prompt: str = "Generate code that solves the following problems:\n",
|
|
|
1142
1291
|
pre_processors = [pre.GenerateCodePreProcessor()]
|
|
1143
1292
|
if constraints is None:
|
|
1144
1293
|
constraints = []
|
|
1145
|
-
return few_shot(
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1294
|
+
return few_shot(
|
|
1295
|
+
prompt=prompt,
|
|
1296
|
+
examples=examples,
|
|
1297
|
+
constraints=constraints,
|
|
1298
|
+
default=default,
|
|
1299
|
+
limit=limit,
|
|
1300
|
+
stop=stop,
|
|
1301
|
+
pre_processors=pre_processors,
|
|
1302
|
+
post_processors=post_processors,
|
|
1303
|
+
**decorator_kwargs,
|
|
1304
|
+
)
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
def outline(
|
|
1308
|
+
prompt: str = "Outline only the essential content as a short list of bullets. Each bullet is in a new line:\n",
|
|
1309
|
+
default: list[str] | None = None,
|
|
1310
|
+
examples: prm.Prompt = _PROMPT_TEXT_TO_OUTLINE,
|
|
1311
|
+
constraints: list[Callable] | None = None,
|
|
1312
|
+
limit: int | None = 1,
|
|
1313
|
+
stop: str | list[str] = "",
|
|
1314
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1315
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1316
|
+
**decorator_kwargs,
|
|
1317
|
+
):
|
|
1165
1318
|
"""Outlines the essential content as a short list of bullets."""
|
|
1166
1319
|
if post_processors is None:
|
|
1167
1320
|
post_processors = [post.StripPostProcessor(), post.SplitNewLinePostProcessor()]
|
|
@@ -1169,27 +1322,31 @@ def outline(prompt: str = "Outline only the essential content as a short list of
|
|
|
1169
1322
|
pre_processors = [pre.TextToOutlinePreProcessor()]
|
|
1170
1323
|
if constraints is None:
|
|
1171
1324
|
constraints = []
|
|
1172
|
-
return few_shot(
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1325
|
+
return few_shot(
|
|
1326
|
+
prompt=prompt,
|
|
1327
|
+
examples=examples,
|
|
1328
|
+
constraints=constraints,
|
|
1329
|
+
default=default,
|
|
1330
|
+
limit=limit,
|
|
1331
|
+
stop=stop,
|
|
1332
|
+
pre_processors=pre_processors,
|
|
1333
|
+
post_processors=post_processors,
|
|
1334
|
+
**decorator_kwargs,
|
|
1335
|
+
)
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
def unique(
|
|
1339
|
+
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",
|
|
1340
|
+
keys: list[str] | None = None,
|
|
1341
|
+
default: list[str] | None = None,
|
|
1342
|
+
examples: prm.Prompt = _PROMPT_UNIQUE_KEY,
|
|
1343
|
+
constraints: list[Callable] | None = None,
|
|
1344
|
+
limit: int | None = 1,
|
|
1345
|
+
stop: str | list[str] = "",
|
|
1346
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1347
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1348
|
+
**decorator_kwargs,
|
|
1349
|
+
):
|
|
1193
1350
|
"""Creates a short, unique key that captures the essential topic from the given statements and does not collide with the list of keys."""
|
|
1194
1351
|
if post_processors is None:
|
|
1195
1352
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1197,27 +1354,31 @@ def unique(prompt: str = "Create a short unique key that captures the essential
|
|
|
1197
1354
|
pre_processors = [pre.UniquePreProcessor()]
|
|
1198
1355
|
if constraints is None:
|
|
1199
1356
|
constraints = []
|
|
1200
|
-
return few_shot(
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1357
|
+
return few_shot(
|
|
1358
|
+
prompt=prompt,
|
|
1359
|
+
keys=keys,
|
|
1360
|
+
examples=examples,
|
|
1361
|
+
constraints=constraints,
|
|
1362
|
+
default=default,
|
|
1363
|
+
limit=limit,
|
|
1364
|
+
stop=stop,
|
|
1365
|
+
pre_processors=pre_processors,
|
|
1366
|
+
post_processors=post_processors,
|
|
1367
|
+
**decorator_kwargs,
|
|
1368
|
+
)
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
def clean(
|
|
1372
|
+
prompt: str = "Clean up the text from special characters or escape sequences. DO NOT change any words or sentences! Keep original semantics:\n",
|
|
1373
|
+
default: list[str] | None = None,
|
|
1374
|
+
examples: prm.Prompt = _PROMPT_CLEAN_TEXT,
|
|
1375
|
+
constraints: list[Callable] | None = None,
|
|
1376
|
+
limit: int | None = 1,
|
|
1377
|
+
stop: str | list[str] = "",
|
|
1378
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1379
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1380
|
+
**decorator_kwargs,
|
|
1381
|
+
):
|
|
1221
1382
|
"""Cleans up a text from special characters and escape sequences."""
|
|
1222
1383
|
if post_processors is None:
|
|
1223
1384
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1225,26 +1386,30 @@ def clean(prompt: str = "Clean up the text from special characters or escape seq
|
|
|
1225
1386
|
pre_processors = [pre.CleanTextMessagePreProcessor()]
|
|
1226
1387
|
if constraints is None:
|
|
1227
1388
|
constraints = []
|
|
1228
|
-
return few_shot(
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1389
|
+
return few_shot(
|
|
1390
|
+
prompt=prompt,
|
|
1391
|
+
examples=examples,
|
|
1392
|
+
constraints=constraints,
|
|
1393
|
+
default=default,
|
|
1394
|
+
limit=limit,
|
|
1395
|
+
stop=stop,
|
|
1396
|
+
pre_processors=pre_processors,
|
|
1397
|
+
post_processors=post_processors,
|
|
1398
|
+
**decorator_kwargs,
|
|
1399
|
+
)
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
def compose(
|
|
1403
|
+
prompt: str = "Create a coherent text based on the facts listed in the outline:\n",
|
|
1404
|
+
default: str | None = None,
|
|
1405
|
+
examples: prm.Prompt | None = None,
|
|
1406
|
+
constraints: list[Callable] | None = None,
|
|
1407
|
+
limit: int | None = 1,
|
|
1408
|
+
stop: str | list[str] = "",
|
|
1409
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1410
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1411
|
+
**decorator_kwargs,
|
|
1412
|
+
):
|
|
1248
1413
|
"""Compose a coherent text based on an outline."""
|
|
1249
1414
|
if post_processors is None:
|
|
1250
1415
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1252,28 +1417,32 @@ def compose(prompt: str = "Create a coherent text based on the facts listed in t
|
|
|
1252
1417
|
pre_processors = [pre.GenerateTextPreProcessor()]
|
|
1253
1418
|
if constraints is None:
|
|
1254
1419
|
constraints = []
|
|
1255
|
-
return few_shot(
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1420
|
+
return few_shot(
|
|
1421
|
+
prompt=prompt,
|
|
1422
|
+
examples=examples,
|
|
1423
|
+
constraints=constraints,
|
|
1424
|
+
default=default,
|
|
1425
|
+
limit=limit,
|
|
1426
|
+
stop=stop,
|
|
1427
|
+
pre_processors=pre_processors,
|
|
1428
|
+
post_processors=post_processors,
|
|
1429
|
+
**decorator_kwargs,
|
|
1430
|
+
)
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
def foreach(
|
|
1434
|
+
condition: str,
|
|
1435
|
+
apply: str,
|
|
1436
|
+
prompt: str = "Iterate over each element and apply operation based on condition:\n",
|
|
1437
|
+
default: str | None = None,
|
|
1438
|
+
examples: prm.Prompt = _PROMPT_FOR_EACH,
|
|
1439
|
+
constraints: list[Callable] | None = None,
|
|
1440
|
+
limit: int | None = 1,
|
|
1441
|
+
stop: str | list[str] = "",
|
|
1442
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1443
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1444
|
+
**decorator_kwargs,
|
|
1445
|
+
):
|
|
1277
1446
|
"""Applies an operation based on a given condition to each element in a list."""
|
|
1278
1447
|
if post_processors is None:
|
|
1279
1448
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1281,29 +1450,33 @@ def foreach(condition: str,
|
|
|
1281
1450
|
pre_processors = [pre.ForEachPreProcessor()]
|
|
1282
1451
|
if constraints is None:
|
|
1283
1452
|
constraints = []
|
|
1284
|
-
return few_shot(
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1453
|
+
return few_shot(
|
|
1454
|
+
prompt=prompt,
|
|
1455
|
+
condition=condition,
|
|
1456
|
+
apply=apply,
|
|
1457
|
+
examples=examples,
|
|
1458
|
+
constraints=constraints,
|
|
1459
|
+
default=default,
|
|
1460
|
+
limit=limit,
|
|
1461
|
+
stop=stop,
|
|
1462
|
+
pre_processors=pre_processors,
|
|
1463
|
+
post_processors=post_processors,
|
|
1464
|
+
**decorator_kwargs,
|
|
1465
|
+
)
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
def dictionary(
|
|
1469
|
+
context: str,
|
|
1470
|
+
prompt: str = "Map related content together under a common abstract topic. Do not remove content:\n",
|
|
1471
|
+
default: str | None = None,
|
|
1472
|
+
examples: prm.Prompt = _PROMPT_MAP_CONTENT,
|
|
1473
|
+
constraints: list[Callable] | None = None,
|
|
1474
|
+
limit: int | None = 1,
|
|
1475
|
+
stop: str | list[str] = "",
|
|
1476
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1477
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1478
|
+
**decorator_kwargs,
|
|
1479
|
+
):
|
|
1307
1480
|
"""Maps related content together under a common abstract topic."""
|
|
1308
1481
|
if post_processors is None:
|
|
1309
1482
|
post_processors = [post.StripPostProcessor(), post.ASTPostProcessor()]
|
|
@@ -1311,27 +1484,32 @@ def dictionary(context: str,
|
|
|
1311
1484
|
pre_processors = [pre.MapPreProcessor()]
|
|
1312
1485
|
if constraints is None:
|
|
1313
1486
|
constraints = []
|
|
1314
|
-
return few_shot(
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1487
|
+
return few_shot(
|
|
1488
|
+
prompt=prompt,
|
|
1489
|
+
context=context,
|
|
1490
|
+
examples=examples,
|
|
1491
|
+
constraints=constraints,
|
|
1492
|
+
default=default,
|
|
1493
|
+
limit=limit,
|
|
1494
|
+
stop=stop,
|
|
1495
|
+
pre_processors=pre_processors,
|
|
1496
|
+
post_processors=post_processors,
|
|
1497
|
+
**decorator_kwargs,
|
|
1498
|
+
)
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
def listing(
|
|
1502
|
+
condition: str,
|
|
1503
|
+
prompt: str = "List each element contained in the text or list based on condition:\n",
|
|
1504
|
+
default: str | None = None,
|
|
1505
|
+
examples: prm.Prompt = _PROMPT_LIST_OBJECTS,
|
|
1506
|
+
constraints: list[Callable] | None = None,
|
|
1507
|
+
stop: str | list[str] = "",
|
|
1508
|
+
limit: int | None = 1,
|
|
1509
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1510
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1511
|
+
**decorator_kwargs,
|
|
1512
|
+
):
|
|
1335
1513
|
"""Lists each element contained in the text or list based on the given condition."""
|
|
1336
1514
|
if post_processors is None:
|
|
1337
1515
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1339,28 +1517,32 @@ def listing(condition: str,
|
|
|
1339
1517
|
pre_processors = [pre.ListPreProcessor()]
|
|
1340
1518
|
if constraints is None:
|
|
1341
1519
|
constraints = []
|
|
1342
|
-
return few_shot(
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1520
|
+
return few_shot(
|
|
1521
|
+
prompt=prompt,
|
|
1522
|
+
condition=condition,
|
|
1523
|
+
examples=examples,
|
|
1524
|
+
constraints=constraints,
|
|
1525
|
+
default=default,
|
|
1526
|
+
stop=stop,
|
|
1527
|
+
limit=limit,
|
|
1528
|
+
pre_processors=pre_processors,
|
|
1529
|
+
post_processors=post_processors,
|
|
1530
|
+
**decorator_kwargs,
|
|
1531
|
+
)
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
def query(
|
|
1535
|
+
context: str,
|
|
1536
|
+
prompt: str | None = None,
|
|
1537
|
+
examples: prm.Prompt | None = None,
|
|
1538
|
+
constraints: list[Callable] | None = None,
|
|
1539
|
+
default: object | None = None,
|
|
1540
|
+
stop: str | list[str] = "",
|
|
1541
|
+
limit: int | None = 1,
|
|
1542
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1543
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1544
|
+
**decorator_kwargs,
|
|
1545
|
+
):
|
|
1364
1546
|
"""Performs a query given a context."""
|
|
1365
1547
|
if post_processors is None:
|
|
1366
1548
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1368,270 +1550,333 @@ def query(context: str,
|
|
|
1368
1550
|
pre_processors = [pre.QueryPreProcessor()]
|
|
1369
1551
|
if constraints is None:
|
|
1370
1552
|
constraints = []
|
|
1371
|
-
return few_shot(
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1553
|
+
return few_shot(
|
|
1554
|
+
prompt=prompt,
|
|
1555
|
+
context=context,
|
|
1556
|
+
examples=examples,
|
|
1557
|
+
constraints=constraints,
|
|
1558
|
+
default=default,
|
|
1559
|
+
stop=stop,
|
|
1560
|
+
limit=limit,
|
|
1561
|
+
pre_processors=pre_processors,
|
|
1562
|
+
post_processors=post_processors,
|
|
1563
|
+
**decorator_kwargs,
|
|
1564
|
+
)
|
|
1565
|
+
|
|
1566
|
+
|
|
1567
|
+
def expand(
|
|
1568
|
+
prompt: str
|
|
1569
|
+
| 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.",
|
|
1570
|
+
examples: prm.Prompt | None = _PROMPT_EXPAND_FUNCTION,
|
|
1571
|
+
constraints: list[Callable] | None = None,
|
|
1572
|
+
default: object | None = None,
|
|
1573
|
+
stop: str | list[str] = "",
|
|
1574
|
+
limit: int | None = 1,
|
|
1575
|
+
pre_processors: list[pre.PreProcessor] | None = _PREPROCESSOR_EXPAND_FUNCTION,
|
|
1576
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1577
|
+
**decorator_kwargs,
|
|
1578
|
+
):
|
|
1392
1579
|
"""Performs a expand command given a context to generate new prompts."""
|
|
1393
1580
|
if post_processors is None:
|
|
1394
1581
|
post_processors = [post.StripPostProcessor(), post.ExpandFunctionPostProcessor()]
|
|
1395
1582
|
if constraints is None:
|
|
1396
1583
|
constraints = []
|
|
1397
|
-
return few_shot(
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1584
|
+
return few_shot(
|
|
1585
|
+
prompt=prompt,
|
|
1586
|
+
examples=examples,
|
|
1587
|
+
constraints=constraints,
|
|
1588
|
+
default=default,
|
|
1589
|
+
stop=stop,
|
|
1590
|
+
limit=limit,
|
|
1591
|
+
pre_processors=pre_processors,
|
|
1592
|
+
post_processors=post_processors,
|
|
1593
|
+
**decorator_kwargs,
|
|
1594
|
+
)
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
def search(
|
|
1598
|
+
query: str,
|
|
1599
|
+
constraints: list[Callable] | None = None,
|
|
1600
|
+
default: object | None = None,
|
|
1601
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1602
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1603
|
+
**decorator_kwargs,
|
|
1604
|
+
):
|
|
1414
1605
|
"""Searches for a given query on the internet."""
|
|
1415
1606
|
if constraints is None:
|
|
1416
1607
|
constraints = []
|
|
1608
|
+
|
|
1417
1609
|
def decorator(func):
|
|
1418
1610
|
@functools.wraps(func)
|
|
1419
1611
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1420
1612
|
# Construct container object for the arguments and kwargs
|
|
1421
|
-
decorator_kwargs[
|
|
1613
|
+
decorator_kwargs["query"] = query
|
|
1422
1614
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1423
1615
|
return EngineRepository.query(
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1616
|
+
engine="search",
|
|
1617
|
+
instance=instance,
|
|
1618
|
+
func=func,
|
|
1619
|
+
constraints=constraints,
|
|
1620
|
+
default=default,
|
|
1621
|
+
pre_processors=pre_processors,
|
|
1622
|
+
post_processors=post_processors,
|
|
1623
|
+
argument=argument,
|
|
1624
|
+
)
|
|
1625
|
+
|
|
1432
1626
|
return wrapper
|
|
1627
|
+
|
|
1433
1628
|
return decorator
|
|
1434
1629
|
|
|
1435
1630
|
|
|
1436
|
-
def opening(
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1631
|
+
def opening(
|
|
1632
|
+
path: str,
|
|
1633
|
+
constraints: list[Callable] | None = None,
|
|
1634
|
+
default: object | None = None,
|
|
1635
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1636
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1637
|
+
**decorator_kwargs,
|
|
1638
|
+
):
|
|
1442
1639
|
"""Opens a file and applies a given function to it."""
|
|
1443
1640
|
if post_processors is None:
|
|
1444
1641
|
post_processors = [post.StripPostProcessor()]
|
|
1445
1642
|
if constraints is None:
|
|
1446
1643
|
constraints = []
|
|
1644
|
+
|
|
1447
1645
|
def decorator(func):
|
|
1448
1646
|
@functools.wraps(func)
|
|
1449
1647
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1450
1648
|
# Construct container object for the arguments and kwargs
|
|
1451
|
-
decorator_kwargs[
|
|
1649
|
+
decorator_kwargs["path"] = path
|
|
1452
1650
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1453
1651
|
return EngineRepository.query(
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1652
|
+
engine="files",
|
|
1653
|
+
instance=instance,
|
|
1654
|
+
func=func,
|
|
1655
|
+
constraints=constraints,
|
|
1656
|
+
default=default,
|
|
1657
|
+
pre_processors=pre_processors,
|
|
1658
|
+
post_processors=post_processors,
|
|
1659
|
+
argument=argument,
|
|
1660
|
+
)
|
|
1661
|
+
|
|
1462
1662
|
return wrapper
|
|
1663
|
+
|
|
1463
1664
|
return decorator
|
|
1464
1665
|
|
|
1465
1666
|
|
|
1466
|
-
def embed(
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1667
|
+
def embed(
|
|
1668
|
+
entries: list[str],
|
|
1669
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1670
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1671
|
+
**decorator_kwargs,
|
|
1672
|
+
):
|
|
1470
1673
|
"""Embeds the entries provided in a decorated function."""
|
|
1471
1674
|
if pre_processors is None:
|
|
1472
1675
|
pre_processors = [pre.UnwrapListSymbolsPreProcessor()]
|
|
1676
|
+
|
|
1473
1677
|
def decorator(func):
|
|
1474
1678
|
@functools.wraps(func)
|
|
1475
1679
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1476
1680
|
# Construct container object for the arguments and kwargs
|
|
1477
|
-
decorator_kwargs[
|
|
1681
|
+
decorator_kwargs["entries"] = entries
|
|
1478
1682
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1479
1683
|
return EngineRepository.query(
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1684
|
+
engine="embedding",
|
|
1685
|
+
instance=instance,
|
|
1686
|
+
func=func,
|
|
1687
|
+
pre_processors=pre_processors,
|
|
1688
|
+
post_processors=post_processors,
|
|
1689
|
+
argument=argument,
|
|
1690
|
+
)
|
|
1691
|
+
|
|
1486
1692
|
return wrapper
|
|
1693
|
+
|
|
1487
1694
|
return decorator
|
|
1488
1695
|
|
|
1489
1696
|
|
|
1490
|
-
def cluster(
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1697
|
+
def cluster(
|
|
1698
|
+
entries: list[str],
|
|
1699
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1700
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1701
|
+
**decorator_kwargs,
|
|
1702
|
+
):
|
|
1494
1703
|
"""Embeds and clusters the input entries."""
|
|
1495
1704
|
if post_processors is None:
|
|
1496
1705
|
post_processors = [post.ClusterPostProcessor()]
|
|
1497
1706
|
if pre_processors is None:
|
|
1498
1707
|
pre_processors = [pre.UnwrapListSymbolsPreProcessor()]
|
|
1499
|
-
assert any(isinstance(pr, post.ClusterPostProcessor) for pr in post_processors),
|
|
1708
|
+
assert any(isinstance(pr, post.ClusterPostProcessor) for pr in post_processors), (
|
|
1709
|
+
"At least one post processor must be a 'ClusterPostProcessor' for clustering!"
|
|
1710
|
+
)
|
|
1500
1711
|
for post_pr in post_processors:
|
|
1501
1712
|
if isinstance(post_pr, post.ClusterPostProcessor):
|
|
1502
1713
|
post_pr.set(decorator_kwargs)
|
|
1503
1714
|
|
|
1504
|
-
return embed(
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1715
|
+
return embed(
|
|
1716
|
+
entries=entries,
|
|
1717
|
+
pre_processors=pre_processors,
|
|
1718
|
+
post_processors=post_processors,
|
|
1719
|
+
**decorator_kwargs,
|
|
1720
|
+
)
|
|
1721
|
+
|
|
1722
|
+
|
|
1723
|
+
def draw(
|
|
1724
|
+
operation: str = "create",
|
|
1725
|
+
prompt: str = "",
|
|
1726
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1727
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1728
|
+
**decorator_kwargs,
|
|
1729
|
+
):
|
|
1515
1730
|
"""Draws an image provided in a decorated function."""
|
|
1516
1731
|
if pre_processors is None:
|
|
1517
1732
|
pre_processors = [pre.ValuePreProcessor()]
|
|
1733
|
+
|
|
1518
1734
|
def decorator(func):
|
|
1519
1735
|
@functools.wraps(func)
|
|
1520
1736
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1521
1737
|
# Construct container object for the arguments and kwargs
|
|
1522
|
-
decorator_kwargs[
|
|
1523
|
-
decorator_kwargs[
|
|
1738
|
+
decorator_kwargs["operation"] = operation
|
|
1739
|
+
decorator_kwargs["prompt"] = prompt
|
|
1524
1740
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1525
1741
|
return EngineRepository.query(
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1742
|
+
engine="drawing",
|
|
1743
|
+
instance=instance,
|
|
1744
|
+
func=func,
|
|
1745
|
+
pre_processors=pre_processors,
|
|
1746
|
+
post_processors=post_processors,
|
|
1747
|
+
argument=argument,
|
|
1748
|
+
)
|
|
1749
|
+
|
|
1532
1750
|
return wrapper
|
|
1751
|
+
|
|
1533
1752
|
return decorator
|
|
1534
1753
|
|
|
1535
1754
|
|
|
1536
|
-
def text_vision(
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1755
|
+
def text_vision(
|
|
1756
|
+
image: str | bytes | None = None,
|
|
1757
|
+
text: list[str] | None = None,
|
|
1758
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1759
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1760
|
+
**decorator_kwargs,
|
|
1761
|
+
):
|
|
1541
1762
|
"""Performs vision-related associative tasks. Currently limited to CLIP model embeddings."""
|
|
1763
|
+
|
|
1542
1764
|
def decorator(func):
|
|
1543
1765
|
@functools.wraps(func)
|
|
1544
1766
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1545
1767
|
# Construct container object for the arguments and kwargs
|
|
1546
|
-
decorator_kwargs[
|
|
1547
|
-
decorator_kwargs[
|
|
1768
|
+
decorator_kwargs["image"] = image
|
|
1769
|
+
decorator_kwargs["text"] = text
|
|
1548
1770
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1549
1771
|
return EngineRepository.query(
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1772
|
+
engine="text_vision",
|
|
1773
|
+
instance=instance,
|
|
1774
|
+
func=func,
|
|
1775
|
+
pre_processors=pre_processors,
|
|
1776
|
+
post_processors=post_processors,
|
|
1777
|
+
argument=argument,
|
|
1778
|
+
)
|
|
1779
|
+
|
|
1556
1780
|
return wrapper
|
|
1781
|
+
|
|
1557
1782
|
return decorator
|
|
1558
1783
|
|
|
1559
1784
|
|
|
1560
|
-
def ocr(
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1785
|
+
def ocr(
|
|
1786
|
+
image: str,
|
|
1787
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1788
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1789
|
+
**decorator_kwargs,
|
|
1790
|
+
):
|
|
1564
1791
|
"""Performs Optical Character Recognition (OCR) on an image."""
|
|
1792
|
+
|
|
1565
1793
|
def decorator(func):
|
|
1566
1794
|
@functools.wraps(func)
|
|
1567
1795
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1568
1796
|
# Construct container object for the arguments and kwargs
|
|
1569
|
-
decorator_kwargs[
|
|
1797
|
+
decorator_kwargs["image"] = image
|
|
1570
1798
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1571
1799
|
return EngineRepository.query(
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1800
|
+
engine="ocr",
|
|
1801
|
+
instance=instance,
|
|
1802
|
+
func=func,
|
|
1803
|
+
pre_processors=pre_processors,
|
|
1804
|
+
post_processors=post_processors,
|
|
1805
|
+
argument=argument,
|
|
1806
|
+
)
|
|
1807
|
+
|
|
1578
1808
|
return wrapper
|
|
1809
|
+
|
|
1579
1810
|
return decorator
|
|
1580
1811
|
|
|
1581
1812
|
|
|
1582
|
-
def speech_to_text(
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1813
|
+
def speech_to_text(
|
|
1814
|
+
prompt: str = "decode",
|
|
1815
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1816
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1817
|
+
**decorator_kwargs,
|
|
1818
|
+
):
|
|
1586
1819
|
"""Decorates the given function for speech recognition."""
|
|
1820
|
+
|
|
1587
1821
|
def decorator(func):
|
|
1588
1822
|
@functools.wraps(func)
|
|
1589
1823
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1590
1824
|
# Construct container object for the arguments and kwargs
|
|
1591
|
-
decorator_kwargs[
|
|
1825
|
+
decorator_kwargs["prompt"] = prompt
|
|
1592
1826
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1593
1827
|
return EngineRepository.query(
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1828
|
+
engine="speech-to-text",
|
|
1829
|
+
instance=instance,
|
|
1830
|
+
func=func,
|
|
1831
|
+
pre_processors=pre_processors,
|
|
1832
|
+
post_processors=post_processors,
|
|
1833
|
+
argument=argument,
|
|
1834
|
+
)
|
|
1835
|
+
|
|
1600
1836
|
return wrapper
|
|
1837
|
+
|
|
1601
1838
|
return decorator
|
|
1602
1839
|
|
|
1603
1840
|
|
|
1604
|
-
def text_to_speech(
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1841
|
+
def text_to_speech(
|
|
1842
|
+
prompt: str,
|
|
1843
|
+
path: str,
|
|
1844
|
+
voice: str = "nova",
|
|
1845
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1846
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1847
|
+
**decorator_kwargs,
|
|
1848
|
+
):
|
|
1610
1849
|
"""Decorates the given function for text to speech synthesis."""
|
|
1850
|
+
|
|
1611
1851
|
def decorator(func):
|
|
1612
1852
|
@functools.wraps(func)
|
|
1613
1853
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1614
1854
|
# Construct container object for the arguments and kwargs
|
|
1615
|
-
decorator_kwargs[
|
|
1616
|
-
decorator_kwargs[
|
|
1617
|
-
decorator_kwargs[
|
|
1855
|
+
decorator_kwargs["path"] = path
|
|
1856
|
+
decorator_kwargs["voice"] = voice
|
|
1857
|
+
decorator_kwargs["prompt"] = prompt
|
|
1618
1858
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1619
1859
|
return EngineRepository.query(
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1860
|
+
engine="text-to-speech",
|
|
1861
|
+
instance=instance,
|
|
1862
|
+
func=func,
|
|
1863
|
+
pre_processors=pre_processors,
|
|
1864
|
+
post_processors=post_processors,
|
|
1865
|
+
argument=argument,
|
|
1866
|
+
)
|
|
1867
|
+
|
|
1626
1868
|
return wrapper
|
|
1869
|
+
|
|
1627
1870
|
return decorator
|
|
1628
1871
|
|
|
1629
1872
|
|
|
1630
|
-
def output(
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1873
|
+
def output(
|
|
1874
|
+
constraints: list[Callable] | None = None,
|
|
1875
|
+
default: object | None = None,
|
|
1876
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1877
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1878
|
+
**decorator_kwargs,
|
|
1879
|
+
):
|
|
1635
1880
|
"""Offers an output stream for writing results."""
|
|
1636
1881
|
if post_processors is None:
|
|
1637
1882
|
post_processors = [post.ConsolePostProcessor()]
|
|
@@ -1639,30 +1884,36 @@ def output(constraints: list[Callable] | None = None,
|
|
|
1639
1884
|
pre_processors = [pre.ConsolePreProcessor()]
|
|
1640
1885
|
if constraints is None:
|
|
1641
1886
|
constraints = []
|
|
1887
|
+
|
|
1642
1888
|
def decorator(func):
|
|
1643
1889
|
@functools.wraps(func)
|
|
1644
1890
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1645
1891
|
# Construct container object for the arguments and kwargs
|
|
1646
1892
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1647
1893
|
return EngineRepository.query(
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1894
|
+
engine="output",
|
|
1895
|
+
instance=instance,
|
|
1896
|
+
func=func,
|
|
1897
|
+
constraints=constraints,
|
|
1898
|
+
default=default,
|
|
1899
|
+
pre_processors=pre_processors,
|
|
1900
|
+
post_processors=post_processors,
|
|
1901
|
+
argument=argument,
|
|
1902
|
+
)
|
|
1903
|
+
|
|
1656
1904
|
return wrapper
|
|
1905
|
+
|
|
1657
1906
|
return decorator
|
|
1658
1907
|
|
|
1659
1908
|
|
|
1660
|
-
def scrape(
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1909
|
+
def scrape(
|
|
1910
|
+
url: str,
|
|
1911
|
+
constraints: list[Callable] | None = None,
|
|
1912
|
+
default: object | None = None,
|
|
1913
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1914
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1915
|
+
**decorator_kwargs,
|
|
1916
|
+
):
|
|
1666
1917
|
"""Fetches data from a given URL and applies the provided post-processors."""
|
|
1667
1918
|
if post_processors is None:
|
|
1668
1919
|
post_processors = []
|
|
@@ -1670,29 +1921,35 @@ def scrape(url: str,
|
|
|
1670
1921
|
pre_processors = []
|
|
1671
1922
|
if constraints is None:
|
|
1672
1923
|
constraints = []
|
|
1924
|
+
|
|
1673
1925
|
def decorator(func):
|
|
1674
1926
|
@functools.wraps(func)
|
|
1675
1927
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1676
|
-
decorator_kwargs[
|
|
1928
|
+
decorator_kwargs["url"] = url
|
|
1677
1929
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1678
1930
|
return EngineRepository.query(
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1931
|
+
engine="scrape",
|
|
1932
|
+
instance=instance,
|
|
1933
|
+
func=func,
|
|
1934
|
+
constraints=constraints,
|
|
1935
|
+
default=default,
|
|
1936
|
+
pre_processors=pre_processors,
|
|
1937
|
+
post_processors=post_processors,
|
|
1938
|
+
argument=argument,
|
|
1939
|
+
)
|
|
1940
|
+
|
|
1687
1941
|
return wrapper
|
|
1942
|
+
|
|
1688
1943
|
return decorator
|
|
1689
1944
|
|
|
1690
1945
|
|
|
1691
|
-
def userinput(
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1946
|
+
def userinput(
|
|
1947
|
+
constraints: list[Callable] | None = None,
|
|
1948
|
+
default: object | None = None,
|
|
1949
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1950
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1951
|
+
**decorator_kwargs,
|
|
1952
|
+
):
|
|
1696
1953
|
"""Prompts for user input and returns the user response through a decorator."""
|
|
1697
1954
|
if post_processors is None:
|
|
1698
1955
|
post_processors = [post.StripPostProcessor()]
|
|
@@ -1700,29 +1957,35 @@ def userinput(constraints: list[Callable] | None = None,
|
|
|
1700
1957
|
pre_processors = [pre.ConsoleInputPreProcessor()]
|
|
1701
1958
|
if constraints is None:
|
|
1702
1959
|
constraints = []
|
|
1960
|
+
|
|
1703
1961
|
def decorator(func):
|
|
1704
1962
|
@functools.wraps(func)
|
|
1705
1963
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1706
1964
|
# Construct container object for the arguments and kwargs
|
|
1707
1965
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1708
1966
|
return EngineRepository.query(
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1967
|
+
engine="userinput",
|
|
1968
|
+
instance=instance,
|
|
1969
|
+
func=func,
|
|
1970
|
+
constraints=constraints,
|
|
1971
|
+
default=default,
|
|
1972
|
+
pre_processors=pre_processors,
|
|
1973
|
+
post_processors=post_processors,
|
|
1974
|
+
argument=argument,
|
|
1975
|
+
)
|
|
1976
|
+
|
|
1717
1977
|
return wrapper
|
|
1978
|
+
|
|
1718
1979
|
return decorator
|
|
1719
1980
|
|
|
1720
1981
|
|
|
1721
|
-
def execute(
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1982
|
+
def execute(
|
|
1983
|
+
default: str | None = None,
|
|
1984
|
+
constraints: list[Callable] | None = None,
|
|
1985
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
1986
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
1987
|
+
**decorator_kwargs,
|
|
1988
|
+
):
|
|
1726
1989
|
"""Executes a given function after applying constraints, pre-processing and post-processing."""
|
|
1727
1990
|
if post_processors is None:
|
|
1728
1991
|
post_processors = []
|
|
@@ -1730,32 +1993,38 @@ def execute(default: str | None = None,
|
|
|
1730
1993
|
pre_processors = []
|
|
1731
1994
|
if constraints is None:
|
|
1732
1995
|
constraints = []
|
|
1996
|
+
|
|
1733
1997
|
def decorator(func):
|
|
1734
1998
|
@functools.wraps(func)
|
|
1735
1999
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1736
2000
|
# Construct container object for the arguments and kwargs
|
|
1737
2001
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1738
2002
|
return EngineRepository.query(
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
2003
|
+
engine="execute",
|
|
2004
|
+
instance=instance,
|
|
2005
|
+
func=func,
|
|
2006
|
+
constraints=constraints,
|
|
2007
|
+
default=default,
|
|
2008
|
+
pre_processors=pre_processors,
|
|
2009
|
+
post_processors=post_processors,
|
|
2010
|
+
argument=argument,
|
|
2011
|
+
)
|
|
2012
|
+
|
|
1747
2013
|
return wrapper
|
|
2014
|
+
|
|
1748
2015
|
return decorator
|
|
1749
2016
|
|
|
1750
2017
|
|
|
1751
|
-
def index(
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
2018
|
+
def index(
|
|
2019
|
+
prompt: Any,
|
|
2020
|
+
index_name: str,
|
|
2021
|
+
operation: str = "search", # | add | config
|
|
2022
|
+
default: str | None = None,
|
|
2023
|
+
constraints: list[Callable] | None = None,
|
|
2024
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
2025
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
2026
|
+
**decorator_kwargs,
|
|
2027
|
+
):
|
|
1759
2028
|
"""Query for a given index and returns the result through a decorator."""
|
|
1760
2029
|
if post_processors is None:
|
|
1761
2030
|
post_processors = []
|
|
@@ -1763,102 +2032,118 @@ def index(prompt: Any,
|
|
|
1763
2032
|
pre_processors = []
|
|
1764
2033
|
if constraints is None:
|
|
1765
2034
|
constraints = []
|
|
2035
|
+
|
|
1766
2036
|
def decorator(func):
|
|
1767
2037
|
@functools.wraps(func)
|
|
1768
2038
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1769
2039
|
# Construct container object for the arguments and kwargs
|
|
1770
|
-
decorator_kwargs[
|
|
1771
|
-
decorator_kwargs[
|
|
1772
|
-
decorator_kwargs[
|
|
2040
|
+
decorator_kwargs["operation"] = operation
|
|
2041
|
+
decorator_kwargs["prompt"] = prompt
|
|
2042
|
+
decorator_kwargs["index_name"] = index_name
|
|
1773
2043
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1774
2044
|
return EngineRepository.query(
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2045
|
+
engine="index",
|
|
2046
|
+
instance=instance,
|
|
2047
|
+
func=func,
|
|
2048
|
+
constraints=constraints,
|
|
2049
|
+
default=default,
|
|
2050
|
+
pre_processors=pre_processors,
|
|
2051
|
+
post_processors=post_processors,
|
|
2052
|
+
argument=argument,
|
|
2053
|
+
)
|
|
2054
|
+
|
|
1783
2055
|
return wrapper
|
|
2056
|
+
|
|
1784
2057
|
return decorator
|
|
1785
2058
|
|
|
1786
2059
|
|
|
1787
2060
|
def command(engines: list[str] | None = None, **decorator_kwargs):
|
|
1788
2061
|
"""Decorates a function to forward commands to the engine backends."""
|
|
1789
2062
|
if engines is None:
|
|
1790
|
-
engines = [
|
|
2063
|
+
engines = ["all"]
|
|
2064
|
+
|
|
1791
2065
|
def decorator(func):
|
|
1792
2066
|
@functools.wraps(func)
|
|
1793
2067
|
def wrapper(instance):
|
|
1794
2068
|
return EngineRepository.command(
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
**decorator_kwargs
|
|
1799
|
-
)
|
|
2069
|
+
engines=engines, instance=instance, func=func, **decorator_kwargs
|
|
2070
|
+
)
|
|
2071
|
+
|
|
1800
2072
|
return wrapper
|
|
2073
|
+
|
|
1801
2074
|
return decorator
|
|
1802
2075
|
|
|
1803
2076
|
|
|
1804
2077
|
def register(engines: dict[str, Any]):
|
|
1805
2078
|
"""Decorates a function to initialize custom engines as backends."""
|
|
2079
|
+
|
|
1806
2080
|
def decorator(func):
|
|
1807
2081
|
@functools.wraps(func)
|
|
1808
2082
|
def wrapper(instance, **kwargs):
|
|
1809
2083
|
return EngineRepository.register(
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
**kwargs
|
|
1814
|
-
)
|
|
2084
|
+
engines=engines, engine_instance=instance, func=func, **kwargs
|
|
2085
|
+
)
|
|
2086
|
+
|
|
1815
2087
|
return wrapper
|
|
2088
|
+
|
|
1816
2089
|
return decorator
|
|
1817
2090
|
|
|
1818
2091
|
|
|
1819
|
-
def tune(
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
2092
|
+
def tune(
|
|
2093
|
+
operation: str = "create",
|
|
2094
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
2095
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
2096
|
+
**decorator_kwargs,
|
|
2097
|
+
):
|
|
1823
2098
|
"""Fine tune a LLM."""
|
|
2099
|
+
|
|
1824
2100
|
def decorator(func):
|
|
1825
2101
|
@functools.wraps(func)
|
|
1826
2102
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1827
|
-
decorator_kwargs[
|
|
2103
|
+
decorator_kwargs["__cmd__"] = operation # TODO: update engine
|
|
1828
2104
|
# Construct container object for the arguments and kwargs
|
|
1829
2105
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1830
2106
|
return EngineRepository.query(
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
2107
|
+
engine="finetune",
|
|
2108
|
+
instance=instance,
|
|
2109
|
+
func=func,
|
|
2110
|
+
pre_processors=pre_processors,
|
|
2111
|
+
post_processors=post_processors,
|
|
2112
|
+
argument=argument,
|
|
2113
|
+
)
|
|
2114
|
+
|
|
1837
2115
|
return wrapper
|
|
2116
|
+
|
|
1838
2117
|
return decorator
|
|
1839
2118
|
|
|
1840
2119
|
|
|
1841
|
-
def caption(
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2120
|
+
def caption(
|
|
2121
|
+
image: str,
|
|
2122
|
+
prompt: str,
|
|
2123
|
+
pre_processors: list[pre.PreProcessor] | None = None,
|
|
2124
|
+
post_processors: list[post.PostProcessor] | None = None,
|
|
2125
|
+
**decorator_kwargs,
|
|
2126
|
+
):
|
|
1846
2127
|
"""Caption the content of an image."""
|
|
1847
2128
|
if pre_processors is None:
|
|
1848
2129
|
pre_processors = [pre.ValuePreProcessor()]
|
|
2130
|
+
|
|
1849
2131
|
def decorator(func):
|
|
1850
2132
|
@functools.wraps(func)
|
|
1851
2133
|
def wrapper(instance, *signature_args, **signature_kwargs):
|
|
1852
2134
|
# Construct container object for the arguments and kwargs
|
|
1853
|
-
decorator_kwargs[
|
|
1854
|
-
decorator_kwargs[
|
|
2135
|
+
decorator_kwargs["image"] = image
|
|
2136
|
+
decorator_kwargs["prompt"] = prompt
|
|
1855
2137
|
argument = Argument(signature_args, signature_kwargs, decorator_kwargs)
|
|
1856
2138
|
return EngineRepository.query(
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
2139
|
+
engine="imagecaptioning",
|
|
2140
|
+
instance=instance,
|
|
2141
|
+
func=func,
|
|
2142
|
+
pre_processors=pre_processors,
|
|
2143
|
+
post_processors=post_processors,
|
|
2144
|
+
argument=argument,
|
|
2145
|
+
)
|
|
2146
|
+
|
|
1863
2147
|
return wrapper
|
|
2148
|
+
|
|
1864
2149
|
return decorator
|