symbolicai 1.0.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 (127) hide show
  1. symai/__init__.py +198 -134
  2. symai/backend/base.py +51 -51
  3. symai/backend/engines/drawing/engine_bfl.py +33 -33
  4. symai/backend/engines/drawing/engine_gpt_image.py +4 -10
  5. symai/backend/engines/embedding/engine_llama_cpp.py +50 -35
  6. symai/backend/engines/embedding/engine_openai.py +22 -16
  7. symai/backend/engines/execute/engine_python.py +16 -16
  8. symai/backend/engines/files/engine_io.py +51 -49
  9. symai/backend/engines/imagecaptioning/engine_blip2.py +27 -23
  10. symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +53 -46
  11. symai/backend/engines/index/engine_pinecone.py +116 -88
  12. symai/backend/engines/index/engine_qdrant.py +1011 -0
  13. symai/backend/engines/index/engine_vectordb.py +78 -52
  14. symai/backend/engines/lean/engine_lean4.py +65 -25
  15. symai/backend/engines/neurosymbolic/__init__.py +28 -28
  16. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +137 -135
  17. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +145 -152
  18. symai/backend/engines/neurosymbolic/engine_cerebras.py +328 -0
  19. symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +75 -49
  20. symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +199 -155
  21. symai/backend/engines/neurosymbolic/engine_groq.py +106 -72
  22. symai/backend/engines/neurosymbolic/engine_huggingface.py +100 -67
  23. symai/backend/engines/neurosymbolic/engine_llama_cpp.py +121 -93
  24. symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +213 -132
  25. symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +180 -137
  26. symai/backend/engines/ocr/engine_apilayer.py +18 -20
  27. symai/backend/engines/output/engine_stdout.py +9 -9
  28. symai/backend/engines/{webscraping → scrape}/engine_requests.py +25 -11
  29. symai/backend/engines/search/engine_openai.py +95 -83
  30. symai/backend/engines/search/engine_parallel.py +665 -0
  31. symai/backend/engines/search/engine_perplexity.py +40 -41
  32. symai/backend/engines/search/engine_serpapi.py +33 -28
  33. symai/backend/engines/speech_to_text/engine_local_whisper.py +37 -27
  34. symai/backend/engines/symbolic/engine_wolframalpha.py +14 -8
  35. symai/backend/engines/text_to_speech/engine_openai.py +15 -19
  36. symai/backend/engines/text_vision/engine_clip.py +34 -28
  37. symai/backend/engines/userinput/engine_console.py +3 -4
  38. symai/backend/mixin/anthropic.py +48 -40
  39. symai/backend/mixin/deepseek.py +4 -5
  40. symai/backend/mixin/google.py +5 -4
  41. symai/backend/mixin/groq.py +2 -4
  42. symai/backend/mixin/openai.py +132 -110
  43. symai/backend/settings.py +14 -14
  44. symai/chat.py +164 -94
  45. symai/collect/dynamic.py +13 -11
  46. symai/collect/pipeline.py +39 -31
  47. symai/collect/stats.py +109 -69
  48. symai/components.py +556 -238
  49. symai/constraints.py +14 -5
  50. symai/core.py +1495 -1210
  51. symai/core_ext.py +55 -50
  52. symai/endpoints/api.py +113 -58
  53. symai/extended/api_builder.py +22 -17
  54. symai/extended/arxiv_pdf_parser.py +13 -5
  55. symai/extended/bibtex_parser.py +8 -4
  56. symai/extended/conversation.py +88 -69
  57. symai/extended/document.py +40 -27
  58. symai/extended/file_merger.py +45 -7
  59. symai/extended/graph.py +38 -24
  60. symai/extended/html_style_template.py +17 -11
  61. symai/extended/interfaces/blip_2.py +1 -1
  62. symai/extended/interfaces/clip.py +4 -2
  63. symai/extended/interfaces/console.py +5 -3
  64. symai/extended/interfaces/dall_e.py +3 -1
  65. symai/extended/interfaces/file.py +2 -0
  66. symai/extended/interfaces/flux.py +3 -1
  67. symai/extended/interfaces/gpt_image.py +15 -6
  68. symai/extended/interfaces/input.py +2 -1
  69. symai/extended/interfaces/llava.py +1 -1
  70. symai/extended/interfaces/{naive_webscraping.py → naive_scrape.py} +3 -2
  71. symai/extended/interfaces/naive_vectordb.py +2 -2
  72. symai/extended/interfaces/ocr.py +4 -2
  73. symai/extended/interfaces/openai_search.py +2 -0
  74. symai/extended/interfaces/parallel.py +30 -0
  75. symai/extended/interfaces/perplexity.py +2 -0
  76. symai/extended/interfaces/pinecone.py +6 -4
  77. symai/extended/interfaces/python.py +2 -0
  78. symai/extended/interfaces/serpapi.py +2 -0
  79. symai/extended/interfaces/terminal.py +0 -1
  80. symai/extended/interfaces/tts.py +2 -1
  81. symai/extended/interfaces/whisper.py +2 -1
  82. symai/extended/interfaces/wolframalpha.py +1 -0
  83. symai/extended/metrics/__init__.py +1 -1
  84. symai/extended/metrics/similarity.py +5 -2
  85. symai/extended/os_command.py +31 -22
  86. symai/extended/packages/symdev.py +39 -34
  87. symai/extended/packages/sympkg.py +30 -27
  88. symai/extended/packages/symrun.py +46 -35
  89. symai/extended/repo_cloner.py +10 -9
  90. symai/extended/seo_query_optimizer.py +15 -12
  91. symai/extended/solver.py +104 -76
  92. symai/extended/summarizer.py +8 -7
  93. symai/extended/taypan_interpreter.py +10 -9
  94. symai/extended/vectordb.py +28 -15
  95. symai/formatter/formatter.py +39 -31
  96. symai/formatter/regex.py +46 -44
  97. symai/functional.py +184 -86
  98. symai/imports.py +85 -51
  99. symai/interfaces.py +1 -1
  100. symai/memory.py +33 -24
  101. symai/menu/screen.py +28 -19
  102. symai/misc/console.py +27 -27
  103. symai/misc/loader.py +4 -3
  104. symai/models/base.py +147 -76
  105. symai/models/errors.py +1 -1
  106. symai/ops/__init__.py +1 -1
  107. symai/ops/measures.py +17 -14
  108. symai/ops/primitives.py +933 -635
  109. symai/post_processors.py +28 -24
  110. symai/pre_processors.py +58 -52
  111. symai/processor.py +15 -9
  112. symai/prompts.py +714 -649
  113. symai/server/huggingface_server.py +115 -32
  114. symai/server/llama_cpp_server.py +14 -6
  115. symai/server/qdrant_server.py +206 -0
  116. symai/shell.py +98 -39
  117. symai/shellsv.py +307 -223
  118. symai/strategy.py +135 -81
  119. symai/symbol.py +276 -225
  120. symai/utils.py +62 -46
  121. {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/METADATA +19 -9
  122. symbolicai-1.1.0.dist-info/RECORD +168 -0
  123. symbolicai-1.0.0.dist-info/RECORD +0 -163
  124. {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/WHEEL +0 -0
  125. {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/entry_points.txt +0 -0
  126. {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/licenses/LICENSE +0 -0
  127. {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/top_level.txt +0 -0
symai/extended/graph.py CHANGED
@@ -21,7 +21,7 @@ If more than one entity pair is extracted from the same sentence, then the CSV f
21
21
 
22
22
  class GraphPreProcessor(PreProcessor):
23
23
  def __call__(self, argument):
24
- return f'$> {argument.args[0]!s} =>'
24
+ return f"$> {argument.args[0]!s} =>"
25
25
 
26
26
 
27
27
  class Graph(Expression):
@@ -29,26 +29,37 @@ class Graph(Expression):
29
29
  def static_context(self) -> str:
30
30
  return GRAPH_DESCRIPTION
31
31
 
32
- def __init__(self, formatter: Callable = _DEFAULT_SENTENCE_FORMATTER, n_workers: int = 1, verbose: bool = False, **kwargs):
32
+ def __init__(
33
+ self,
34
+ formatter: Callable = _DEFAULT_SENTENCE_FORMATTER,
35
+ n_workers: int = 1,
36
+ verbose: bool = False,
37
+ **kwargs,
38
+ ):
33
39
  super().__init__(**kwargs)
34
- self.formatter = formatter
35
- self.n_workers = n_workers
40
+ self.formatter = formatter
41
+ self.n_workers = n_workers
36
42
  self.sym_return_type = Graph
37
- self.verbose = verbose
43
+ self.verbose = verbose
38
44
 
39
45
  def process_symbol(self, s, *_args, **kwargs):
40
- res = ''
46
+ res = ""
41
47
 
42
- @core.few_shot(prompt="Extract relationships between entities:\n",
43
- examples=Prompt([
44
- '$> John has a dog. =>John, dog, 1 EOF',
45
- '$> Karl has two sons. =>Karl, sons, 2 EOF',
46
- '$> Similarly, the term general linguistics is used to distinguish core linguistics from other types of study =>general linguistics, core linguistics, 1 EOF',
47
- '$> X has Y and Z has Y =>X, Y, 1\nZ, Y, 1 EOF',
48
- ]),
49
- pre_processors=[GraphPreProcessor()],
50
- post_processors=[StripPostProcessor()],
51
- stop=['EOF'], **kwargs)
48
+ @core.few_shot(
49
+ prompt="Extract relationships between entities:\n",
50
+ examples=Prompt(
51
+ [
52
+ "$> John has a dog. =>John, dog, 1 EOF",
53
+ "$> Karl has two sons. =>Karl, sons, 2 EOF",
54
+ "$> Similarly, the term general linguistics is used to distinguish core linguistics from other types of study =>general linguistics, core linguistics, 1 EOF",
55
+ "$> X has Y and Z has Y =>X, Y, 1\nZ, Y, 1 EOF",
56
+ ]
57
+ ),
58
+ pre_processors=[GraphPreProcessor()],
59
+ post_processors=[StripPostProcessor()],
60
+ stop=["EOF"],
61
+ **kwargs,
62
+ )
52
63
  def _func(_, text) -> str:
53
64
  pass
54
65
 
@@ -57,17 +68,19 @@ class Graph(Expression):
57
68
  UserMessage(str(s))
58
69
  r = _func(self, s)
59
70
  rec = str(r)
60
- lines = rec.split('\n')
71
+ lines = rec.split("\n")
61
72
  for line in lines:
62
73
  stripped_line = line.strip()
63
74
  if len(stripped_line) > 0:
64
- csv = stripped_line.split(',')
75
+ csv = stripped_line.split(",")
65
76
  try:
66
- if len(csv) == 3 and \
67
- csv[0].strip() != '' and \
68
- csv[1].strip() != '' and \
69
- int(csv[2].strip()) > 0:
70
- res += stripped_line + '\n'
77
+ if (
78
+ len(csv) == 3
79
+ and csv[0].strip() != ""
80
+ and csv[1].strip() != ""
81
+ and int(csv[2].strip()) > 0
82
+ ):
83
+ res += stripped_line + "\n"
71
84
  except Exception as e:
72
85
  if self.verbose:
73
86
  UserMessage(str(e))
@@ -75,7 +88,7 @@ class Graph(Expression):
75
88
  return res
76
89
 
77
90
  def forward(self, sym: Symbol, **_kwargs) -> Symbol:
78
- res = 'source,target,value\n'
91
+ res = "source,target,value\n"
79
92
  sym_list = self.formatter(sym).value
80
93
  if self.n_workers == 1:
81
94
  for s in sym_list:
@@ -87,4 +100,5 @@ class Graph(Expression):
87
100
  res += r
88
101
  return res
89
102
 
103
+
90
104
  _DEFAULT_SENTENCE_FORMATTER = SentenceFormatter()
@@ -61,13 +61,15 @@ class HtmlStyleTemplate(Expression):
61
61
  super().__init__(**kwargs)
62
62
  self.html_template_seq = Template()
63
63
  self.html_template_seq.template_ = HEADER_STYLE_DESCRIPTION
64
- self.html_stream = Stream(
65
- self.html_template_seq
64
+ self.html_stream = Stream(self.html_template_seq)
65
+ self.style_template = Style(
66
+ description=HTML_STREAM_STYLE_DESCRIPTION,
67
+ libraries=[
68
+ "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css",
69
+ "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js",
70
+ "https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js",
71
+ ],
66
72
  )
67
- self.style_template = Style(description=HTML_STREAM_STYLE_DESCRIPTION,
68
- libraries=['https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css',
69
- 'https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js',
70
- 'https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js'])
71
73
 
72
74
  def forward(self, sym: Symbol, **kwargs) -> Symbol:
73
75
  """The `render` method takes a `Symbol` as an argument and returns a `Symbol` containing the rendered news.
@@ -79,8 +81,12 @@ class HtmlStyleTemplate(Expression):
79
81
  if not isinstance(sym, Symbol):
80
82
  sym = Symbol(sym)
81
83
  html_data = list(self.html_stream(sym, **kwargs))
82
- style_data = [str(self.style_template(html,
83
- template=HTML_TEMPLATE_STYLE,
84
- placeholder='{{placeholder}}',
85
- **kwargs)) for html in html_data]
86
- return Symbol('\n'.join(style_data))
84
+ style_data = [
85
+ str(
86
+ self.style_template(
87
+ html, template=HTML_TEMPLATE_STYLE, placeholder="{{placeholder}}", **kwargs
88
+ )
89
+ )
90
+ for html in html_data
91
+ ]
92
+ return Symbol("\n".join(style_data))
@@ -1,4 +1,3 @@
1
-
2
1
  from ... import core
3
2
  from ...symbol import Expression
4
3
 
@@ -12,4 +11,5 @@ class blip_2(Expression):
12
11
  @core.caption(image=image, prompt=query, **kwargs)
13
12
  def _func(_) -> str:
14
13
  pass
14
+
15
15
  return self.sym_return_type(_func(self))
@@ -1,4 +1,3 @@
1
-
2
1
  import numpy as np
3
2
 
4
3
  from ... import core
@@ -10,8 +9,11 @@ class clip(Expression):
10
9
  super().__init__(*args, **kwargs)
11
10
  self.name = self.__class__.__name__
12
11
 
13
- def __call__(self, image: str | bytes | None = None, text: list[str] | None = None, **kwargs) -> "clip":
12
+ def __call__(
13
+ self, image: str | bytes | None = None, text: list[str] | None = None, **kwargs
14
+ ) -> "clip":
14
15
  @core.text_vision(image=image, text=text, **kwargs)
15
16
  def _func(_) -> np.ndarray:
16
17
  pass
18
+
17
19
  return self.sym_return_type(_func(self))
@@ -10,12 +10,14 @@ class console(Expression):
10
10
 
11
11
  def __call__(self, *args, **kwargs) -> "console":
12
12
  def _handler(payload):
13
- args_ = payload.get('args', ())
14
- message = ' '.join(str(arg) for arg in args_)
13
+ args_ = payload.get("args", ())
14
+ message = " ".join(str(arg) for arg in args_)
15
15
  UserMessage(message)
16
16
 
17
- kwargs['handler'] = _handler
17
+ kwargs["handler"] = _handler
18
+
18
19
  @core.output(**kwargs)
19
20
  def _func(_, *args):
20
21
  pass
22
+
21
23
  return self.sym_return_type(_func(self, *args))
@@ -8,9 +8,11 @@ class dall_e(Expression):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.name = self.__class__.__name__
10
10
 
11
- def __call__(self, sym: Symbol, operation: str = 'create', **kwargs) -> GPTImageResult:
11
+ def __call__(self, sym: Symbol, operation: str = "create", **kwargs) -> GPTImageResult:
12
12
  sym = self._to_symbol(sym)
13
+
13
14
  @core.draw(operation=operation, **kwargs)
14
15
  def _func(_) -> GPTImageResult:
15
16
  pass
17
+
16
18
  return _func(sym)
@@ -9,7 +9,9 @@ class file(Expression):
9
9
 
10
10
  def __call__(self, path: Symbol, **kwargs) -> "file":
11
11
  path = self._to_symbol(path)
12
+
12
13
  @core.opening(path=path.value, **kwargs)
13
14
  def _func(_) -> str:
14
15
  pass
16
+
15
17
  return self.sym_return_type(_func(self))
@@ -8,9 +8,11 @@ class flux(Expression):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.name = self.__class__.__name__
10
10
 
11
- def __call__(self, prompt: str, operation: str = 'create', **kwargs) -> FluxResult:
11
+ def __call__(self, prompt: str, operation: str = "create", **kwargs) -> FluxResult:
12
12
  prompt = self._to_symbol(prompt)
13
+
13
14
  @core.draw(operation=operation, **kwargs)
14
15
  def _func(_) -> FluxResult:
15
16
  pass
17
+
16
18
  return _func(prompt)
@@ -8,9 +8,18 @@ class gpt_image(Expression):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.name = self.__class__.__name__
10
10
 
11
- def __call__(self, prompt: str | None = None, operation: str = 'create', engine: str | None = None, model: str | None = None, **kwargs) -> GPTImageResult:
12
- prompt = self._to_symbol(prompt)
13
- @core.draw(engine=engine or "drawing", operation=operation, model=model, **kwargs)
14
- def _func(_) -> GPTImageResult:
15
- pass
16
- return _func(prompt)
11
+ def __call__(
12
+ self,
13
+ prompt: str | None = None,
14
+ operation: str = "create",
15
+ engine: str | None = None,
16
+ model: str | None = None,
17
+ **kwargs,
18
+ ) -> GPTImageResult:
19
+ prompt = self._to_symbol(prompt)
20
+
21
+ @core.draw(engine=engine or "drawing", operation=operation, model=model, **kwargs)
22
+ def _func(_) -> GPTImageResult:
23
+ pass
24
+
25
+ return _func(prompt)
@@ -2,7 +2,7 @@ from ... import core
2
2
  from ...symbol import Expression
3
3
 
4
4
 
5
- class input(Expression): # noqa
5
+ class input(Expression): # noqa
6
6
  def __init__(self, *args, **kwargs):
7
7
  super().__init__(*args, **kwargs)
8
8
  self.name = self.__class__.__name__
@@ -11,4 +11,5 @@ class input(Expression): # noqa
11
11
  @core.userinput(**kwargs)
12
12
  def _func(_, message) -> str:
13
13
  pass
14
+
14
15
  return self.sym_return_type(_func(self, message))
@@ -1,4 +1,3 @@
1
-
2
1
  from ... import core
3
2
  from ...symbol import Expression
4
3
 
@@ -12,4 +11,5 @@ class llava(Expression):
12
11
  @core.caption(image=image, prompt=query, **kwargs)
13
12
  def _func(_) -> str:
14
13
  pass
14
+
15
15
  return self.sym_return_type(_func(self))
@@ -1,9 +1,9 @@
1
1
  from ... import core
2
- from ...backend.engines.webscraping.engine_requests import RequestsResult
2
+ from ...backend.engines.scrape.engine_requests import RequestsResult
3
3
  from ...symbol import Expression
4
4
 
5
5
 
6
- class naive_webscraping(Expression):
6
+ class naive_scrape(Expression):
7
7
  def __init__(self, *args, **kwargs):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.name = self.__class__.__name__
@@ -14,4 +14,5 @@ class naive_webscraping(Expression):
14
14
  # The fallback path may inject debugging kwargs like `error`/`stack_trace`;
15
15
  # accept and ignore them so EngineRepository can surface structured failures.
16
16
  return None
17
+
17
18
  return _func(self)
@@ -4,7 +4,7 @@ from ...utils import UserMessage
4
4
 
5
5
 
6
6
  class naive_vectordb(Expression):
7
- def __init__(self, index_name = VectorDBIndexEngine._default_index_name, *args, **kwargs):
7
+ def __init__(self, index_name=VectorDBIndexEngine._default_index_name, *args, **kwargs):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.index_name = index_name
10
10
  self.name = self.__class__.__name__
@@ -15,7 +15,7 @@ class naive_vectordb(Expression):
15
15
  operation: str = "search",
16
16
  index_name: str | None = None,
17
17
  storage_file: str | None = None,
18
- **kwargs
18
+ **kwargs,
19
19
  ) -> VectorDBResult:
20
20
  index = self.index_name if index_name is None else index_name
21
21
  if operation == "search":
@@ -9,9 +9,11 @@ class ocr(Expression):
9
9
  self.name = self.__class__.__name__
10
10
 
11
11
  def __call__(self, image_url: str, **kwargs) -> ApiLayerResult:
12
- if not image_url.startswith('http'):
13
- image_url = f'file://{image_url}'
12
+ if not image_url.startswith("http"):
13
+ image_url = f"file://{image_url}"
14
+
14
15
  @core.ocr(image=image_url, **kwargs)
15
16
  def _func(_) -> ApiLayerResult:
16
17
  pass
18
+
17
19
  return _func(self)
@@ -10,7 +10,9 @@ class openai_search(Expression):
10
10
 
11
11
  def __call__(self, query: Symbol, **kwargs) -> SearchResult:
12
12
  query = self._to_symbol(query)
13
+
13
14
  @core.search(query=query.value, **kwargs)
14
15
  def _func(_) -> SearchResult:
15
16
  pass
17
+
16
18
  return _func(self)
@@ -0,0 +1,30 @@
1
+ from ... import core
2
+ from ...backend.engines.search.engine_parallel import ExtractResult, SearchResult
3
+ from ...symbol import Expression, Symbol
4
+
5
+
6
+ class parallel(Expression):
7
+ def __init__(self, *args, **kwargs):
8
+ super().__init__(*args, **kwargs)
9
+ self.name = self.__class__.__name__
10
+
11
+ def search(self, query: Symbol, **kwargs) -> SearchResult:
12
+ query = self._to_symbol(query)
13
+
14
+ @core.search(query=query.value, **kwargs)
15
+ def _func(_) -> SearchResult:
16
+ pass
17
+
18
+ return _func(self)
19
+
20
+ def scrape(self, url: str, **kwargs) -> ExtractResult:
21
+ symbol = self._to_symbol(url)
22
+ options = dict(kwargs)
23
+ options.pop("query", None)
24
+ options["url"] = symbol.value
25
+
26
+ @core.search(query="", **options)
27
+ def _func(_, *_args, **_inner_kwargs) -> ExtractResult:
28
+ return None
29
+
30
+ return _func(self)
@@ -10,7 +10,9 @@ class perplexity(Expression):
10
10
 
11
11
  def __call__(self, query: Symbol, **kwargs) -> SearchResult:
12
12
  query = self._to_symbol(query)
13
+
13
14
  @core.search(query=query.value, **kwargs)
14
15
  def _func(_) -> SearchResult:
15
16
  pass
17
+
16
18
  return _func(self)
@@ -4,15 +4,17 @@ from ...utils import UserMessage
4
4
 
5
5
 
6
6
  class pinecone(Expression):
7
- def __init__(self, index_name = PineconeIndexEngine._default_index_name, *args, **kwargs):
7
+ def __init__(self, index_name=PineconeIndexEngine._default_index_name, *args, **kwargs):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.index_name = index_name
10
10
  self.name = self.__class__.__name__
11
11
 
12
- def __call__(self, stmt: str, operation: str = "search", index_name = None, **kwargs) -> PineconeResult:
13
- stmt = self._to_symbol(stmt)
12
+ def __call__(
13
+ self, stmt: str, operation: str = "search", index_name=None, **kwargs
14
+ ) -> PineconeResult:
15
+ stmt = self._to_symbol(stmt)
14
16
  index = self.index_name if index_name is None else index_name
15
- if operation == "search":
17
+ if operation == "search":
16
18
  return self.get(query=stmt.embedding, index_name=index, ori_query=stmt.value, **kwargs)
17
19
  if operation == "add":
18
20
  return self.add(doc=stmt.zip(), index_name=index, **kwargs)
@@ -9,7 +9,9 @@ class python(Expression):
9
9
 
10
10
  def __call__(self, expr: str, **kwargs) -> Result:
11
11
  sym = self._to_symbol(expr)
12
+
12
13
  @core.execute(**kwargs)
13
14
  def _func(_) -> Result:
14
15
  pass
16
+
15
17
  return _func(sym)
@@ -10,7 +10,9 @@ class serpapi(Expression):
10
10
 
11
11
  def __call__(self, query: Symbol, **kwargs) -> SearchResult:
12
12
  query = self._to_symbol(query)
13
+
13
14
  @core.search(query=query.value, **kwargs)
14
15
  def _func(_) -> SearchResult:
15
16
  pass
17
+
16
18
  return _func(self)
@@ -1,4 +1,3 @@
1
-
2
1
  from ...shellsv import process_command
3
2
  from ...symbol import Expression
4
3
 
@@ -7,8 +7,9 @@ class tts(Expression):
7
7
  super().__init__(*args, **kwargs)
8
8
  self.name = self.__class__.__name__
9
9
 
10
- def __call__(self, prompt: Symbol, path: str, voice: str = 'nova', **kwargs) -> Result:
10
+ def __call__(self, prompt: Symbol, path: str, voice: str = "nova", **kwargs) -> Result:
11
11
  @core.text_to_speech(prompt=str(prompt), path=path, voice=voice, **kwargs)
12
12
  def _func(_) -> Result:
13
13
  pass
14
+
14
15
  return _func(self)
@@ -8,8 +8,9 @@ class whisper(Expression):
8
8
  super().__init__(*args, **kwargs)
9
9
  self.name = self.__class__.__name__
10
10
 
11
- def __call__(self, audio_path: str, operation: str = 'decode', **kwargs) -> WhisperResult:
11
+ def __call__(self, audio_path: str, operation: str = "decode", **kwargs) -> WhisperResult:
12
12
  @core.speech_to_text(audio=audio_path, prompt=operation, **kwargs)
13
13
  def _func(_) -> WhisperResult:
14
14
  pass
15
+
15
16
  return _func(self)
@@ -12,4 +12,5 @@ class wolframalpha(Expression):
12
12
  @core.expression(**kwargs)
13
13
  def _func(_, expr: str) -> WolframResult:
14
14
  pass
15
+
15
16
  return _func(self, expr)
@@ -1,6 +1,6 @@
1
1
  from . import similarity as _similarity
2
2
 
3
- __all__ = getattr(_similarity, "__all__", None) # noqa
3
+ __all__ = getattr(_similarity, "__all__", None) # noqa
4
4
  if __all__ is None:
5
5
  __all__ = [name for name in dir(_similarity) if not name.startswith("_")]
6
6
 
@@ -1,6 +1,7 @@
1
- '''
1
+ """
2
2
  @TODO: This must go away. As soon as we have Qdrant, everything related to vectordb must be cleaned up.
3
- '''
3
+ """
4
+
4
5
  import random
5
6
 
6
7
  import numpy as np
@@ -60,6 +61,7 @@ def derridaean_similarity(vectors, query_vector):
60
61
  :param query_vector: vector
61
62
  :return: derridaean similarity between the vector and the matrix of vectors
62
63
  """
64
+
63
65
  def random_change(value):
64
66
  return value + random.uniform(-0.2, 0.2)
65
67
 
@@ -74,6 +76,7 @@ def adams_similarity(vectors, query_vector):
74
76
  :param query_vector: vector
75
77
  :return: adams similarity between the vector and the matrix of vectors
76
78
  """
79
+
77
80
  def adams_change(_value):
78
81
  return 0.42
79
82
 
@@ -61,43 +61,52 @@ Write an executable command that starts a process according to the user query, p
61
61
 
62
62
 
63
63
  class OSCommand(Expression):
64
- def __init__(self, programs: list[str],
65
- metadata: dict[str, str] | None = None,
66
- verbose: bool = False,
67
- os_platform: str = 'auto',
68
- **kwargs):
64
+ def __init__(
65
+ self,
66
+ programs: list[str],
67
+ metadata: dict[str, str] | None = None,
68
+ verbose: bool = False,
69
+ os_platform: str = "auto",
70
+ **kwargs,
71
+ ):
69
72
  if metadata is None:
70
73
  metadata = {}
71
74
  super().__init__(**kwargs)
72
- self.verbose: bool = verbose
73
- self.os_platform: str = os_platform
74
- self.programs: list[str] = programs
75
- self.meta: dict[str, str] = metadata
75
+ self.verbose: bool = verbose
76
+ self.os_platform: str = os_platform
77
+ self.programs: list[str] = programs
78
+ self.meta: dict[str, str] = metadata
76
79
 
77
- if self.os_platform == 'auto':
80
+ if self.os_platform == "auto":
78
81
  self.os_platform = platform.platform()
79
82
  if len(programs) == 0:
80
- UserMessage('No programs specified!', raise_with=Exception)
83
+ UserMessage("No programs specified!", raise_with=Exception)
81
84
 
82
85
  def execute_os_command(self, *args, **_kwargs):
83
86
  command = args[0]
84
- UserMessage(f'Executing {self.os_platform} command: {command}')
85
- if 'linux' in self.os_platform.lower():
87
+ UserMessage(f"Executing {self.os_platform} command: {command}")
88
+ if "linux" in self.os_platform.lower():
86
89
  return [subprocess.run(["bash", "-c", str(command)], check=False)]
87
- if 'windows' in self.os_platform.lower():
90
+ if "windows" in self.os_platform.lower():
88
91
  return [subprocess.run(["powershell", "-Command", str(command)], check=False)]
89
- if 'mac' in self.os_platform.lower():
92
+ if "mac" in self.os_platform.lower():
90
93
  return [subprocess.run(["bash", "-c", str(command)], check=False)]
91
- UserMessage('Unsupported platform!', raise_with=Exception)
94
+ UserMessage("Unsupported platform!", raise_with=Exception)
92
95
  return []
93
96
 
94
97
  def forward(self, sym: Symbol, **kwargs) -> Expression:
95
98
  sym = self._to_symbol(sym)
96
- kwargs['verbose'] = self.verbose
99
+ kwargs["verbose"] = self.verbose
97
100
 
98
- prompt = Context.format(programs=self.programs,
99
- platform=self.os_platform,
100
- query=sym,
101
- metadata=self.meta)
101
+ prompt = Context.format(
102
+ programs=self.programs, platform=self.os_platform, query=sym, metadata=self.meta
103
+ )
102
104
  command = sym.query(prompt, post_processors=[CodeExtractPostProcessor()], **kwargs)
103
- return self.sym_return_type(self.output(expr=self.execute_os_command, raw_input=True, processed_input=command.value, **kwargs))
105
+ return self.sym_return_type(
106
+ self.output(
107
+ expr=self.execute_os_command,
108
+ raw_input=True,
109
+ processed_input=command.value,
110
+ **kwargs,
111
+ )
112
+ )