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.
- symai/__init__.py +198 -134
- symai/backend/base.py +51 -51
- symai/backend/engines/drawing/engine_bfl.py +33 -33
- symai/backend/engines/drawing/engine_gpt_image.py +4 -10
- symai/backend/engines/embedding/engine_llama_cpp.py +50 -35
- symai/backend/engines/embedding/engine_openai.py +22 -16
- symai/backend/engines/execute/engine_python.py +16 -16
- symai/backend/engines/files/engine_io.py +51 -49
- symai/backend/engines/imagecaptioning/engine_blip2.py +27 -23
- symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +53 -46
- symai/backend/engines/index/engine_pinecone.py +116 -88
- symai/backend/engines/index/engine_qdrant.py +1011 -0
- symai/backend/engines/index/engine_vectordb.py +78 -52
- symai/backend/engines/lean/engine_lean4.py +65 -25
- symai/backend/engines/neurosymbolic/__init__.py +28 -28
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +137 -135
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +145 -152
- symai/backend/engines/neurosymbolic/engine_cerebras.py +328 -0
- symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +75 -49
- symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +199 -155
- symai/backend/engines/neurosymbolic/engine_groq.py +106 -72
- symai/backend/engines/neurosymbolic/engine_huggingface.py +100 -67
- symai/backend/engines/neurosymbolic/engine_llama_cpp.py +121 -93
- symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +213 -132
- symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +180 -137
- symai/backend/engines/ocr/engine_apilayer.py +18 -20
- symai/backend/engines/output/engine_stdout.py +9 -9
- symai/backend/engines/{webscraping → scrape}/engine_requests.py +25 -11
- symai/backend/engines/search/engine_openai.py +95 -83
- symai/backend/engines/search/engine_parallel.py +665 -0
- symai/backend/engines/search/engine_perplexity.py +40 -41
- symai/backend/engines/search/engine_serpapi.py +33 -28
- symai/backend/engines/speech_to_text/engine_local_whisper.py +37 -27
- symai/backend/engines/symbolic/engine_wolframalpha.py +14 -8
- symai/backend/engines/text_to_speech/engine_openai.py +15 -19
- symai/backend/engines/text_vision/engine_clip.py +34 -28
- symai/backend/engines/userinput/engine_console.py +3 -4
- symai/backend/mixin/anthropic.py +48 -40
- symai/backend/mixin/deepseek.py +4 -5
- symai/backend/mixin/google.py +5 -4
- symai/backend/mixin/groq.py +2 -4
- symai/backend/mixin/openai.py +132 -110
- symai/backend/settings.py +14 -14
- symai/chat.py +164 -94
- symai/collect/dynamic.py +13 -11
- symai/collect/pipeline.py +39 -31
- symai/collect/stats.py +109 -69
- symai/components.py +556 -238
- symai/constraints.py +14 -5
- symai/core.py +1495 -1210
- symai/core_ext.py +55 -50
- symai/endpoints/api.py +113 -58
- symai/extended/api_builder.py +22 -17
- symai/extended/arxiv_pdf_parser.py +13 -5
- symai/extended/bibtex_parser.py +8 -4
- symai/extended/conversation.py +88 -69
- symai/extended/document.py +40 -27
- symai/extended/file_merger.py +45 -7
- symai/extended/graph.py +38 -24
- symai/extended/html_style_template.py +17 -11
- symai/extended/interfaces/blip_2.py +1 -1
- symai/extended/interfaces/clip.py +4 -2
- symai/extended/interfaces/console.py +5 -3
- symai/extended/interfaces/dall_e.py +3 -1
- symai/extended/interfaces/file.py +2 -0
- symai/extended/interfaces/flux.py +3 -1
- symai/extended/interfaces/gpt_image.py +15 -6
- symai/extended/interfaces/input.py +2 -1
- symai/extended/interfaces/llava.py +1 -1
- symai/extended/interfaces/{naive_webscraping.py → naive_scrape.py} +3 -2
- symai/extended/interfaces/naive_vectordb.py +2 -2
- symai/extended/interfaces/ocr.py +4 -2
- symai/extended/interfaces/openai_search.py +2 -0
- symai/extended/interfaces/parallel.py +30 -0
- symai/extended/interfaces/perplexity.py +2 -0
- symai/extended/interfaces/pinecone.py +6 -4
- symai/extended/interfaces/python.py +2 -0
- symai/extended/interfaces/serpapi.py +2 -0
- symai/extended/interfaces/terminal.py +0 -1
- symai/extended/interfaces/tts.py +2 -1
- symai/extended/interfaces/whisper.py +2 -1
- symai/extended/interfaces/wolframalpha.py +1 -0
- symai/extended/metrics/__init__.py +1 -1
- symai/extended/metrics/similarity.py +5 -2
- symai/extended/os_command.py +31 -22
- symai/extended/packages/symdev.py +39 -34
- symai/extended/packages/sympkg.py +30 -27
- symai/extended/packages/symrun.py +46 -35
- symai/extended/repo_cloner.py +10 -9
- symai/extended/seo_query_optimizer.py +15 -12
- symai/extended/solver.py +104 -76
- symai/extended/summarizer.py +8 -7
- symai/extended/taypan_interpreter.py +10 -9
- symai/extended/vectordb.py +28 -15
- symai/formatter/formatter.py +39 -31
- symai/formatter/regex.py +46 -44
- symai/functional.py +184 -86
- symai/imports.py +85 -51
- symai/interfaces.py +1 -1
- symai/memory.py +33 -24
- symai/menu/screen.py +28 -19
- symai/misc/console.py +27 -27
- symai/misc/loader.py +4 -3
- symai/models/base.py +147 -76
- symai/models/errors.py +1 -1
- symai/ops/__init__.py +1 -1
- symai/ops/measures.py +17 -14
- symai/ops/primitives.py +933 -635
- symai/post_processors.py +28 -24
- symai/pre_processors.py +58 -52
- symai/processor.py +15 -9
- symai/prompts.py +714 -649
- symai/server/huggingface_server.py +115 -32
- symai/server/llama_cpp_server.py +14 -6
- symai/server/qdrant_server.py +206 -0
- symai/shell.py +98 -39
- symai/shellsv.py +307 -223
- symai/strategy.py +135 -81
- symai/symbol.py +276 -225
- symai/utils.py +62 -46
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/METADATA +19 -9
- symbolicai-1.1.0.dist-info/RECORD +168 -0
- symbolicai-1.0.0.dist-info/RECORD +0 -163
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/WHEEL +0 -0
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/entry_points.txt +0 -0
- {symbolicai-1.0.0.dist-info → symbolicai-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {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
|
|
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__(
|
|
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
|
|
35
|
-
self.n_workers
|
|
40
|
+
self.formatter = formatter
|
|
41
|
+
self.n_workers = n_workers
|
|
36
42
|
self.sym_return_type = Graph
|
|
37
|
-
self.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(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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(
|
|
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
|
|
67
|
-
csv
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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 =
|
|
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
|
-
|
|
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 = [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
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__(
|
|
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(
|
|
14
|
-
message =
|
|
13
|
+
args_ = payload.get("args", ())
|
|
14
|
+
message = " ".join(str(arg) for arg in args_)
|
|
15
15
|
UserMessage(message)
|
|
16
16
|
|
|
17
|
-
kwargs[
|
|
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 =
|
|
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)
|
|
@@ -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 =
|
|
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__(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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):
|
|
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,9 +1,9 @@
|
|
|
1
1
|
from ... import core
|
|
2
|
-
from ...backend.engines.
|
|
2
|
+
from ...backend.engines.scrape.engine_requests import RequestsResult
|
|
3
3
|
from ...symbol import Expression
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
class
|
|
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
|
|
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":
|
symai/extended/interfaces/ocr.py
CHANGED
|
@@ -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(
|
|
13
|
-
image_url = f
|
|
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)
|
|
@@ -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)
|
|
@@ -4,15 +4,17 @@ from ...utils import UserMessage
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
class pinecone(Expression):
|
|
7
|
-
def __init__(self, index_name
|
|
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__(
|
|
13
|
-
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
|
|
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)
|
symai/extended/interfaces/tts.py
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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)
|
|
@@ -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
|
|
symai/extended/os_command.py
CHANGED
|
@@ -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__(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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:
|
|
73
|
-
self.os_platform:
|
|
74
|
-
self.programs:
|
|
75
|
-
self.meta: dict[str, str]
|
|
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 ==
|
|
80
|
+
if self.os_platform == "auto":
|
|
78
81
|
self.os_platform = platform.platform()
|
|
79
82
|
if len(programs) == 0:
|
|
80
|
-
UserMessage(
|
|
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
|
|
85
|
-
if
|
|
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
|
|
90
|
+
if "windows" in self.os_platform.lower():
|
|
88
91
|
return [subprocess.run(["powershell", "-Command", str(command)], check=False)]
|
|
89
|
-
if
|
|
92
|
+
if "mac" in self.os_platform.lower():
|
|
90
93
|
return [subprocess.run(["bash", "-c", str(command)], check=False)]
|
|
91
|
-
UserMessage(
|
|
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[
|
|
99
|
+
kwargs["verbose"] = self.verbose
|
|
97
100
|
|
|
98
|
-
prompt = Context.format(
|
|
99
|
-
|
|
100
|
-
|
|
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(
|
|
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
|
+
)
|