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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. symai/__init__.py +96 -64
  2. symai/backend/base.py +93 -80
  3. symai/backend/engines/drawing/engine_bfl.py +12 -11
  4. symai/backend/engines/drawing/engine_gpt_image.py +108 -87
  5. symai/backend/engines/embedding/engine_llama_cpp.py +25 -28
  6. symai/backend/engines/embedding/engine_openai.py +3 -5
  7. symai/backend/engines/execute/engine_python.py +6 -5
  8. symai/backend/engines/files/engine_io.py +74 -67
  9. symai/backend/engines/imagecaptioning/engine_blip2.py +3 -3
  10. symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +54 -38
  11. symai/backend/engines/index/engine_pinecone.py +23 -24
  12. symai/backend/engines/index/engine_vectordb.py +16 -14
  13. symai/backend/engines/lean/engine_lean4.py +38 -34
  14. symai/backend/engines/neurosymbolic/__init__.py +41 -13
  15. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +262 -182
  16. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +263 -191
  17. symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +53 -49
  18. symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +212 -211
  19. symai/backend/engines/neurosymbolic/engine_groq.py +87 -63
  20. symai/backend/engines/neurosymbolic/engine_huggingface.py +21 -24
  21. symai/backend/engines/neurosymbolic/engine_llama_cpp.py +117 -48
  22. symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +256 -229
  23. symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +270 -150
  24. symai/backend/engines/ocr/engine_apilayer.py +6 -8
  25. symai/backend/engines/output/engine_stdout.py +1 -4
  26. symai/backend/engines/search/engine_openai.py +7 -7
  27. symai/backend/engines/search/engine_perplexity.py +5 -5
  28. symai/backend/engines/search/engine_serpapi.py +12 -14
  29. symai/backend/engines/speech_to_text/engine_local_whisper.py +20 -27
  30. symai/backend/engines/symbolic/engine_wolframalpha.py +3 -3
  31. symai/backend/engines/text_to_speech/engine_openai.py +5 -7
  32. symai/backend/engines/text_vision/engine_clip.py +7 -11
  33. symai/backend/engines/userinput/engine_console.py +3 -3
  34. symai/backend/engines/webscraping/engine_requests.py +81 -48
  35. symai/backend/mixin/__init__.py +13 -0
  36. symai/backend/mixin/anthropic.py +4 -2
  37. symai/backend/mixin/deepseek.py +2 -0
  38. symai/backend/mixin/google.py +2 -0
  39. symai/backend/mixin/openai.py +11 -3
  40. symai/backend/settings.py +83 -16
  41. symai/chat.py +101 -78
  42. symai/collect/__init__.py +7 -1
  43. symai/collect/dynamic.py +77 -69
  44. symai/collect/pipeline.py +35 -27
  45. symai/collect/stats.py +75 -63
  46. symai/components.py +198 -169
  47. symai/constraints.py +15 -12
  48. symai/core.py +698 -359
  49. symai/core_ext.py +32 -34
  50. symai/endpoints/api.py +80 -73
  51. symai/extended/.DS_Store +0 -0
  52. symai/extended/__init__.py +46 -12
  53. symai/extended/api_builder.py +11 -8
  54. symai/extended/arxiv_pdf_parser.py +13 -12
  55. symai/extended/bibtex_parser.py +2 -3
  56. symai/extended/conversation.py +101 -90
  57. symai/extended/document.py +17 -10
  58. symai/extended/file_merger.py +18 -13
  59. symai/extended/graph.py +18 -13
  60. symai/extended/html_style_template.py +2 -4
  61. symai/extended/interfaces/blip_2.py +1 -2
  62. symai/extended/interfaces/clip.py +1 -2
  63. symai/extended/interfaces/console.py +7 -1
  64. symai/extended/interfaces/dall_e.py +1 -1
  65. symai/extended/interfaces/flux.py +1 -1
  66. symai/extended/interfaces/gpt_image.py +1 -1
  67. symai/extended/interfaces/input.py +1 -1
  68. symai/extended/interfaces/llava.py +0 -1
  69. symai/extended/interfaces/naive_vectordb.py +7 -8
  70. symai/extended/interfaces/naive_webscraping.py +1 -1
  71. symai/extended/interfaces/ocr.py +1 -1
  72. symai/extended/interfaces/pinecone.py +6 -5
  73. symai/extended/interfaces/serpapi.py +1 -1
  74. symai/extended/interfaces/terminal.py +2 -3
  75. symai/extended/interfaces/tts.py +1 -1
  76. symai/extended/interfaces/whisper.py +1 -1
  77. symai/extended/interfaces/wolframalpha.py +1 -1
  78. symai/extended/metrics/__init__.py +11 -1
  79. symai/extended/metrics/similarity.py +11 -13
  80. symai/extended/os_command.py +17 -16
  81. symai/extended/packages/__init__.py +29 -3
  82. symai/extended/packages/symdev.py +19 -16
  83. symai/extended/packages/sympkg.py +12 -9
  84. symai/extended/packages/symrun.py +21 -19
  85. symai/extended/repo_cloner.py +11 -10
  86. symai/extended/seo_query_optimizer.py +1 -2
  87. symai/extended/solver.py +20 -23
  88. symai/extended/summarizer.py +4 -3
  89. symai/extended/taypan_interpreter.py +10 -12
  90. symai/extended/vectordb.py +99 -82
  91. symai/formatter/__init__.py +9 -1
  92. symai/formatter/formatter.py +12 -16
  93. symai/formatter/regex.py +62 -63
  94. symai/functional.py +176 -122
  95. symai/imports.py +136 -127
  96. symai/interfaces.py +56 -27
  97. symai/memory.py +14 -13
  98. symai/misc/console.py +49 -39
  99. symai/misc/loader.py +5 -3
  100. symai/models/__init__.py +17 -1
  101. symai/models/base.py +269 -181
  102. symai/models/errors.py +0 -1
  103. symai/ops/__init__.py +32 -22
  104. symai/ops/measures.py +11 -15
  105. symai/ops/primitives.py +348 -228
  106. symai/post_processors.py +32 -28
  107. symai/pre_processors.py +39 -41
  108. symai/processor.py +6 -4
  109. symai/prompts.py +59 -45
  110. symai/server/huggingface_server.py +23 -20
  111. symai/server/llama_cpp_server.py +7 -5
  112. symai/shell.py +3 -4
  113. symai/shellsv.py +499 -375
  114. symai/strategy.py +517 -287
  115. symai/symbol.py +111 -116
  116. symai/utils.py +42 -36
  117. {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/METADATA +4 -2
  118. symbolicai-1.0.0.dist-info/RECORD +163 -0
  119. symbolicai-0.20.2.dist-info/RECORD +0 -162
  120. {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/WHEEL +0 -0
  121. {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/entry_points.txt +0 -0
  122. {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/licenses/LICENSE +0 -0
  123. {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/top_level.txt +0 -0
symai/post_processors.py CHANGED
@@ -1,19 +1,21 @@
1
1
  import ast
2
2
  import re
3
- import numpy as np
4
-
5
3
  from collections import namedtuple
6
4
  from typing import Any
5
+
6
+ import numpy as np
7
7
  from sklearn.cluster import HDBSCAN
8
8
 
9
+ from .utils import UserMessage
10
+
9
11
 
10
12
  class PostProcessor:
11
13
  def __call__(self, response, argument) -> Any:
12
- raise NotImplementedError()
14
+ raise NotImplementedError
13
15
 
14
16
 
15
17
  class StripPostProcessor(PostProcessor):
16
- def __call__(self, response, argument) -> Any:
18
+ def __call__(self, response, _argument) -> Any:
17
19
  if response is None:
18
20
  return None
19
21
  if not isinstance(response, str):
@@ -53,17 +55,19 @@ class TemplatePostProcessor(PostProcessor):
53
55
 
54
56
 
55
57
  class SplitNewLinePostProcessor(PostProcessor):
56
- def __call__(self, response, argument) -> Any:
58
+ def __call__(self, response, _argument) -> Any:
57
59
  tmp = response.split('\n')
58
60
  return [t.strip() for t in tmp if len(t.strip()) > 0]
59
61
 
60
62
 
61
63
  class JsonTruncatePostProcessor(PostProcessor):
62
- def __call__(self, response, argument) -> Any:
64
+ def __call__(self, response, _argument) -> Any:
63
65
  count_b = response.count('[JSON_BEGIN]')
64
66
  count_e = response.count('[JSON_END]')
65
67
  if count_b > 1 or count_e > 1:
66
- raise ValueError("More than one [JSON_BEGIN] or [JSON_END] found. Please only generate one JSON response.")
68
+ msg = "More than one [JSON_BEGIN] or [JSON_END] found. Please only generate one JSON response."
69
+ UserMessage(msg)
70
+ raise ValueError(msg)
67
71
  # cut off everything until the first '{'
68
72
  start_idx = response.find('{')
69
73
  response = response[start_idx:]
@@ -80,11 +84,13 @@ class JsonTruncatePostProcessor(PostProcessor):
80
84
 
81
85
 
82
86
  class JsonTruncateMarkdownPostProcessor(PostProcessor):
83
- def __call__(self, response, argument) -> Any:
87
+ def __call__(self, response, _argument) -> Any:
84
88
  count_b = response.count('```json')
85
89
  count_e = response.count('```')
86
90
  if count_b > 1 or count_e > 2:
87
- raise ValueError("More than one ```json Markdown found. Please only generate one JSON response.")
91
+ msg = "More than one ```json Markdown found. Please only generate one JSON response."
92
+ UserMessage(msg)
93
+ raise ValueError(msg)
88
94
  # cut off everything until the first '{'
89
95
  start_idx = response.find('{')
90
96
  response = response[start_idx:]
@@ -101,7 +107,7 @@ class JsonTruncateMarkdownPostProcessor(PostProcessor):
101
107
 
102
108
 
103
109
  class CodeExtractPostProcessor(PostProcessor):
104
- def __call__(self, response, argument, tag=None, **kwargs) -> Any:
110
+ def __call__(self, response, _argument, tag=None, **_kwargs) -> Any:
105
111
  if '```' not in str(response):
106
112
  return response
107
113
  try:
@@ -110,15 +116,14 @@ class CodeExtractPostProcessor(PostProcessor):
110
116
  else:
111
117
  pattern = r'```(?:\w*\n)?' + re.escape(str(tag)) + r'\n(.*?)(?:```|$)'
112
118
  matches = re.findall(pattern, str(response), re.DOTALL)
113
- code = "\n".join(matches).strip()
114
- return code
119
+ return "\n".join(matches).strip()
115
120
  except Exception:
116
121
  # If any error occurs during processing, return the original response
117
122
  return response
118
123
 
119
124
 
120
125
  class WolframAlphaPostProcessor(PostProcessor):
121
- def __call__(self, response, argument) -> Any:
126
+ def __call__(self, response, _argument) -> Any:
122
127
  try:
123
128
  res = next(response.value.results).text
124
129
  response._value = res
@@ -135,10 +140,10 @@ class WolframAlphaPostProcessor(PostProcessor):
135
140
 
136
141
 
137
142
  class SplitPipePostProcessor(PostProcessor):
138
- def __call__(self, response, argument) -> Any:
143
+ def __call__(self, response, _argument) -> Any:
139
144
  tmp = response if isinstance(response, list) else [response]
140
145
  tmp = [r.split('|') for r in tmp if len(r.strip()) > 0]
141
- tmp = sum(tmp, [])
146
+ tmp = [item for group in tmp for item in group]
142
147
  return [t.strip() for t in tmp if len(t.strip()) > 0]
143
148
 
144
149
 
@@ -152,11 +157,11 @@ class NotifySubscriberPostProcessor(PostProcessor):
152
157
 
153
158
 
154
159
  class ASTPostProcessor(PostProcessor):
155
- def __call__(self, response, *args, **kwargs) -> Any:
160
+ def __call__(self, response, *_args, **_kwargs) -> Any:
156
161
  try:
157
162
  val = ast.literal_eval(response.strip())
158
163
  return self._recursive_parse(val)
159
- except:
164
+ except (ValueError, SyntaxError):
160
165
  return response
161
166
 
162
167
  def _recursive_parse(self, obj):
@@ -164,7 +169,7 @@ class ASTPostProcessor(PostProcessor):
164
169
  if isinstance(obj, str):
165
170
  try:
166
171
  return self._recursive_parse(ast.literal_eval(obj))
167
- except:
172
+ except (ValueError, SyntaxError):
168
173
  return obj
169
174
  elif isinstance(obj, list):
170
175
  return [self._recursive_parse(item) for item in obj]
@@ -181,32 +186,31 @@ class ASTPostProcessor(PostProcessor):
181
186
  class ConsolePostProcessor(PostProcessor):
182
187
  def __call__(self, response, argument) -> Any:
183
188
  verbose = argument.prop.verbose
184
- if verbose: print(f"Argument: {argument}")
189
+ if verbose:
190
+ UserMessage(f"Argument: {argument}")
185
191
  return response
186
192
 
187
193
 
188
194
  class TakeLastPostProcessor(PostProcessor):
189
- def __call__(self, response, argument) -> Any:
195
+ def __call__(self, response, _argument) -> Any:
190
196
  return response[-1]
191
197
 
192
198
 
193
199
  class ExpandFunctionPostProcessor(PostProcessor):
194
- def __call__(self, response, argument) -> Any:
200
+ def __call__(self, response, _argument) -> Any:
195
201
  return 'def ' + response
196
202
 
197
203
 
198
204
  class CaseInsensitivePostProcessor(PostProcessor):
199
- def __call__(self, response, argument) -> Any:
205
+ def __call__(self, response, _argument) -> Any:
200
206
  return str(response).lower()
201
207
 
202
208
  class ConfirmToBoolPostProcessor(PostProcessor):
203
- def __call__(self, response, argument) -> Any:
209
+ def __call__(self, response, _argument) -> Any:
204
210
  if response is None:
205
211
  return False
206
212
  rsp = response.strip()
207
- from .symbol import Symbol
213
+ # Lazy Symbol import prevents post_processors -> symbol -> core -> functional -> post_processors cycle.
214
+ from .symbol import Symbol # noqa
208
215
  sym = Symbol(rsp)
209
- if sym.isinstanceof('confirming answer'):
210
- return True
211
- else:
212
- return False
216
+ return bool(sym.isinstanceof('confirming answer'))
symai/pre_processors.py CHANGED
@@ -1,17 +1,17 @@
1
1
  import traceback
2
- from typing import Any, List, Optional
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"{str(argument.prop.prompt)}"
14
+ return f"{argument.prop.prompt!s}"
15
15
 
16
16
 
17
17
  class JsonPreProcessor(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} {str(comp)} {b} =>"
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 '|' in list_ and not '[' in list_:
94
+ if '|' in list_ and '[' not in list_:
95
95
  list_ = [v.strip() for v in list_.split('|') if len(v.strip()) > 0]
96
96
  list_ = str(list_)
97
- return f"order: '{str(order)}' measure: '{str(measure)}' list: {list_} =>"
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 '{str(argument.args[0])}' with '{str(argument.args[1])}'=>"
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 '{str(argument.args[0])}' =>"
109
+ return f"text '{argument.prop.instance}' include '{argument.args[0]!s}' =>"
110
110
 
111
111
 
112
112
  class CombinePreProcessor(PreProcessor):
@@ -168,7 +168,7 @@ class IsInstanceOfPreProcessor(PreProcessor):
168
168
  class ExtractPatternPreProcessor(PreProcessor):
169
169
  def __call__(self, argument) -> Any:
170
170
  assert len(argument.args) == 1
171
- return f"from '{str(argument.prop.instance)}' extract '{str(argument.args[0])}' =>"
171
+ return f"from '{argument.prop.instance!s}' extract '{argument.args[0]!s}' =>"
172
172
 
173
173
 
174
174
  class SimpleSymbolicExpressionPreProcessor(PreProcessor):
@@ -193,35 +193,35 @@ class SemanticMappingPreProcessor(PreProcessor):
193
193
  assert len(argument.args) >= 1
194
194
  topics = list(argument.prop.subscriber.keys())
195
195
  assert len(topics) > 0
196
- return f"topics {str(topics)} in\ntext: '{str(argument.args[0])}' =>"
196
+ return f"topics {topics!s} in\ntext: '{argument.args[0]!s}' =>"
197
197
 
198
198
 
199
199
  class SimulateCodePreProcessor(PreProcessor):
200
200
  def __call__(self, argument) -> Any:
201
201
  val = argument.args[0] if len(argument.args) > 0 else ''
202
- return f"code '{str(argument.prop.instance)}' params '{str(val)}' =>"
202
+ return f"code '{argument.prop.instance!s}' params '{val!s}' =>"
203
203
 
204
204
 
205
205
  class GenerateCodePreProcessor(PreProcessor):
206
206
  def __call__(self, argument) -> Any:
207
- return f"description '{str(argument.prop.instance)}' =>"
207
+ return f"description '{argument.prop.instance!s}' =>"
208
208
 
209
209
 
210
210
  class TextToOutlinePreProcessor(PreProcessor):
211
211
  def __call__(self, argument) -> Any:
212
- return f"text '{str(argument.prop.instance)}' =>"
212
+ return f"text '{argument.prop.instance!s}' =>"
213
213
 
214
214
 
215
215
  class UniquePreProcessor(PreProcessor):
216
216
  def __call__(self, argument) -> Any:
217
217
  unique = argument.prop.keys
218
218
  val = f'List of keys: {unique}\n'
219
- return f"{val}text '{str(argument.prop.instance)}' =>"
219
+ return f"{val}text '{argument.prop.instance!s}' =>"
220
220
 
221
221
 
222
222
  class GenerateTextPreProcessor(PreProcessor):
223
223
  def __call__(self, argument) -> Any:
224
- return f"{str(argument.prop.instance)}"
224
+ return f"{argument.prop.instance!s}"
225
225
 
226
226
 
227
227
  class ClusterPreProcessor(PreProcessor):
@@ -242,7 +242,7 @@ class MapPreProcessor(PreProcessor):
242
242
  def __call__(self, argument) -> Any:
243
243
  val = prep_as_str(argument.prop.instance)
244
244
  context = argument.prop.context
245
- return f"{val} map '{str(context)}' =>"
245
+ return f"{val} map '{context!s}' =>"
246
246
 
247
247
 
248
248
  class ListPreProcessor(PreProcessor):
@@ -254,7 +254,7 @@ class ListPreProcessor(PreProcessor):
254
254
 
255
255
  class QueryPreProcessor(PreProcessor):
256
256
  def __call__(self, argument) -> Any:
257
- val = f'Data:\n{str(argument.prop.instance)}\n'
257
+ val = f'Data:\n{argument.prop.instance!s}\n'
258
258
  query = f"Context: {argument.prop.context}\n"
259
259
  return f"{val}{query}Answer:"
260
260
 
@@ -285,14 +285,14 @@ class ArgsPreProcessor(PreProcessor):
285
285
  class ModifyPreProcessor(PreProcessor):
286
286
  def __call__(self, argument) -> Any:
287
287
  changes = argument.prop.changes
288
- return f"text '{str(argument.prop.instance)}' modify '{str(changes)}'=>"
288
+ return f"text '{argument.prop.instance!s}' modify '{changes!s}'=>"
289
289
 
290
290
 
291
291
  class FilterPreProcessor(PreProcessor):
292
292
  def __call__(self, argument) -> Any:
293
293
  criteria = argument.prop.criteria
294
294
  include = 'include' if argument.prop.include else 'remove'
295
- return f"text '{str(argument.prop.instance)}' {include} '{str(criteria)}' =>"
295
+ return f"text '{argument.prop.instance!s}' {include} '{criteria!s}' =>"
296
296
 
297
297
 
298
298
  class MapExpressionPreProcessor(PreProcessor):
@@ -303,7 +303,7 @@ class MapExpressionPreProcessor(PreProcessor):
303
303
 
304
304
 
305
305
  class ArgsToInputPreProcessor(PreProcessor):
306
- def __init__(self, skip: Optional[List[int]] = None) -> None:
306
+ def __init__(self, skip: list[int] | None = None) -> None:
307
307
  super().__init__()
308
308
  skip = [skip] if skip and isinstance(skip, int) else skip
309
309
  self.skip = skip if skip is not None else []
@@ -313,48 +313,46 @@ class ArgsToInputPreProcessor(PreProcessor):
313
313
  for i, arg in enumerate(argument.args):
314
314
  if i in self.skip:
315
315
  continue
316
- input_ += f"{str(arg)}\n"
316
+ input_ += f"{arg!s}\n"
317
317
  return input_
318
318
 
319
319
 
320
320
  class SelfToInputPreProcessor(PreProcessor):
321
- def __init__(self, skip: Optional[List[int]] = None) -> None:
321
+ def __init__(self, skip: list[int] | None = None) -> None:
322
322
  super().__init__()
323
323
  skip = [skip] if skip and isinstance(skip, int) else skip
324
324
  self.skip = skip if skip is not None else []
325
325
 
326
326
  def __call__(self, argument) -> Any:
327
- input_ = f'{str(argument.prop.instance)}\n'
328
- return input_
327
+ return f'{argument.prop.instance!s}\n'
329
328
 
330
329
 
331
330
  class DataTemplatePreProcessor(PreProcessor):
332
- def __init__(self, skip: Optional[List[int]] = None) -> None:
331
+ def __init__(self, skip: list[int] | None = None) -> None:
333
332
  super().__init__()
334
333
  self.skip = skip if skip is not None else []
335
334
 
336
335
  def __call__(self, argument) -> Any:
337
- input_ = f'[Data]:\n{str(argument.prop.instance)}\n'
336
+ input_ = f'[Data]:\n{argument.prop.instance!s}\n'
338
337
  for i, arg in enumerate(argument.args):
339
338
  if i in self.skip:
340
339
  continue
341
- input_ += f"{str(arg)}\n"
340
+ input_ += f"{arg!s}\n"
342
341
  return input_
343
342
 
344
343
 
345
344
  class ConsoleInputPreProcessor(PreProcessor):
346
- def __init__(self, skip: Optional[List[int]] = None) -> None:
345
+ def __init__(self, skip: list[int] | None = None) -> None:
347
346
  super().__init__()
348
347
  skip = [skip] if skip and isinstance(skip, int) else skip
349
348
  self.skip = skip if skip is not None else []
350
349
 
351
350
  def __call__(self, argument) -> Any:
352
- input_ = f'\n{str(argument.args[0])}\n$> '
353
- return input_
351
+ return f'\n{argument.args[0]!s}\n$> '
354
352
 
355
353
 
356
354
  class ConsolePreProcessor(PreProcessor):
357
- def __init__(self, skip: Optional[List[int]] = None) -> None:
355
+ def __init__(self, skip: list[int] | None = None) -> None:
358
356
  super().__init__()
359
357
  skip = [skip] if skip and isinstance(skip, int) else skip
360
358
  self.skip = skip if skip is not None else []
@@ -366,7 +364,7 @@ class ConsolePreProcessor(PreProcessor):
366
364
  symbol_obj = argument.prop.instance
367
365
  symbol_value = argument.args[0]
368
366
  method_args = argument.args[1:]
369
- object_ = f"symbol_value: {repr(symbol_value)}"
367
+ object_ = f"symbol_value: {symbol_value!r}"
370
368
 
371
369
  # kwargs passed at Symbol-construction time (e.g. test_kwarg=…)
372
370
  if symbol_obj._kwargs:
@@ -387,7 +385,7 @@ class LanguagePreProcessor(PreProcessor):
387
385
  def __call__(self, argument) -> Any:
388
386
  language = argument.prop.language
389
387
  argument.prop.prompt = argument.prop.prompt.format(language)
390
- return f"{str(argument.prop.instance)}"
388
+ return f"{argument.prop.instance!s}"
391
389
 
392
390
 
393
391
  class TextFormatPreProcessor(PreProcessor):
@@ -411,7 +409,7 @@ class StylePreProcessor(PreProcessor):
411
409
  text = f'[FORMAT]: {description}\n'
412
410
  libs = ', '.join(argument.prop.libraries)
413
411
  libraries = f"[LIBRARIES]: {libs}\n"
414
- content = f'[DATA]:\n{str(argument.prop.instance)}\n\n'
412
+ content = f'[DATA]:\n{argument.prop.instance!s}\n\n'
415
413
  if argument.prop.template:
416
414
  placeholder = argument.prop.placeholder
417
415
  template = argument.prop.template
@@ -466,30 +464,30 @@ class EnumPreProcessor(PreProcessor):
466
464
 
467
465
  class TextMessagePreProcessor(PreProcessor):
468
466
  def __call__(self, argument) -> Any:
469
- return f'Text: {str(argument.prop.instance)}\n'
467
+ return f'Text: {argument.prop.instance!s}\n'
470
468
 
471
469
 
472
470
  class SummaryPreProcessing(PreProcessor):
473
471
  def __call__(self, argument) -> Any:
474
472
  ctxt = f"Context: {argument.prop.context} " if argument.prop.context else ''
475
- return f'{ctxt}Text: {str(argument.prop.instance)}\n'
473
+ return f'{ctxt}Text: {argument.prop.instance!s}\n'
476
474
 
477
475
 
478
476
  class CleanTextMessagePreProcessor(PreProcessor):
479
477
  def __call__(self, argument) -> Any:
480
- return f"Text: '{str(argument.prop.instance)}' =>"
478
+ return f"Text: '{argument.prop.instance!s}' =>"
481
479
 
482
480
 
483
481
  class PredictionMessagePreProcessor(PreProcessor):
484
- def __call__(self, argument) -> Any:
485
- return f'Prediction:'
482
+ def __call__(self, _argument) -> Any:
483
+ return 'Prediction:'
486
484
 
487
485
 
488
486
  class ArrowMessagePreProcessor(PreProcessor):
489
487
  def __call__(self, argument) -> Any:
490
- return f'{str(argument.prop.instance)} =>'
488
+ return f'{argument.prop.instance!s} =>'
491
489
 
492
490
 
493
491
  class ValuePreProcessor(PreProcessor):
494
492
  def __call__(self, argument) -> Any:
495
- return f'{str(argument.prop.instance)}'
493
+ return f'{argument.prop.instance!s}'
symai/processor.py CHANGED
@@ -1,6 +1,7 @@
1
- from typing import Any, Optional, List, Union
2
- from .pre_processors import PreProcessor
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:
@@ -11,7 +12,7 @@ class ProcessorPipeline:
11
12
  processors: A list of processors to be applied to the response.
12
13
  '''
13
14
 
14
- def __init__(self, processors: Optional[List[Union[PreProcessor, PostProcessor]]] = None) -> None:
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:
@@ -28,10 +29,11 @@ class ProcessorPipeline:
28
29
  processed_input += t if t is not None else ''
29
30
  return processed_input
30
31
 
31
- elif isinstance(self.processors[0], PostProcessor):
32
+ if isinstance(self.processors[0], PostProcessor):
32
33
  assert len(args) == 2, f"Expected 2 arguments of type Response and Argument, got {len(args)}"
33
34
  response, argument = args
34
35
  for processor in self.processors:
35
36
  assert isinstance(processor, PostProcessor), f"Expected PostProcessor, got {type(processor)}"
36
37
  response = processor(response, argument, **kwds)
37
38
  return response
39
+ return None