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/pre_processors.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import traceback
|
|
2
|
-
from typing import Any
|
|
2
|
+
from typing import Any
|
|
3
3
|
|
|
4
4
|
from .utils import prep_as_str
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class PreProcessor:
|
|
8
8
|
def __call__(self, argument) -> Any:
|
|
9
|
-
raise NotImplementedError
|
|
9
|
+
raise NotImplementedError
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class RawInputPreProcessor(PreProcessor):
|
|
13
13
|
def __call__(self, argument) -> Any:
|
|
14
|
-
return f"{
|
|
14
|
+
return f"{argument.prop.prompt!s}"
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class JsonPreProcessor(PreProcessor):
|
|
@@ -19,7 +19,7 @@ class JsonPreProcessor(PreProcessor):
|
|
|
19
19
|
assert len(argument.args) == 1
|
|
20
20
|
self.format = format
|
|
21
21
|
value = str(argument.args[0])
|
|
22
|
-
return f
|
|
22
|
+
return f"{value} => [JSON_BEGIN]"
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class FormatPreProcessor(PreProcessor):
|
|
@@ -36,7 +36,7 @@ class EqualsPreProcessor(PreProcessor):
|
|
|
36
36
|
assert len(argument.args) == 1
|
|
37
37
|
a = prep_as_str(argument.prop.instance)
|
|
38
38
|
b = prep_as_str(argument.args[0])
|
|
39
|
-
return f
|
|
39
|
+
return f"{a} == {b} =>"
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
class InterpretExpressionPreProcessor(PreProcessor):
|
|
@@ -50,7 +50,7 @@ class IndexPreProcessor(PreProcessor):
|
|
|
50
50
|
assert len(argument.args) == 1
|
|
51
51
|
a = prep_as_str(argument.prop.instance)
|
|
52
52
|
b = prep_as_str(argument.args[0])
|
|
53
|
-
return f
|
|
53
|
+
return f"{a} index {b} =>"
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
class SetIndexPreProcessor(PreProcessor):
|
|
@@ -59,7 +59,7 @@ class SetIndexPreProcessor(PreProcessor):
|
|
|
59
59
|
a = prep_as_str(argument.prop.instance)
|
|
60
60
|
b = prep_as_str(argument.args[0])
|
|
61
61
|
c = prep_as_str(argument.args[1])
|
|
62
|
-
return f
|
|
62
|
+
return f"{a} index {b} set {c} =>"
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
class DeleteIndexPreProcessor(PreProcessor):
|
|
@@ -67,7 +67,7 @@ class DeleteIndexPreProcessor(PreProcessor):
|
|
|
67
67
|
assert len(argument.args) == 1
|
|
68
68
|
a = prep_as_str(argument.prop.instance)
|
|
69
69
|
b = prep_as_str(argument.args[0])
|
|
70
|
-
return f
|
|
70
|
+
return f"{a} remove {b} =>"
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
class PromptPreProcessor(PreProcessor):
|
|
@@ -81,7 +81,7 @@ class ComparePreProcessor(PreProcessor):
|
|
|
81
81
|
comp = argument.prop.operator
|
|
82
82
|
a = prep_as_str(argument.prop.instance)
|
|
83
83
|
b = prep_as_str(argument.args[0])
|
|
84
|
-
return f"{a} {
|
|
84
|
+
return f"{a} {comp!s} {b} =>"
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
class RankPreProcessor(PreProcessor):
|
|
@@ -91,22 +91,22 @@ class RankPreProcessor(PreProcessor):
|
|
|
91
91
|
measure = argument.prop.measure if argument.prop.measure else argument.args[0]
|
|
92
92
|
list_ = prep_as_str(argument.prop.instance)
|
|
93
93
|
# convert to list if not already a list
|
|
94
|
-
if
|
|
95
|
-
list_ = [v.strip() for v in list_.split(
|
|
94
|
+
if "|" in list_ and "[" not in list_:
|
|
95
|
+
list_ = [v.strip() for v in list_.split("|") if len(v.strip()) > 0]
|
|
96
96
|
list_ = str(list_)
|
|
97
|
-
return f"order: '{
|
|
97
|
+
return f"order: '{order!s}' measure: '{measure!s}' list: {list_} =>"
|
|
98
98
|
|
|
99
99
|
|
|
100
100
|
class ReplacePreProcessor(PreProcessor):
|
|
101
101
|
def __call__(self, argument) -> Any:
|
|
102
102
|
assert len(argument.args) == 2
|
|
103
|
-
return f"text '{argument.prop.instance}' replace '{
|
|
103
|
+
return f"text '{argument.prop.instance}' replace '{argument.args[0]!s}' with '{argument.args[1]!s}'=>"
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
class IncludePreProcessor(PreProcessor):
|
|
107
107
|
def __call__(self, argument) -> Any:
|
|
108
108
|
assert len(argument.args) == 1
|
|
109
|
-
return f"text '{argument.prop.instance}' include '{
|
|
109
|
+
return f"text '{argument.prop.instance}' include '{argument.args[0]!s}' =>"
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
class CombinePreProcessor(PreProcessor):
|
|
@@ -122,9 +122,12 @@ class TemplatePreProcessor(PreProcessor):
|
|
|
122
122
|
placeholder = argument.prop.placeholder
|
|
123
123
|
template = argument.prop.template
|
|
124
124
|
parts = str(template).split(placeholder)
|
|
125
|
-
assert len(parts) == 2,
|
|
125
|
+
assert len(parts) == 2, (
|
|
126
|
+
f"Your template must contain exactly one placeholder '{placeholder}' split:"
|
|
127
|
+
+ str(len(parts))
|
|
128
|
+
)
|
|
126
129
|
argument.prop.template_suffix = parts[1]
|
|
127
|
-
return f
|
|
130
|
+
return f"----------\n[Template]:\n{parts[0]}"
|
|
128
131
|
|
|
129
132
|
|
|
130
133
|
class NegatePreProcessor(PreProcessor):
|
|
@@ -168,14 +171,14 @@ class IsInstanceOfPreProcessor(PreProcessor):
|
|
|
168
171
|
class ExtractPatternPreProcessor(PreProcessor):
|
|
169
172
|
def __call__(self, argument) -> Any:
|
|
170
173
|
assert len(argument.args) == 1
|
|
171
|
-
return f"from '{
|
|
174
|
+
return f"from '{argument.prop.instance!s}' extract '{argument.args[0]!s}' =>"
|
|
172
175
|
|
|
173
176
|
|
|
174
177
|
class SimpleSymbolicExpressionPreProcessor(PreProcessor):
|
|
175
178
|
def __call__(self, argument) -> Any:
|
|
176
179
|
assert len(argument.args) >= 1
|
|
177
180
|
val = str(argument.args[0])
|
|
178
|
-
val = val.replace(
|
|
181
|
+
val = val.replace("self", str(argument.prop.instance))
|
|
179
182
|
return f"expr :{val} =: =>"
|
|
180
183
|
|
|
181
184
|
|
|
@@ -193,87 +196,89 @@ class SemanticMappingPreProcessor(PreProcessor):
|
|
|
193
196
|
assert len(argument.args) >= 1
|
|
194
197
|
topics = list(argument.prop.subscriber.keys())
|
|
195
198
|
assert len(topics) > 0
|
|
196
|
-
return f"topics {
|
|
199
|
+
return f"topics {topics!s} in\ntext: '{argument.args[0]!s}' =>"
|
|
197
200
|
|
|
198
201
|
|
|
199
202
|
class SimulateCodePreProcessor(PreProcessor):
|
|
200
203
|
def __call__(self, argument) -> Any:
|
|
201
|
-
val = argument.args[0] if len(argument.args) > 0 else
|
|
202
|
-
return f"code '{
|
|
204
|
+
val = argument.args[0] if len(argument.args) > 0 else ""
|
|
205
|
+
return f"code '{argument.prop.instance!s}' params '{val!s}' =>"
|
|
203
206
|
|
|
204
207
|
|
|
205
208
|
class GenerateCodePreProcessor(PreProcessor):
|
|
206
209
|
def __call__(self, argument) -> Any:
|
|
207
|
-
return f"description '{
|
|
210
|
+
return f"description '{argument.prop.instance!s}' =>"
|
|
208
211
|
|
|
209
212
|
|
|
210
213
|
class TextToOutlinePreProcessor(PreProcessor):
|
|
211
214
|
def __call__(self, argument) -> Any:
|
|
212
|
-
return f"text '{
|
|
215
|
+
return f"text '{argument.prop.instance!s}' =>"
|
|
213
216
|
|
|
214
217
|
|
|
215
218
|
class UniquePreProcessor(PreProcessor):
|
|
216
219
|
def __call__(self, argument) -> Any:
|
|
217
220
|
unique = argument.prop.keys
|
|
218
|
-
val = f
|
|
219
|
-
return f"{val}text '{
|
|
221
|
+
val = f"List of keys: {unique}\n"
|
|
222
|
+
return f"{val}text '{argument.prop.instance!s}' =>"
|
|
220
223
|
|
|
221
224
|
|
|
222
225
|
class GenerateTextPreProcessor(PreProcessor):
|
|
223
226
|
def __call__(self, argument) -> Any:
|
|
224
|
-
return f"{
|
|
227
|
+
return f"{argument.prop.instance!s}"
|
|
225
228
|
|
|
226
229
|
|
|
227
230
|
class ClusterPreProcessor(PreProcessor):
|
|
228
231
|
def __call__(self, argument) -> Any:
|
|
229
|
-
assert isinstance(argument.prop.instance.value, list),
|
|
232
|
+
assert isinstance(argument.prop.instance.value, list), (
|
|
233
|
+
"ClusterPreProcessor can only be applied to a list"
|
|
234
|
+
)
|
|
230
235
|
return argument.prop.instance.value
|
|
231
236
|
|
|
232
237
|
|
|
233
238
|
class ForEachPreProcessor(PreProcessor):
|
|
234
239
|
def __call__(self, argument) -> Any:
|
|
235
|
-
val
|
|
236
|
-
cond
|
|
240
|
+
val = prep_as_str(argument.prop.instance)
|
|
241
|
+
cond = argument.prop.condition
|
|
237
242
|
apply = argument.prop.apply
|
|
238
243
|
return f"{val} foreach '{cond}' apply '{apply}' =>"
|
|
239
244
|
|
|
240
245
|
|
|
241
246
|
class MapPreProcessor(PreProcessor):
|
|
242
247
|
def __call__(self, argument) -> Any:
|
|
243
|
-
val
|
|
248
|
+
val = prep_as_str(argument.prop.instance)
|
|
244
249
|
context = argument.prop.context
|
|
245
|
-
return f"{val} map '{
|
|
250
|
+
return f"{val} map '{context!s}' =>"
|
|
246
251
|
|
|
247
252
|
|
|
248
253
|
class ListPreProcessor(PreProcessor):
|
|
249
254
|
def __call__(self, argument) -> Any:
|
|
250
|
-
val
|
|
255
|
+
val = prep_as_str(argument.prop.instance)
|
|
251
256
|
cond = argument.prop.condition
|
|
252
257
|
return f"{val} list '{cond}' =>"
|
|
253
258
|
|
|
254
259
|
|
|
255
260
|
class QueryPreProcessor(PreProcessor):
|
|
256
261
|
def __call__(self, argument) -> Any:
|
|
257
|
-
val
|
|
262
|
+
val = f"Data:\n{argument.prop.instance!s}\n"
|
|
258
263
|
query = f"Context: {argument.prop.context}\n"
|
|
259
264
|
return f"{val}{query}Answer:"
|
|
260
265
|
|
|
261
266
|
|
|
262
267
|
class SufficientInformationPreProcessor(PreProcessor):
|
|
263
268
|
def __call__(self, argument) -> Any:
|
|
264
|
-
val
|
|
269
|
+
val = prep_as_str(argument.prop.instance)
|
|
265
270
|
query = prep_as_str(argument.prop.query)
|
|
266
|
-
return f
|
|
271
|
+
return f"query {query} content {val} =>"
|
|
267
272
|
|
|
268
273
|
|
|
269
274
|
class ExpandFunctionPreProcessor(PreProcessor):
|
|
270
275
|
def __call__(self, argument) -> Any:
|
|
271
276
|
val = prep_as_str(argument.prop.instance)
|
|
272
|
-
return f
|
|
277
|
+
return f"{val} =>\ndef"
|
|
273
278
|
|
|
274
279
|
|
|
275
280
|
class ArgsPreProcessor(PreProcessor):
|
|
276
|
-
def __init__(self, format: str =
|
|
281
|
+
def __init__(self, format: str = "") -> None:
|
|
277
282
|
self.format = format
|
|
278
283
|
|
|
279
284
|
def __call__(self, argument) -> Any:
|
|
@@ -285,14 +290,14 @@ class ArgsPreProcessor(PreProcessor):
|
|
|
285
290
|
class ModifyPreProcessor(PreProcessor):
|
|
286
291
|
def __call__(self, argument) -> Any:
|
|
287
292
|
changes = argument.prop.changes
|
|
288
|
-
return f"text '{
|
|
293
|
+
return f"text '{argument.prop.instance!s}' modify '{changes!s}'=>"
|
|
289
294
|
|
|
290
295
|
|
|
291
296
|
class FilterPreProcessor(PreProcessor):
|
|
292
297
|
def __call__(self, argument) -> Any:
|
|
293
298
|
criteria = argument.prop.criteria
|
|
294
|
-
include =
|
|
295
|
-
return f"text '{
|
|
299
|
+
include = "include" if argument.prop.include else "remove"
|
|
300
|
+
return f"text '{argument.prop.instance!s}' {include} '{criteria!s}' =>"
|
|
296
301
|
|
|
297
302
|
|
|
298
303
|
class MapExpressionPreProcessor(PreProcessor):
|
|
@@ -303,58 +308,56 @@ class MapExpressionPreProcessor(PreProcessor):
|
|
|
303
308
|
|
|
304
309
|
|
|
305
310
|
class ArgsToInputPreProcessor(PreProcessor):
|
|
306
|
-
def __init__(self, skip:
|
|
311
|
+
def __init__(self, skip: list[int] | None = None) -> None:
|
|
307
312
|
super().__init__()
|
|
308
313
|
skip = [skip] if skip and isinstance(skip, int) else skip
|
|
309
314
|
self.skip = skip if skip is not None else []
|
|
310
315
|
|
|
311
316
|
def __call__(self, argument) -> Any:
|
|
312
|
-
input_ =
|
|
317
|
+
input_ = ""
|
|
313
318
|
for i, arg in enumerate(argument.args):
|
|
314
319
|
if i in self.skip:
|
|
315
320
|
continue
|
|
316
|
-
input_ += f"{
|
|
321
|
+
input_ += f"{arg!s}\n"
|
|
317
322
|
return input_
|
|
318
323
|
|
|
319
324
|
|
|
320
325
|
class SelfToInputPreProcessor(PreProcessor):
|
|
321
|
-
def __init__(self, skip:
|
|
326
|
+
def __init__(self, skip: list[int] | None = None) -> None:
|
|
322
327
|
super().__init__()
|
|
323
328
|
skip = [skip] if skip and isinstance(skip, int) else skip
|
|
324
329
|
self.skip = skip if skip is not None else []
|
|
325
330
|
|
|
326
331
|
def __call__(self, argument) -> Any:
|
|
327
|
-
|
|
328
|
-
return input_
|
|
332
|
+
return f"{argument.prop.instance!s}\n"
|
|
329
333
|
|
|
330
334
|
|
|
331
335
|
class DataTemplatePreProcessor(PreProcessor):
|
|
332
|
-
def __init__(self, skip:
|
|
336
|
+
def __init__(self, skip: list[int] | None = None) -> None:
|
|
333
337
|
super().__init__()
|
|
334
338
|
self.skip = skip if skip is not None else []
|
|
335
339
|
|
|
336
340
|
def __call__(self, argument) -> Any:
|
|
337
|
-
input_ = f
|
|
341
|
+
input_ = f"[Data]:\n{argument.prop.instance!s}\n"
|
|
338
342
|
for i, arg in enumerate(argument.args):
|
|
339
343
|
if i in self.skip:
|
|
340
344
|
continue
|
|
341
|
-
input_ += f"{
|
|
345
|
+
input_ += f"{arg!s}\n"
|
|
342
346
|
return input_
|
|
343
347
|
|
|
344
348
|
|
|
345
349
|
class ConsoleInputPreProcessor(PreProcessor):
|
|
346
|
-
def __init__(self, skip:
|
|
350
|
+
def __init__(self, skip: list[int] | None = None) -> None:
|
|
347
351
|
super().__init__()
|
|
348
352
|
skip = [skip] if skip and isinstance(skip, int) else skip
|
|
349
353
|
self.skip = skip if skip is not None else []
|
|
350
354
|
|
|
351
355
|
def __call__(self, argument) -> Any:
|
|
352
|
-
|
|
353
|
-
return input_
|
|
356
|
+
return f"\n{argument.args[0]!s}\n$> "
|
|
354
357
|
|
|
355
358
|
|
|
356
359
|
class ConsolePreProcessor(PreProcessor):
|
|
357
|
-
def __init__(self, skip:
|
|
360
|
+
def __init__(self, skip: list[int] | None = None) -> None:
|
|
358
361
|
super().__init__()
|
|
359
362
|
skip = [skip] if skip and isinstance(skip, int) else skip
|
|
360
363
|
self.skip = skip if skip is not None else []
|
|
@@ -363,10 +366,10 @@ class ConsolePreProcessor(PreProcessor):
|
|
|
363
366
|
# _func is called as: _func(self, self.value, *method_args, **method_kwargs)
|
|
364
367
|
# argument.args[0] == symbol value, argument.prop.instance == Symbol object
|
|
365
368
|
if argument.args:
|
|
366
|
-
symbol_obj
|
|
369
|
+
symbol_obj = argument.prop.instance
|
|
367
370
|
symbol_value = argument.args[0]
|
|
368
|
-
method_args
|
|
369
|
-
object_ = f"symbol_value: {
|
|
371
|
+
method_args = argument.args[1:]
|
|
372
|
+
object_ = f"symbol_value: {symbol_value!r}"
|
|
370
373
|
|
|
371
374
|
# kwargs passed at Symbol-construction time (e.g. test_kwarg=…)
|
|
372
375
|
if symbol_obj._kwargs:
|
|
@@ -381,13 +384,11 @@ class ConsolePreProcessor(PreProcessor):
|
|
|
381
384
|
return object_
|
|
382
385
|
|
|
383
386
|
|
|
384
|
-
|
|
385
|
-
|
|
386
387
|
class LanguagePreProcessor(PreProcessor):
|
|
387
388
|
def __call__(self, argument) -> Any:
|
|
388
389
|
language = argument.prop.language
|
|
389
390
|
argument.prop.prompt = argument.prop.prompt.format(language)
|
|
390
|
-
return f"{
|
|
391
|
+
return f"{argument.prop.instance!s}"
|
|
391
392
|
|
|
392
393
|
|
|
393
394
|
class TextFormatPreProcessor(PreProcessor):
|
|
@@ -408,15 +409,18 @@ class TranscriptionPreProcessor(PreProcessor):
|
|
|
408
409
|
class StylePreProcessor(PreProcessor):
|
|
409
410
|
def __call__(self, argument) -> Any:
|
|
410
411
|
description = argument.prop.description
|
|
411
|
-
text = f
|
|
412
|
-
libs =
|
|
412
|
+
text = f"[FORMAT]: {description}\n"
|
|
413
|
+
libs = ", ".join(argument.prop.libraries)
|
|
413
414
|
libraries = f"[LIBRARIES]: {libs}\n"
|
|
414
|
-
content = f
|
|
415
|
+
content = f"[DATA]:\n{argument.prop.instance!s}\n\n"
|
|
415
416
|
if argument.prop.template:
|
|
416
417
|
placeholder = argument.prop.placeholder
|
|
417
|
-
template
|
|
418
|
-
parts
|
|
419
|
-
assert len(parts) == 2,
|
|
418
|
+
template = argument.prop.template
|
|
419
|
+
parts = str(template).split(placeholder)
|
|
420
|
+
assert len(parts) == 2, (
|
|
421
|
+
f"Your template must contain exactly one placeholder '{placeholder}' split:"
|
|
422
|
+
+ str(len(parts))
|
|
423
|
+
)
|
|
420
424
|
argument.prop.template_suffix = parts[1]
|
|
421
425
|
return f'f"{text}{libraries}{content}"----------\n[TEMPLATE]:\n{parts[0]}'
|
|
422
426
|
return f"{text}{libraries}{content}"
|
|
@@ -439,9 +443,9 @@ class UnwrapListSymbolsPreProcessor(PreProcessor):
|
|
|
439
443
|
class ExceptionPreProcessor(PreProcessor):
|
|
440
444
|
def __call__(self, argument) -> Any:
|
|
441
445
|
ctxt = prep_as_str(argument.prop.instance)
|
|
442
|
-
ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else
|
|
443
|
-
val
|
|
444
|
-
e
|
|
446
|
+
ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ""
|
|
447
|
+
val = argument.prop.query
|
|
448
|
+
e = argument.prop.exception
|
|
445
449
|
exception = "".join(traceback.format_exception_only(type(e), e)).strip()
|
|
446
450
|
return f"context '{val}' exception '{exception}' code'{ctxt}' =>"
|
|
447
451
|
|
|
@@ -449,47 +453,47 @@ class ExceptionPreProcessor(PreProcessor):
|
|
|
449
453
|
class CorrectionPreProcessor(PreProcessor):
|
|
450
454
|
def __call__(self, argument) -> Any:
|
|
451
455
|
ctxt = prep_as_str(argument.prop.instance)
|
|
452
|
-
ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else
|
|
453
|
-
val
|
|
454
|
-
exception =
|
|
456
|
+
ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ""
|
|
457
|
+
val = argument.prop.context
|
|
458
|
+
exception = ""
|
|
455
459
|
if not argument.prop.exception:
|
|
456
|
-
e
|
|
457
|
-
err_msg
|
|
460
|
+
e = argument.prop.exception
|
|
461
|
+
err_msg = "".join(traceback.format_exception_only(type(e), e)).strip()
|
|
458
462
|
exception = f" exception '{err_msg}'"
|
|
459
463
|
return f'context "{val}"{exception} code "{ctxt}" =>'
|
|
460
464
|
|
|
461
465
|
|
|
462
466
|
class EnumPreProcessor(PreProcessor):
|
|
463
467
|
def __call__(self, argument) -> Any:
|
|
464
|
-
return f
|
|
468
|
+
return f"[{', '.join([str(x) for x in argument.prop.enum])}]\n"
|
|
465
469
|
|
|
466
470
|
|
|
467
471
|
class TextMessagePreProcessor(PreProcessor):
|
|
468
472
|
def __call__(self, argument) -> Any:
|
|
469
|
-
return f
|
|
473
|
+
return f"Text: {argument.prop.instance!s}\n"
|
|
470
474
|
|
|
471
475
|
|
|
472
476
|
class SummaryPreProcessing(PreProcessor):
|
|
473
477
|
def __call__(self, argument) -> Any:
|
|
474
|
-
ctxt = f"Context: {argument.prop.context} " if argument.prop.context else
|
|
475
|
-
return f
|
|
478
|
+
ctxt = f"Context: {argument.prop.context} " if argument.prop.context else ""
|
|
479
|
+
return f"{ctxt}Text: {argument.prop.instance!s}\n"
|
|
476
480
|
|
|
477
481
|
|
|
478
482
|
class CleanTextMessagePreProcessor(PreProcessor):
|
|
479
483
|
def __call__(self, argument) -> Any:
|
|
480
|
-
return f"Text: '{
|
|
484
|
+
return f"Text: '{argument.prop.instance!s}' =>"
|
|
481
485
|
|
|
482
486
|
|
|
483
487
|
class PredictionMessagePreProcessor(PreProcessor):
|
|
484
|
-
def __call__(self,
|
|
485
|
-
return
|
|
488
|
+
def __call__(self, _argument) -> Any:
|
|
489
|
+
return "Prediction:"
|
|
486
490
|
|
|
487
491
|
|
|
488
492
|
class ArrowMessagePreProcessor(PreProcessor):
|
|
489
493
|
def __call__(self, argument) -> Any:
|
|
490
|
-
return f
|
|
494
|
+
return f"{argument.prop.instance!s} =>"
|
|
491
495
|
|
|
492
496
|
|
|
493
497
|
class ValuePreProcessor(PreProcessor):
|
|
494
498
|
def __call__(self, argument) -> Any:
|
|
495
|
-
return f
|
|
499
|
+
return f"{argument.prop.instance!s}"
|
symai/processor.py
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
3
|
from .post_processors import PostProcessor
|
|
4
|
+
from .pre_processors import PreProcessor
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class ProcessorPipeline:
|
|
7
|
-
|
|
8
|
+
"""
|
|
8
9
|
Base class for all processors.
|
|
9
10
|
|
|
10
11
|
Args:
|
|
11
12
|
processors: A list of processors to be applied to the response.
|
|
12
|
-
|
|
13
|
+
"""
|
|
13
14
|
|
|
14
|
-
def __init__(self, processors:
|
|
15
|
+
def __init__(self, processors: list[PreProcessor | PostProcessor] | None = None) -> None:
|
|
15
16
|
self.processors = processors
|
|
16
17
|
|
|
17
18
|
def __call__(self, *args: Any, **kwds: Any) -> Any:
|
|
@@ -20,18 +21,25 @@ class ProcessorPipeline:
|
|
|
20
21
|
|
|
21
22
|
if isinstance(self.processors[0], PreProcessor):
|
|
22
23
|
assert len(args) == 1, f"Expected 1 argument of type Argument, got {len(args)}"
|
|
23
|
-
processed_input
|
|
24
|
+
processed_input = ""
|
|
24
25
|
for processor in self.processors:
|
|
25
|
-
assert isinstance(processor, PreProcessor),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
assert isinstance(processor, PreProcessor), (
|
|
27
|
+
f"Expected PreProcessor, got {type(processor)}"
|
|
28
|
+
)
|
|
29
|
+
argument = args[0]
|
|
30
|
+
t = processor(argument, **kwds)
|
|
31
|
+
processed_input += t if t is not None else ""
|
|
29
32
|
return processed_input
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
assert len(args) == 2,
|
|
34
|
+
if isinstance(self.processors[0], PostProcessor):
|
|
35
|
+
assert len(args) == 2, (
|
|
36
|
+
f"Expected 2 arguments of type Response and Argument, got {len(args)}"
|
|
37
|
+
)
|
|
33
38
|
response, argument = args
|
|
34
39
|
for processor in self.processors:
|
|
35
|
-
assert isinstance(processor, PostProcessor),
|
|
40
|
+
assert isinstance(processor, PostProcessor), (
|
|
41
|
+
f"Expected PostProcessor, got {type(processor)}"
|
|
42
|
+
)
|
|
36
43
|
response = processor(response, argument, **kwds)
|
|
37
44
|
return response
|
|
45
|
+
return None
|