symbolicai 1.0.0__py3-none-any.whl → 1.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. symai/__init__.py +198 -134
  2. symai/backend/base.py +51 -51
  3. symai/backend/engines/drawing/engine_bfl.py +33 -33
  4. symai/backend/engines/drawing/engine_gpt_image.py +4 -10
  5. symai/backend/engines/embedding/engine_llama_cpp.py +50 -35
  6. symai/backend/engines/embedding/engine_openai.py +22 -16
  7. symai/backend/engines/execute/engine_python.py +16 -16
  8. symai/backend/engines/files/engine_io.py +51 -49
  9. symai/backend/engines/imagecaptioning/engine_blip2.py +27 -23
  10. symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +53 -46
  11. symai/backend/engines/index/engine_pinecone.py +116 -88
  12. symai/backend/engines/index/engine_qdrant.py +1011 -0
  13. symai/backend/engines/index/engine_vectordb.py +78 -52
  14. symai/backend/engines/lean/engine_lean4.py +65 -25
  15. symai/backend/engines/neurosymbolic/__init__.py +35 -28
  16. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +137 -135
  17. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +145 -152
  18. symai/backend/engines/neurosymbolic/engine_cerebras.py +328 -0
  19. symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +75 -49
  20. symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +199 -155
  21. symai/backend/engines/neurosymbolic/engine_groq.py +106 -72
  22. symai/backend/engines/neurosymbolic/engine_huggingface.py +100 -67
  23. symai/backend/engines/neurosymbolic/engine_llama_cpp.py +121 -93
  24. symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +213 -132
  25. symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +180 -137
  26. symai/backend/engines/ocr/engine_apilayer.py +18 -20
  27. symai/backend/engines/output/engine_stdout.py +9 -9
  28. symai/backend/engines/{webscraping → scrape}/engine_requests.py +25 -11
  29. symai/backend/engines/search/engine_openai.py +95 -83
  30. symai/backend/engines/search/engine_parallel.py +665 -0
  31. symai/backend/engines/search/engine_perplexity.py +40 -41
  32. symai/backend/engines/search/engine_serpapi.py +33 -28
  33. symai/backend/engines/speech_to_text/engine_local_whisper.py +37 -27
  34. symai/backend/engines/symbolic/engine_wolframalpha.py +14 -8
  35. symai/backend/engines/text_to_speech/engine_openai.py +15 -19
  36. symai/backend/engines/text_vision/engine_clip.py +34 -28
  37. symai/backend/engines/userinput/engine_console.py +3 -4
  38. symai/backend/mixin/__init__.py +4 -0
  39. symai/backend/mixin/anthropic.py +48 -40
  40. symai/backend/mixin/cerebras.py +9 -0
  41. symai/backend/mixin/deepseek.py +4 -5
  42. symai/backend/mixin/google.py +5 -4
  43. symai/backend/mixin/groq.py +2 -4
  44. symai/backend/mixin/openai.py +132 -110
  45. symai/backend/settings.py +14 -14
  46. symai/chat.py +164 -94
  47. symai/collect/dynamic.py +13 -11
  48. symai/collect/pipeline.py +39 -31
  49. symai/collect/stats.py +109 -69
  50. symai/components.py +578 -238
  51. symai/constraints.py +14 -5
  52. symai/core.py +1495 -1210
  53. symai/core_ext.py +55 -50
  54. symai/endpoints/api.py +113 -58
  55. symai/extended/api_builder.py +22 -17
  56. symai/extended/arxiv_pdf_parser.py +13 -5
  57. symai/extended/bibtex_parser.py +8 -4
  58. symai/extended/conversation.py +88 -69
  59. symai/extended/document.py +40 -27
  60. symai/extended/file_merger.py +45 -7
  61. symai/extended/graph.py +38 -24
  62. symai/extended/html_style_template.py +17 -11
  63. symai/extended/interfaces/blip_2.py +1 -1
  64. symai/extended/interfaces/clip.py +4 -2
  65. symai/extended/interfaces/console.py +5 -3
  66. symai/extended/interfaces/dall_e.py +3 -1
  67. symai/extended/interfaces/file.py +2 -0
  68. symai/extended/interfaces/flux.py +3 -1
  69. symai/extended/interfaces/gpt_image.py +15 -6
  70. symai/extended/interfaces/input.py +2 -1
  71. symai/extended/interfaces/llava.py +1 -1
  72. symai/extended/interfaces/{naive_webscraping.py → naive_scrape.py} +3 -2
  73. symai/extended/interfaces/naive_vectordb.py +2 -2
  74. symai/extended/interfaces/ocr.py +4 -2
  75. symai/extended/interfaces/openai_search.py +2 -0
  76. symai/extended/interfaces/parallel.py +30 -0
  77. symai/extended/interfaces/perplexity.py +2 -0
  78. symai/extended/interfaces/pinecone.py +6 -4
  79. symai/extended/interfaces/python.py +2 -0
  80. symai/extended/interfaces/serpapi.py +2 -0
  81. symai/extended/interfaces/terminal.py +0 -1
  82. symai/extended/interfaces/tts.py +2 -1
  83. symai/extended/interfaces/whisper.py +2 -1
  84. symai/extended/interfaces/wolframalpha.py +1 -0
  85. symai/extended/metrics/__init__.py +1 -1
  86. symai/extended/metrics/similarity.py +5 -2
  87. symai/extended/os_command.py +31 -22
  88. symai/extended/packages/symdev.py +39 -34
  89. symai/extended/packages/sympkg.py +30 -27
  90. symai/extended/packages/symrun.py +46 -35
  91. symai/extended/repo_cloner.py +10 -9
  92. symai/extended/seo_query_optimizer.py +15 -12
  93. symai/extended/solver.py +104 -76
  94. symai/extended/summarizer.py +8 -7
  95. symai/extended/taypan_interpreter.py +10 -9
  96. symai/extended/vectordb.py +28 -15
  97. symai/formatter/formatter.py +39 -31
  98. symai/formatter/regex.py +46 -44
  99. symai/functional.py +184 -86
  100. symai/imports.py +85 -51
  101. symai/interfaces.py +1 -1
  102. symai/memory.py +33 -24
  103. symai/menu/screen.py +28 -19
  104. symai/misc/console.py +27 -27
  105. symai/misc/loader.py +4 -3
  106. symai/models/base.py +147 -76
  107. symai/models/errors.py +1 -1
  108. symai/ops/__init__.py +1 -1
  109. symai/ops/measures.py +17 -14
  110. symai/ops/primitives.py +933 -635
  111. symai/post_processors.py +28 -24
  112. symai/pre_processors.py +58 -52
  113. symai/processor.py +15 -9
  114. symai/prompts.py +714 -649
  115. symai/server/huggingface_server.py +115 -32
  116. symai/server/llama_cpp_server.py +14 -6
  117. symai/server/qdrant_server.py +206 -0
  118. symai/shell.py +98 -39
  119. symai/shellsv.py +307 -223
  120. symai/strategy.py +135 -81
  121. symai/symbol.py +276 -225
  122. symai/utils.py +62 -46
  123. {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/METADATA +19 -9
  124. symbolicai-1.1.1.dist-info/RECORD +169 -0
  125. symbolicai-1.0.0.dist-info/RECORD +0 -163
  126. {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/WHEEL +0 -0
  127. {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/entry_points.txt +0 -0
  128. {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/licenses/LICENSE +0 -0
  129. {symbolicai-1.0.0.dist-info → symbolicai-1.1.1.dist-info}/top_level.txt +0 -0
symai/post_processors.py CHANGED
@@ -29,7 +29,9 @@ class StripPostProcessor(PostProcessor):
29
29
 
30
30
  class ClusterPostProcessor(PostProcessor):
31
31
  def __call__(self, response, argument) -> Any:
32
- assert hasattr(self, 'clustering_kwargs'), "'clustering_kwargs' must be set in the class before calling __call__; use 'set' method."
32
+ assert hasattr(self, "clustering_kwargs"), (
33
+ "'clustering_kwargs' must be set in the class before calling __call__; use 'set' method."
34
+ )
33
35
  clustering = HDBSCAN(**self.clustering_kwargs).fit(response)
34
36
  ids = np.unique(clustering.labels_)
35
37
  map_ = {}
@@ -47,32 +49,32 @@ class ClusterPostProcessor(PostProcessor):
47
49
 
48
50
  class TemplatePostProcessor(PostProcessor):
49
51
  def __call__(self, response, argument) -> Any:
50
- template = argument.prop.template
52
+ template = argument.prop.template
51
53
  placeholder = argument.prop.placeholder
52
- template = argument.prop.template
54
+ template = argument.prop.template
53
55
  parts = str(template).split(placeholder)
54
- return f'{parts[0]}{response}{parts[1]}'
56
+ return f"{parts[0]}{response}{parts[1]}"
55
57
 
56
58
 
57
59
  class SplitNewLinePostProcessor(PostProcessor):
58
60
  def __call__(self, response, _argument) -> Any:
59
- tmp = response.split('\n')
61
+ tmp = response.split("\n")
60
62
  return [t.strip() for t in tmp if len(t.strip()) > 0]
61
63
 
62
64
 
63
65
  class JsonTruncatePostProcessor(PostProcessor):
64
66
  def __call__(self, response, _argument) -> Any:
65
- count_b = response.count('[JSON_BEGIN]')
66
- count_e = response.count('[JSON_END]')
67
+ count_b = response.count("[JSON_BEGIN]")
68
+ count_e = response.count("[JSON_END]")
67
69
  if count_b > 1 or count_e > 1:
68
70
  msg = "More than one [JSON_BEGIN] or [JSON_END] found. Please only generate one JSON response."
69
71
  UserMessage(msg)
70
72
  raise ValueError(msg)
71
73
  # cut off everything until the first '{'
72
- start_idx = response.find('{')
74
+ start_idx = response.find("{")
73
75
  response = response[start_idx:]
74
76
  # find the first occurence of '}' looking backwards
75
- end_idx = response.rfind('}') + 1
77
+ end_idx = response.rfind("}") + 1
76
78
  response = response[:end_idx]
77
79
  # search after the first character of '{' if it is a '"' and if not, replace it
78
80
  try:
@@ -85,17 +87,17 @@ class JsonTruncatePostProcessor(PostProcessor):
85
87
 
86
88
  class JsonTruncateMarkdownPostProcessor(PostProcessor):
87
89
  def __call__(self, response, _argument) -> Any:
88
- count_b = response.count('```json')
89
- count_e = response.count('```')
90
+ count_b = response.count("```json")
91
+ count_e = response.count("```")
90
92
  if count_b > 1 or count_e > 2:
91
93
  msg = "More than one ```json Markdown found. Please only generate one JSON response."
92
94
  UserMessage(msg)
93
95
  raise ValueError(msg)
94
96
  # cut off everything until the first '{'
95
- start_idx = response.find('{')
97
+ start_idx = response.find("{")
96
98
  response = response[start_idx:]
97
99
  # find the first occurence of '}' looking backwards
98
- end_idx = response.rfind('}') + 1
100
+ end_idx = response.rfind("}") + 1
99
101
  response = response[:end_idx]
100
102
  # search after the first character of '{' if it is a '"' and if not, replace it
101
103
  try:
@@ -108,13 +110,13 @@ class JsonTruncateMarkdownPostProcessor(PostProcessor):
108
110
 
109
111
  class CodeExtractPostProcessor(PostProcessor):
110
112
  def __call__(self, response, _argument, tag=None, **_kwargs) -> Any:
111
- if '```' not in str(response):
113
+ if "```" not in str(response):
112
114
  return response
113
115
  try:
114
116
  if tag is None:
115
- pattern = r'```(?:\w*\n)?(.*?)(?:```|$)'
117
+ pattern = r"```(?:\w*\n)?(.*?)(?:```|$)"
116
118
  else:
117
- pattern = r'```(?:\w*\n)?' + re.escape(str(tag)) + r'\n(.*?)(?:```|$)'
119
+ pattern = r"```(?:\w*\n)?" + re.escape(str(tag)) + r"\n(.*?)(?:```|$)"
118
120
  matches = re.findall(pattern, str(response), re.DOTALL)
119
121
  return "\n".join(matches).strip()
120
122
  except Exception:
@@ -129,10 +131,10 @@ class WolframAlphaPostProcessor(PostProcessor):
129
131
  response._value = res
130
132
  return response
131
133
  except StopIteration:
132
- vals = ''
134
+ vals = ""
133
135
  for pod in response.value.pods:
134
136
  for sub in pod.subpods:
135
- vals += f'{sub.plaintext}\n'
137
+ vals += f"{sub.plaintext}\n"
136
138
  if len(vals) > 0:
137
139
  response._value = vals
138
140
  return response
@@ -142,16 +144,16 @@ class WolframAlphaPostProcessor(PostProcessor):
142
144
  class SplitPipePostProcessor(PostProcessor):
143
145
  def __call__(self, response, _argument) -> Any:
144
146
  tmp = response if isinstance(response, list) else [response]
145
- tmp = [r.split('|') for r in tmp if len(r.strip()) > 0]
147
+ tmp = [r.split("|") for r in tmp if len(r.strip()) > 0]
146
148
  tmp = [item for group in tmp for item in group]
147
149
  return [t.strip() for t in tmp if len(t.strip()) > 0]
148
150
 
149
151
 
150
152
  class NotifySubscriberPostProcessor(PostProcessor):
151
153
  def __call__(self, response, argument) -> Any:
152
- for k, v in argument.kwargs['subscriber'].items():
154
+ for k, v in argument.kwargs["subscriber"].items():
153
155
  if k in response:
154
- Event = namedtuple('Event', ['args', 'kwargs', 'response'])
156
+ Event = namedtuple("Event", ["args", "kwargs", "response"])
155
157
  v(Event(argument.args, argument.kwargs, response))
156
158
  return response
157
159
 
@@ -198,19 +200,21 @@ class TakeLastPostProcessor(PostProcessor):
198
200
 
199
201
  class ExpandFunctionPostProcessor(PostProcessor):
200
202
  def __call__(self, response, _argument) -> Any:
201
- return 'def ' + response
203
+ return "def " + response
202
204
 
203
205
 
204
206
  class CaseInsensitivePostProcessor(PostProcessor):
205
207
  def __call__(self, response, _argument) -> Any:
206
208
  return str(response).lower()
207
209
 
210
+
208
211
  class ConfirmToBoolPostProcessor(PostProcessor):
209
212
  def __call__(self, response, _argument) -> Any:
210
213
  if response is None:
211
214
  return False
212
215
  rsp = response.strip()
213
216
  # Lazy Symbol import prevents post_processors -> symbol -> core -> functional -> post_processors cycle.
214
- from .symbol import Symbol # noqa
217
+ from .symbol import Symbol # noqa
218
+
215
219
  sym = Symbol(rsp)
216
- return bool(sym.isinstanceof('confirming answer'))
220
+ return bool(sym.isinstanceof("confirming answer"))
symai/pre_processors.py CHANGED
@@ -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'{value} => [JSON_BEGIN]'
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'{a} == {b} =>'
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'{a} index {b} =>'
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'{a} index {b} set {c} =>'
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'{a} remove {b} =>'
70
+ return f"{a} remove {b} =>"
71
71
 
72
72
 
73
73
  class PromptPreProcessor(PreProcessor):
@@ -91,8 +91,8 @@ 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 '|' in list_ and '[' not in list_:
95
- list_ = [v.strip() for v in list_.split('|') if len(v.strip()) > 0]
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
97
  return f"order: '{order!s}' measure: '{measure!s}' list: {list_} =>"
98
98
 
@@ -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, f"Your template must contain exactly one placeholder '{placeholder}' split:" + str(len(parts))
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'----------\n[Template]:\n{parts[0]}'
130
+ return f"----------\n[Template]:\n{parts[0]}"
128
131
 
129
132
 
130
133
  class NegatePreProcessor(PreProcessor):
@@ -175,7 +178,7 @@ 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('self', str(argument.prop.instance))
181
+ val = val.replace("self", str(argument.prop.instance))
179
182
  return f"expr :{val} =: =>"
180
183
 
181
184
 
@@ -198,7 +201,7 @@ class SemanticMappingPreProcessor(PreProcessor):
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 ''
204
+ val = argument.args[0] if len(argument.args) > 0 else ""
202
205
  return f"code '{argument.prop.instance!s}' params '{val!s}' =>"
203
206
 
204
207
 
@@ -215,7 +218,7 @@ class TextToOutlinePreProcessor(PreProcessor):
215
218
  class UniquePreProcessor(PreProcessor):
216
219
  def __call__(self, argument) -> Any:
217
220
  unique = argument.prop.keys
218
- val = f'List of keys: {unique}\n'
221
+ val = f"List of keys: {unique}\n"
219
222
  return f"{val}text '{argument.prop.instance!s}' =>"
220
223
 
221
224
 
@@ -226,54 +229,56 @@ class GenerateTextPreProcessor(PreProcessor):
226
229
 
227
230
  class ClusterPreProcessor(PreProcessor):
228
231
  def __call__(self, argument) -> Any:
229
- assert isinstance(argument.prop.instance.value, list), "ClusterPreProcessor can only be applied to a 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 = prep_as_str(argument.prop.instance)
236
- cond = argument.prop.condition
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 = prep_as_str(argument.prop.instance)
248
+ val = prep_as_str(argument.prop.instance)
244
249
  context = argument.prop.context
245
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 = prep_as_str(argument.prop.instance)
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 = f'Data:\n{argument.prop.instance!s}\n'
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 = prep_as_str(argument.prop.instance)
269
+ val = prep_as_str(argument.prop.instance)
265
270
  query = prep_as_str(argument.prop.query)
266
- return f'query {query} content {val} =>'
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'{val} =>\ndef'
277
+ return f"{val} =>\ndef"
273
278
 
274
279
 
275
280
  class ArgsPreProcessor(PreProcessor):
276
- def __init__(self, format: str = '') -> None:
281
+ def __init__(self, format: str = "") -> None:
277
282
  self.format = format
278
283
 
279
284
  def __call__(self, argument) -> Any:
@@ -291,7 +296,7 @@ class ModifyPreProcessor(PreProcessor):
291
296
  class FilterPreProcessor(PreProcessor):
292
297
  def __call__(self, argument) -> Any:
293
298
  criteria = argument.prop.criteria
294
- include = 'include' if argument.prop.include else 'remove'
299
+ include = "include" if argument.prop.include else "remove"
295
300
  return f"text '{argument.prop.instance!s}' {include} '{criteria!s}' =>"
296
301
 
297
302
 
@@ -309,7 +314,7 @@ class ArgsToInputPreProcessor(PreProcessor):
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
@@ -324,7 +329,7 @@ class SelfToInputPreProcessor(PreProcessor):
324
329
  self.skip = skip if skip is not None else []
325
330
 
326
331
  def __call__(self, argument) -> Any:
327
- return f'{argument.prop.instance!s}\n'
332
+ return f"{argument.prop.instance!s}\n"
328
333
 
329
334
 
330
335
  class DataTemplatePreProcessor(PreProcessor):
@@ -333,7 +338,7 @@ class DataTemplatePreProcessor(PreProcessor):
333
338
  self.skip = skip if skip is not None else []
334
339
 
335
340
  def __call__(self, argument) -> Any:
336
- input_ = f'[Data]:\n{argument.prop.instance!s}\n'
341
+ input_ = f"[Data]:\n{argument.prop.instance!s}\n"
337
342
  for i, arg in enumerate(argument.args):
338
343
  if i in self.skip:
339
344
  continue
@@ -348,7 +353,7 @@ class ConsoleInputPreProcessor(PreProcessor):
348
353
  self.skip = skip if skip is not None else []
349
354
 
350
355
  def __call__(self, argument) -> Any:
351
- return f'\n{argument.args[0]!s}\n$> '
356
+ return f"\n{argument.args[0]!s}\n$> "
352
357
 
353
358
 
354
359
  class ConsolePreProcessor(PreProcessor):
@@ -361,9 +366,9 @@ class ConsolePreProcessor(PreProcessor):
361
366
  # _func is called as: _func(self, self.value, *method_args, **method_kwargs)
362
367
  # argument.args[0] == symbol value, argument.prop.instance == Symbol object
363
368
  if argument.args:
364
- symbol_obj = argument.prop.instance
369
+ symbol_obj = argument.prop.instance
365
370
  symbol_value = argument.args[0]
366
- method_args = argument.args[1:]
371
+ method_args = argument.args[1:]
367
372
  object_ = f"symbol_value: {symbol_value!r}"
368
373
 
369
374
  # kwargs passed at Symbol-construction time (e.g. test_kwarg=…)
@@ -379,8 +384,6 @@ class ConsolePreProcessor(PreProcessor):
379
384
  return object_
380
385
 
381
386
 
382
-
383
-
384
387
  class LanguagePreProcessor(PreProcessor):
385
388
  def __call__(self, argument) -> Any:
386
389
  language = argument.prop.language
@@ -406,15 +409,18 @@ class TranscriptionPreProcessor(PreProcessor):
406
409
  class StylePreProcessor(PreProcessor):
407
410
  def __call__(self, argument) -> Any:
408
411
  description = argument.prop.description
409
- text = f'[FORMAT]: {description}\n'
410
- libs = ', '.join(argument.prop.libraries)
412
+ text = f"[FORMAT]: {description}\n"
413
+ libs = ", ".join(argument.prop.libraries)
411
414
  libraries = f"[LIBRARIES]: {libs}\n"
412
- content = f'[DATA]:\n{argument.prop.instance!s}\n\n'
415
+ content = f"[DATA]:\n{argument.prop.instance!s}\n\n"
413
416
  if argument.prop.template:
414
417
  placeholder = argument.prop.placeholder
415
- template = argument.prop.template
416
- parts = str(template).split(placeholder)
417
- assert len(parts) == 2, f"Your template must contain exactly one placeholder '{placeholder}' split:" + str(len(parts))
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
+ )
418
424
  argument.prop.template_suffix = parts[1]
419
425
  return f'f"{text}{libraries}{content}"----------\n[TEMPLATE]:\n{parts[0]}'
420
426
  return f"{text}{libraries}{content}"
@@ -437,9 +443,9 @@ class UnwrapListSymbolsPreProcessor(PreProcessor):
437
443
  class ExceptionPreProcessor(PreProcessor):
438
444
  def __call__(self, argument) -> Any:
439
445
  ctxt = prep_as_str(argument.prop.instance)
440
- ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ''
441
- val = argument.prop.query
442
- e = argument.prop.exception
446
+ ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ""
447
+ val = argument.prop.query
448
+ e = argument.prop.exception
443
449
  exception = "".join(traceback.format_exception_only(type(e), e)).strip()
444
450
  return f"context '{val}' exception '{exception}' code'{ctxt}' =>"
445
451
 
@@ -447,30 +453,30 @@ class ExceptionPreProcessor(PreProcessor):
447
453
  class CorrectionPreProcessor(PreProcessor):
448
454
  def __call__(self, argument) -> Any:
449
455
  ctxt = prep_as_str(argument.prop.instance)
450
- ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ''
451
- val = argument.prop.context
452
- exception = ''
456
+ ctxt = f"{ctxt}\n" if ctxt and len(ctxt) > 0 else ""
457
+ val = argument.prop.context
458
+ exception = ""
453
459
  if not argument.prop.exception:
454
- e = argument.prop.exception
455
- err_msg = "".join(traceback.format_exception_only(type(e), e)).strip()
460
+ e = argument.prop.exception
461
+ err_msg = "".join(traceback.format_exception_only(type(e), e)).strip()
456
462
  exception = f" exception '{err_msg}'"
457
463
  return f'context "{val}"{exception} code "{ctxt}" =>'
458
464
 
459
465
 
460
466
  class EnumPreProcessor(PreProcessor):
461
467
  def __call__(self, argument) -> Any:
462
- return f'[{", ".join([str(x) for x in argument.prop.enum])}]\n'
468
+ return f"[{', '.join([str(x) for x in argument.prop.enum])}]\n"
463
469
 
464
470
 
465
471
  class TextMessagePreProcessor(PreProcessor):
466
472
  def __call__(self, argument) -> Any:
467
- return f'Text: {argument.prop.instance!s}\n'
473
+ return f"Text: {argument.prop.instance!s}\n"
468
474
 
469
475
 
470
476
  class SummaryPreProcessing(PreProcessor):
471
477
  def __call__(self, argument) -> Any:
472
- ctxt = f"Context: {argument.prop.context} " if argument.prop.context else ''
473
- return f'{ctxt}Text: {argument.prop.instance!s}\n'
478
+ ctxt = f"Context: {argument.prop.context} " if argument.prop.context else ""
479
+ return f"{ctxt}Text: {argument.prop.instance!s}\n"
474
480
 
475
481
 
476
482
  class CleanTextMessagePreProcessor(PreProcessor):
@@ -480,14 +486,14 @@ class CleanTextMessagePreProcessor(PreProcessor):
480
486
 
481
487
  class PredictionMessagePreProcessor(PreProcessor):
482
488
  def __call__(self, _argument) -> Any:
483
- return 'Prediction:'
489
+ return "Prediction:"
484
490
 
485
491
 
486
492
  class ArrowMessagePreProcessor(PreProcessor):
487
493
  def __call__(self, argument) -> Any:
488
- return f'{argument.prop.instance!s} =>'
494
+ return f"{argument.prop.instance!s} =>"
489
495
 
490
496
 
491
497
  class ValuePreProcessor(PreProcessor):
492
498
  def __call__(self, argument) -> Any:
493
- return f'{argument.prop.instance!s}'
499
+ return f"{argument.prop.instance!s}"
symai/processor.py CHANGED
@@ -5,12 +5,12 @@ from .pre_processors import PreProcessor
5
5
 
6
6
 
7
7
  class ProcessorPipeline:
8
- '''
8
+ """
9
9
  Base class for all processors.
10
10
 
11
11
  Args:
12
12
  processors: A list of processors to be applied to the response.
13
- '''
13
+ """
14
14
 
15
15
  def __init__(self, processors: list[PreProcessor | PostProcessor] | None = None) -> None:
16
16
  self.processors = processors
@@ -21,19 +21,25 @@ class ProcessorPipeline:
21
21
 
22
22
  if isinstance(self.processors[0], PreProcessor):
23
23
  assert len(args) == 1, f"Expected 1 argument of type Argument, got {len(args)}"
24
- processed_input = ''
24
+ processed_input = ""
25
25
  for processor in self.processors:
26
- assert isinstance(processor, PreProcessor), f"Expected PreProcessor, got {type(processor)}"
27
- argument = args[0]
28
- t = processor(argument, **kwds)
29
- processed_input += t if t is not None else ''
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 ""
30
32
  return processed_input
31
33
 
32
34
  if isinstance(self.processors[0], PostProcessor):
33
- assert len(args) == 2, f"Expected 2 arguments of type Response and Argument, got {len(args)}"
35
+ assert len(args) == 2, (
36
+ f"Expected 2 arguments of type Response and Argument, got {len(args)}"
37
+ )
34
38
  response, argument = args
35
39
  for processor in self.processors:
36
- assert isinstance(processor, PostProcessor), f"Expected PostProcessor, got {type(processor)}"
40
+ assert isinstance(processor, PostProcessor), (
41
+ f"Expected PostProcessor, got {type(processor)}"
42
+ )
37
43
  response = processor(response, argument, **kwds)
38
44
  return response
39
45
  return None