symbolicai 0.20.2__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- symai/__init__.py +96 -64
- symai/backend/base.py +93 -80
- symai/backend/engines/drawing/engine_bfl.py +12 -11
- symai/backend/engines/drawing/engine_gpt_image.py +108 -87
- symai/backend/engines/embedding/engine_llama_cpp.py +25 -28
- symai/backend/engines/embedding/engine_openai.py +3 -5
- symai/backend/engines/execute/engine_python.py +6 -5
- symai/backend/engines/files/engine_io.py +74 -67
- symai/backend/engines/imagecaptioning/engine_blip2.py +3 -3
- symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +54 -38
- symai/backend/engines/index/engine_pinecone.py +23 -24
- symai/backend/engines/index/engine_vectordb.py +16 -14
- symai/backend/engines/lean/engine_lean4.py +38 -34
- symai/backend/engines/neurosymbolic/__init__.py +41 -13
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +262 -182
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +263 -191
- symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +53 -49
- symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +212 -211
- symai/backend/engines/neurosymbolic/engine_groq.py +87 -63
- symai/backend/engines/neurosymbolic/engine_huggingface.py +21 -24
- symai/backend/engines/neurosymbolic/engine_llama_cpp.py +117 -48
- symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +256 -229
- symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +270 -150
- symai/backend/engines/ocr/engine_apilayer.py +6 -8
- symai/backend/engines/output/engine_stdout.py +1 -4
- symai/backend/engines/search/engine_openai.py +7 -7
- symai/backend/engines/search/engine_perplexity.py +5 -5
- symai/backend/engines/search/engine_serpapi.py +12 -14
- symai/backend/engines/speech_to_text/engine_local_whisper.py +20 -27
- symai/backend/engines/symbolic/engine_wolframalpha.py +3 -3
- symai/backend/engines/text_to_speech/engine_openai.py +5 -7
- symai/backend/engines/text_vision/engine_clip.py +7 -11
- symai/backend/engines/userinput/engine_console.py +3 -3
- symai/backend/engines/webscraping/engine_requests.py +81 -48
- symai/backend/mixin/__init__.py +13 -0
- symai/backend/mixin/anthropic.py +4 -2
- symai/backend/mixin/deepseek.py +2 -0
- symai/backend/mixin/google.py +2 -0
- symai/backend/mixin/openai.py +11 -3
- symai/backend/settings.py +83 -16
- symai/chat.py +101 -78
- symai/collect/__init__.py +7 -1
- symai/collect/dynamic.py +77 -69
- symai/collect/pipeline.py +35 -27
- symai/collect/stats.py +75 -63
- symai/components.py +198 -169
- symai/constraints.py +15 -12
- symai/core.py +698 -359
- symai/core_ext.py +32 -34
- symai/endpoints/api.py +80 -73
- symai/extended/.DS_Store +0 -0
- symai/extended/__init__.py +46 -12
- symai/extended/api_builder.py +11 -8
- symai/extended/arxiv_pdf_parser.py +13 -12
- symai/extended/bibtex_parser.py +2 -3
- symai/extended/conversation.py +101 -90
- symai/extended/document.py +17 -10
- symai/extended/file_merger.py +18 -13
- symai/extended/graph.py +18 -13
- symai/extended/html_style_template.py +2 -4
- symai/extended/interfaces/blip_2.py +1 -2
- symai/extended/interfaces/clip.py +1 -2
- symai/extended/interfaces/console.py +7 -1
- symai/extended/interfaces/dall_e.py +1 -1
- symai/extended/interfaces/flux.py +1 -1
- symai/extended/interfaces/gpt_image.py +1 -1
- symai/extended/interfaces/input.py +1 -1
- symai/extended/interfaces/llava.py +0 -1
- symai/extended/interfaces/naive_vectordb.py +7 -8
- symai/extended/interfaces/naive_webscraping.py +1 -1
- symai/extended/interfaces/ocr.py +1 -1
- symai/extended/interfaces/pinecone.py +6 -5
- symai/extended/interfaces/serpapi.py +1 -1
- symai/extended/interfaces/terminal.py +2 -3
- symai/extended/interfaces/tts.py +1 -1
- symai/extended/interfaces/whisper.py +1 -1
- symai/extended/interfaces/wolframalpha.py +1 -1
- symai/extended/metrics/__init__.py +11 -1
- symai/extended/metrics/similarity.py +11 -13
- symai/extended/os_command.py +17 -16
- symai/extended/packages/__init__.py +29 -3
- symai/extended/packages/symdev.py +19 -16
- symai/extended/packages/sympkg.py +12 -9
- symai/extended/packages/symrun.py +21 -19
- symai/extended/repo_cloner.py +11 -10
- symai/extended/seo_query_optimizer.py +1 -2
- symai/extended/solver.py +20 -23
- symai/extended/summarizer.py +4 -3
- symai/extended/taypan_interpreter.py +10 -12
- symai/extended/vectordb.py +99 -82
- symai/formatter/__init__.py +9 -1
- symai/formatter/formatter.py +12 -16
- symai/formatter/regex.py +62 -63
- symai/functional.py +176 -122
- symai/imports.py +136 -127
- symai/interfaces.py +56 -27
- symai/memory.py +14 -13
- symai/misc/console.py +49 -39
- symai/misc/loader.py +5 -3
- symai/models/__init__.py +17 -1
- symai/models/base.py +269 -181
- symai/models/errors.py +0 -1
- symai/ops/__init__.py +32 -22
- symai/ops/measures.py +11 -15
- symai/ops/primitives.py +348 -228
- symai/post_processors.py +32 -28
- symai/pre_processors.py +39 -41
- symai/processor.py +6 -4
- symai/prompts.py +59 -45
- symai/server/huggingface_server.py +23 -20
- symai/server/llama_cpp_server.py +7 -5
- symai/shell.py +3 -4
- symai/shellsv.py +499 -375
- symai/strategy.py +517 -287
- symai/symbol.py +111 -116
- symai/utils.py +42 -36
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/METADATA +4 -2
- symbolicai-1.0.0.dist-info/RECORD +163 -0
- symbolicai-0.20.2.dist-info/RECORD +0 -162
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/WHEEL +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/entry_points.txt +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/licenses/LICENSE +0 -0
- {symbolicai-0.20.2.dist-info → symbolicai-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import subprocess
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
3
6
|
import docker
|
|
4
7
|
import paramiko
|
|
5
|
-
|
|
6
|
-
from typing import Any, List, Tuple, Optional, Dict
|
|
7
|
-
from ...base import Engine
|
|
8
|
+
|
|
8
9
|
from ....symbol import Result
|
|
10
|
+
from ....utils import UserMessage
|
|
11
|
+
from ...base import Engine
|
|
12
|
+
|
|
9
13
|
|
|
10
14
|
class LeanResult(Result):
|
|
11
15
|
"""
|
|
@@ -14,7 +18,7 @@ class LeanResult(Result):
|
|
|
14
18
|
Attributes:
|
|
15
19
|
_value (Dict[str, str]): A dictionary containing the output of the Lean execution.
|
|
16
20
|
"""
|
|
17
|
-
def __init__(self, value:
|
|
21
|
+
def __init__(self, value: dict[str, str]) -> None:
|
|
18
22
|
"""
|
|
19
23
|
Initializes a new LeanResult instance.
|
|
20
24
|
|
|
@@ -57,7 +61,7 @@ class LeanEngine(Engine):
|
|
|
57
61
|
self.ssh_host: str = ssh_host
|
|
58
62
|
self.ssh_port: int = ssh_port
|
|
59
63
|
self.ssh_user: str = ssh_user
|
|
60
|
-
self.ssh_key_path:
|
|
64
|
+
self.ssh_key_path: Path = Path(ssh_key_path).expanduser()
|
|
61
65
|
self.docker_client: docker.DockerClient = docker.from_env()
|
|
62
66
|
self.container: docker.models.containers.Container = self._ensure_container()
|
|
63
67
|
self.name = self.__class__.__name__
|
|
@@ -85,7 +89,7 @@ class LeanEngine(Engine):
|
|
|
85
89
|
existing_container: docker.models.containers.Container = self.docker_client.containers.get(container_name)
|
|
86
90
|
existing_container.remove(force=True)
|
|
87
91
|
except docker.errors.NotFound:
|
|
88
|
-
|
|
92
|
+
UserMessage(f"No existing container named '{container_name}' found. Proceeding to create a new one.")
|
|
89
93
|
|
|
90
94
|
dockerfile: str = """
|
|
91
95
|
FROM buildpack-deps:buster
|
|
@@ -110,11 +114,11 @@ class LeanEngine(Engine):
|
|
|
110
114
|
"""
|
|
111
115
|
with tempfile.NamedTemporaryFile("w", delete=False) as temp_dockerfile:
|
|
112
116
|
temp_dockerfile.write(dockerfile)
|
|
113
|
-
dockerfile_path
|
|
117
|
+
dockerfile_path = Path(temp_dockerfile.name)
|
|
114
118
|
|
|
115
119
|
image: docker.models.images.Image
|
|
116
|
-
image, _ = self.docker_client.images.build(path=
|
|
117
|
-
|
|
120
|
+
image, _ = self.docker_client.images.build(path=str(dockerfile_path.parent), dockerfile=str(dockerfile_path), tag="lean4-container-image")
|
|
121
|
+
dockerfile_path.unlink()
|
|
118
122
|
|
|
119
123
|
container: docker.models.containers.Container = self.docker_client.containers.run(
|
|
120
124
|
image.id,
|
|
@@ -129,15 +133,16 @@ class LeanEngine(Engine):
|
|
|
129
133
|
Sets up SSH access to the Docker container, including generating an SSH key pair if necessary,
|
|
130
134
|
and configuring the container to accept SSH connections using the generated key.
|
|
131
135
|
"""
|
|
132
|
-
if not
|
|
133
|
-
subprocess.run(['ssh-keygen', '-t', 'rsa', '-b', '2048', '-f', self.ssh_key_path, '-N', ''], check=True)
|
|
136
|
+
if not self.ssh_key_path.exists():
|
|
137
|
+
subprocess.run(['ssh-keygen', '-t', 'rsa', '-b', '2048', '-f', str(self.ssh_key_path), '-N', ''], check=True)
|
|
134
138
|
|
|
135
139
|
subprocess.run(['docker', 'exec', self.container.id, 'mkdir', '-p', '/root/.ssh'], check=True)
|
|
136
|
-
|
|
140
|
+
public_key_path = self.ssh_key_path.parent / f'{self.ssh_key_path.name}.pub'
|
|
141
|
+
subprocess.run(['docker', 'cp', str(public_key_path), f'{self.container.id}:/root/.ssh/authorized_keys'], check=True)
|
|
137
142
|
subprocess.run(['docker', 'exec', self.container.id, 'chmod', '600', '/root/.ssh/authorized_keys'], check=True)
|
|
138
143
|
subprocess.run(['docker', 'exec', self.container.id, 'chown', 'root:root', '/root/.ssh/authorized_keys'], check=True)
|
|
139
144
|
|
|
140
|
-
def forward(self, argument: Any) ->
|
|
145
|
+
def forward(self, argument: Any) -> tuple[list[LeanResult], dict]:
|
|
141
146
|
"""
|
|
142
147
|
Executes Lean code provided as a string or as an object property.
|
|
143
148
|
|
|
@@ -149,14 +154,14 @@ class LeanEngine(Engine):
|
|
|
149
154
|
"""
|
|
150
155
|
code: str = argument if isinstance(argument, str) else argument.prop.prepared_input
|
|
151
156
|
|
|
152
|
-
rsp:
|
|
153
|
-
err:
|
|
154
|
-
tmpfile_path:
|
|
155
|
-
metadata:
|
|
157
|
+
rsp: LeanResult | None = None
|
|
158
|
+
err: str | None = None
|
|
159
|
+
tmpfile_path: Path | None = None
|
|
160
|
+
metadata: dict[str, Any] = {}
|
|
156
161
|
try:
|
|
157
162
|
with tempfile.NamedTemporaryFile(delete=False, suffix=".lean") as tmpfile:
|
|
158
163
|
tmpfile.write(code.encode())
|
|
159
|
-
tmpfile_path = tmpfile.name
|
|
164
|
+
tmpfile_path = Path(tmpfile.name)
|
|
160
165
|
|
|
161
166
|
output, exec_metadata = self._execute_lean(tmpfile_path)
|
|
162
167
|
metadata.update(exec_metadata)
|
|
@@ -168,17 +173,17 @@ class LeanEngine(Engine):
|
|
|
168
173
|
except Exception as e:
|
|
169
174
|
err = str(e)
|
|
170
175
|
metadata.update({'status': 'error', 'message': err})
|
|
171
|
-
|
|
176
|
+
UserMessage(f"Error during Lean execution: {err}")
|
|
172
177
|
finally:
|
|
173
|
-
if tmpfile_path and
|
|
174
|
-
|
|
178
|
+
if tmpfile_path and tmpfile_path.exists():
|
|
179
|
+
tmpfile_path.unlink()
|
|
175
180
|
if self.container:
|
|
176
|
-
|
|
181
|
+
UserMessage(f"Killing Docker container '{self.container.id}'...")
|
|
177
182
|
self.container.remove(force=True)
|
|
178
183
|
|
|
179
184
|
return [rsp] if rsp else [], metadata
|
|
180
185
|
|
|
181
|
-
def _execute_lean(self, filepath: str) ->
|
|
186
|
+
def _execute_lean(self, filepath: str) -> tuple[str, dict]:
|
|
182
187
|
"""
|
|
183
188
|
Executes a Lean script within the Docker container via SSH.
|
|
184
189
|
|
|
@@ -191,23 +196,23 @@ class LeanEngine(Engine):
|
|
|
191
196
|
try:
|
|
192
197
|
ssh = paramiko.SSHClient()
|
|
193
198
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
194
|
-
ssh.connect(self.ssh_host, port=self.ssh_port, username=self.ssh_user, key_filename=self.ssh_key_path)
|
|
199
|
+
ssh.connect(self.ssh_host, port=self.ssh_port, username=self.ssh_user, key_filename=str(self.ssh_key_path))
|
|
195
200
|
|
|
196
201
|
elan_path: str = "/usr/local/elan/bin/elan"
|
|
197
202
|
lean_path: str = "/usr/local/elan/bin/lean"
|
|
198
203
|
|
|
199
|
-
|
|
204
|
+
_stdin, stdout, stderr = ssh.exec_command(f"{elan_path} default stable && {lean_path} --version")
|
|
200
205
|
output: str = stdout.read().decode()
|
|
201
206
|
error: str = stderr.read().decode()
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
UserMessage(f"SSH Command Output: {output}")
|
|
208
|
+
UserMessage(f"SSH Command Error: {error}")
|
|
204
209
|
|
|
205
210
|
sftp = ssh.open_sftp()
|
|
206
|
-
remote_path: str = f"/root/{
|
|
211
|
+
remote_path: str = f"/root/{Path(filepath).name}"
|
|
207
212
|
sftp.put(filepath, remote_path)
|
|
208
213
|
sftp.close()
|
|
209
214
|
|
|
210
|
-
|
|
215
|
+
_stdin, stdout, stderr = ssh.exec_command(f"{lean_path} {remote_path}")
|
|
211
216
|
output = stdout.read().decode()
|
|
212
217
|
error = stderr.read().decode()
|
|
213
218
|
|
|
@@ -216,13 +221,12 @@ class LeanEngine(Engine):
|
|
|
216
221
|
|
|
217
222
|
if "error" in output.lower() or "error" in error.lower():
|
|
218
223
|
return output, {'status': 'failure'}
|
|
219
|
-
|
|
224
|
+
if not output and not error:
|
|
220
225
|
return "Lean program halted successfully with no output.", {'status': 'success'}
|
|
221
|
-
|
|
222
|
-
return output, {'status': 'success'}
|
|
226
|
+
return output, {'status': 'success'}
|
|
223
227
|
|
|
224
228
|
except Exception as e:
|
|
225
|
-
|
|
229
|
+
UserMessage(f"SSH command execution failed: {e!s}", raise_with=RuntimeError)
|
|
226
230
|
|
|
227
231
|
def prepare(self, argument: Any) -> None:
|
|
228
232
|
"""
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
from ...mixin import (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
from ...mixin import (
|
|
2
|
+
ANTHROPIC_CHAT_MODELS,
|
|
3
|
+
ANTHROPIC_REASONING_MODELS,
|
|
4
|
+
DEEPSEEK_CHAT_MODELS,
|
|
5
|
+
DEEPSEEK_REASONING_MODELS,
|
|
6
|
+
GOOGLE_CHAT_MODELS,
|
|
7
|
+
GOOGLE_REASONING_MODELS,
|
|
8
|
+
GROQ_CHAT_MODELS,
|
|
9
|
+
GROQ_REASONING_MODELS,
|
|
10
|
+
OPENAI_CHAT_MODELS,
|
|
11
|
+
OPENAI_REASONING_MODELS,
|
|
12
|
+
)
|
|
6
13
|
from .engine_anthropic_claudeX_chat import ClaudeXChatEngine
|
|
7
14
|
from .engine_anthropic_claudeX_reasoning import ClaudeXReasoningEngine
|
|
8
15
|
from .engine_deepseekX_reasoning import DeepSeekXReasoningEngine
|
|
@@ -13,12 +20,33 @@ from .engine_openai_gptX_reasoning import GPTXReasoningEngine
|
|
|
13
20
|
|
|
14
21
|
# create the mapping
|
|
15
22
|
ENGINE_MAPPING = {
|
|
16
|
-
**
|
|
17
|
-
**
|
|
18
|
-
**
|
|
19
|
-
**
|
|
20
|
-
**
|
|
21
|
-
**
|
|
22
|
-
**
|
|
23
|
-
**
|
|
23
|
+
**dict.fromkeys(ANTHROPIC_CHAT_MODELS, ClaudeXChatEngine),
|
|
24
|
+
**dict.fromkeys(ANTHROPIC_REASONING_MODELS, ClaudeXReasoningEngine),
|
|
25
|
+
**dict.fromkeys(DEEPSEEK_REASONING_MODELS, DeepSeekXReasoningEngine),
|
|
26
|
+
**dict.fromkeys(GOOGLE_REASONING_MODELS, GeminiXReasoningEngine),
|
|
27
|
+
**dict.fromkeys(OPENAI_CHAT_MODELS, GPTXChatEngine),
|
|
28
|
+
**dict.fromkeys(OPENAI_REASONING_MODELS, GPTXReasoningEngine),
|
|
29
|
+
**dict.fromkeys(GROQ_CHAT_MODELS, GroqEngine),
|
|
30
|
+
**dict.fromkeys(GROQ_REASONING_MODELS, GroqEngine),
|
|
24
31
|
}
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"ANTHROPIC_CHAT_MODELS",
|
|
35
|
+
"ANTHROPIC_REASONING_MODELS",
|
|
36
|
+
"DEEPSEEK_CHAT_MODELS",
|
|
37
|
+
"DEEPSEEK_REASONING_MODELS",
|
|
38
|
+
"ENGINE_MAPPING",
|
|
39
|
+
"GOOGLE_CHAT_MODELS",
|
|
40
|
+
"GOOGLE_REASONING_MODELS",
|
|
41
|
+
"GROQ_CHAT_MODELS",
|
|
42
|
+
"GROQ_REASONING_MODELS",
|
|
43
|
+
"OPENAI_CHAT_MODELS",
|
|
44
|
+
"OPENAI_REASONING_MODELS",
|
|
45
|
+
"ClaudeXChatEngine",
|
|
46
|
+
"ClaudeXReasoningEngine",
|
|
47
|
+
"DeepSeekXReasoningEngine",
|
|
48
|
+
"GPTXChatEngine",
|
|
49
|
+
"GPTXReasoningEngine",
|
|
50
|
+
"GeminiXReasoningEngine",
|
|
51
|
+
"GroqEngine",
|
|
52
|
+
]
|