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