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