symbolicai 0.21.0__py3-none-any.whl → 1.1.0__py3-none-any.whl

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