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.
- symai/__init__.py +269 -173
- symai/backend/base.py +123 -110
- symai/backend/engines/drawing/engine_bfl.py +45 -44
- symai/backend/engines/drawing/engine_gpt_image.py +112 -97
- symai/backend/engines/embedding/engine_llama_cpp.py +63 -52
- symai/backend/engines/embedding/engine_openai.py +25 -21
- symai/backend/engines/execute/engine_python.py +19 -18
- symai/backend/engines/files/engine_io.py +104 -95
- symai/backend/engines/imagecaptioning/engine_blip2.py +28 -24
- symai/backend/engines/imagecaptioning/engine_llavacpp_client.py +102 -79
- symai/backend/engines/index/engine_pinecone.py +124 -97
- symai/backend/engines/index/engine_qdrant.py +1011 -0
- symai/backend/engines/index/engine_vectordb.py +84 -56
- symai/backend/engines/lean/engine_lean4.py +96 -52
- symai/backend/engines/neurosymbolic/__init__.py +41 -13
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +330 -248
- symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +329 -264
- symai/backend/engines/neurosymbolic/engine_cerebras.py +328 -0
- symai/backend/engines/neurosymbolic/engine_deepseekX_reasoning.py +118 -88
- symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +344 -299
- symai/backend/engines/neurosymbolic/engine_groq.py +173 -115
- symai/backend/engines/neurosymbolic/engine_huggingface.py +114 -84
- symai/backend/engines/neurosymbolic/engine_llama_cpp.py +144 -118
- symai/backend/engines/neurosymbolic/engine_openai_gptX_chat.py +415 -307
- symai/backend/engines/neurosymbolic/engine_openai_gptX_reasoning.py +394 -231
- symai/backend/engines/ocr/engine_apilayer.py +23 -27
- symai/backend/engines/output/engine_stdout.py +10 -13
- symai/backend/engines/{webscraping → scrape}/engine_requests.py +101 -54
- symai/backend/engines/search/engine_openai.py +100 -88
- symai/backend/engines/search/engine_parallel.py +665 -0
- symai/backend/engines/search/engine_perplexity.py +44 -45
- symai/backend/engines/search/engine_serpapi.py +37 -34
- symai/backend/engines/speech_to_text/engine_local_whisper.py +54 -51
- symai/backend/engines/symbolic/engine_wolframalpha.py +15 -9
- symai/backend/engines/text_to_speech/engine_openai.py +20 -26
- symai/backend/engines/text_vision/engine_clip.py +39 -37
- symai/backend/engines/userinput/engine_console.py +5 -6
- symai/backend/mixin/__init__.py +13 -0
- symai/backend/mixin/anthropic.py +48 -38
- symai/backend/mixin/deepseek.py +6 -5
- symai/backend/mixin/google.py +7 -4
- symai/backend/mixin/groq.py +2 -4
- symai/backend/mixin/openai.py +140 -110
- symai/backend/settings.py +87 -20
- symai/chat.py +216 -123
- symai/collect/__init__.py +7 -1
- symai/collect/dynamic.py +80 -70
- symai/collect/pipeline.py +67 -51
- symai/collect/stats.py +161 -109
- symai/components.py +707 -360
- symai/constraints.py +24 -12
- symai/core.py +1857 -1233
- symai/core_ext.py +83 -80
- symai/endpoints/api.py +166 -104
- symai/extended/.DS_Store +0 -0
- symai/extended/__init__.py +46 -12
- symai/extended/api_builder.py +29 -21
- symai/extended/arxiv_pdf_parser.py +23 -14
- symai/extended/bibtex_parser.py +9 -6
- symai/extended/conversation.py +156 -126
- symai/extended/document.py +50 -30
- symai/extended/file_merger.py +57 -14
- symai/extended/graph.py +51 -32
- symai/extended/html_style_template.py +18 -14
- symai/extended/interfaces/blip_2.py +2 -3
- symai/extended/interfaces/clip.py +4 -3
- symai/extended/interfaces/console.py +9 -1
- symai/extended/interfaces/dall_e.py +4 -2
- symai/extended/interfaces/file.py +2 -0
- symai/extended/interfaces/flux.py +4 -2
- symai/extended/interfaces/gpt_image.py +16 -7
- symai/extended/interfaces/input.py +2 -1
- symai/extended/interfaces/llava.py +1 -2
- symai/extended/interfaces/{naive_webscraping.py → naive_scrape.py} +4 -3
- symai/extended/interfaces/naive_vectordb.py +9 -10
- symai/extended/interfaces/ocr.py +5 -3
- 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 +12 -9
- symai/extended/interfaces/python.py +2 -0
- symai/extended/interfaces/serpapi.py +3 -1
- symai/extended/interfaces/terminal.py +2 -4
- symai/extended/interfaces/tts.py +3 -2
- symai/extended/interfaces/whisper.py +3 -2
- symai/extended/interfaces/wolframalpha.py +2 -1
- symai/extended/metrics/__init__.py +11 -1
- symai/extended/metrics/similarity.py +14 -13
- symai/extended/os_command.py +39 -29
- symai/extended/packages/__init__.py +29 -3
- symai/extended/packages/symdev.py +51 -43
- symai/extended/packages/sympkg.py +41 -35
- symai/extended/packages/symrun.py +63 -50
- symai/extended/repo_cloner.py +14 -12
- symai/extended/seo_query_optimizer.py +15 -13
- symai/extended/solver.py +116 -91
- symai/extended/summarizer.py +12 -10
- symai/extended/taypan_interpreter.py +17 -18
- symai/extended/vectordb.py +122 -92
- symai/formatter/__init__.py +9 -1
- symai/formatter/formatter.py +51 -47
- symai/formatter/regex.py +70 -69
- symai/functional.py +325 -176
- symai/imports.py +190 -147
- symai/interfaces.py +57 -28
- symai/memory.py +45 -35
- symai/menu/screen.py +28 -19
- symai/misc/console.py +66 -56
- symai/misc/loader.py +8 -5
- symai/models/__init__.py +17 -1
- symai/models/base.py +395 -236
- symai/models/errors.py +1 -2
- symai/ops/__init__.py +32 -22
- symai/ops/measures.py +24 -25
- symai/ops/primitives.py +1149 -731
- symai/post_processors.py +58 -50
- symai/pre_processors.py +86 -82
- symai/processor.py +21 -13
- symai/prompts.py +764 -685
- symai/server/huggingface_server.py +135 -49
- symai/server/llama_cpp_server.py +21 -11
- symai/server/qdrant_server.py +206 -0
- symai/shell.py +100 -42
- symai/shellsv.py +700 -492
- symai/strategy.py +630 -346
- symai/symbol.py +368 -322
- symai/utils.py +100 -78
- {symbolicai-0.21.0.dist-info → symbolicai-1.1.0.dist-info}/METADATA +22 -10
- symbolicai-1.1.0.dist-info/RECORD +168 -0
- symbolicai-0.21.0.dist-info/RECORD +0 -162
- {symbolicai-0.21.0.dist-info → symbolicai-1.1.0.dist-info}/WHEEL +0 -0
- {symbolicai-0.21.0.dist-info → symbolicai-1.1.0.dist-info}/entry_points.txt +0 -0
- {symbolicai-0.21.0.dist-info → symbolicai-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {symbolicai-0.21.0.dist-info → symbolicai-1.1.0.dist-info}/top_level.txt +0 -0
symai/memory.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
from typing import List
|
|
2
|
-
|
|
3
1
|
from . import core_ext
|
|
4
|
-
from .symbol import Expression, Symbol
|
|
5
2
|
from .components import Function
|
|
3
|
+
from .symbol import Expression, Symbol
|
|
6
4
|
|
|
7
5
|
|
|
8
6
|
class Memory(Expression):
|
|
@@ -25,90 +23,102 @@ class Memory(Expression):
|
|
|
25
23
|
class SlidingWindowListMemory(Memory):
|
|
26
24
|
def __init__(self, window_size: int = 10, max_size: int = 1000, **kwargs):
|
|
27
25
|
super().__init__(**kwargs)
|
|
28
|
-
self._memory:
|
|
29
|
-
self._window_size: int
|
|
30
|
-
self._max_size: int
|
|
26
|
+
self._memory: list[str] = []
|
|
27
|
+
self._window_size: int = window_size
|
|
28
|
+
self._max_size: int = max_size
|
|
31
29
|
|
|
32
|
-
def store(self, query: str, *
|
|
30
|
+
def store(self, query: str, *_args, **_kwargs):
|
|
33
31
|
self._memory.append(query)
|
|
34
32
|
if len(self._memory) > self._max_size:
|
|
35
|
-
self._memory = self._memory[-self._max_size:]
|
|
33
|
+
self._memory = self._memory[-self._max_size :]
|
|
36
34
|
|
|
37
|
-
def forget(self, query: Symbol, *
|
|
35
|
+
def forget(self, query: Symbol, *_args, **_kwargs):
|
|
38
36
|
self._memory.remove(query)
|
|
39
37
|
|
|
40
|
-
def recall(self, *
|
|
41
|
-
return self._memory[-self._window_size:]
|
|
38
|
+
def recall(self, *_args, **_kwargs):
|
|
39
|
+
return self._memory[-self._window_size :]
|
|
42
40
|
|
|
43
41
|
|
|
44
42
|
class SlidingWindowStringConcatMemory(Memory):
|
|
45
|
-
def __init__(self, *
|
|
43
|
+
def __init__(self, *_args, **kwargs):
|
|
46
44
|
super().__init__(**kwargs)
|
|
47
|
-
self._memory: str
|
|
48
|
-
self.marker: str
|
|
45
|
+
self._memory: str = ""
|
|
46
|
+
self.marker: str = "[--++=|=++--]"
|
|
49
47
|
|
|
50
|
-
@core_ext.bind(engine=
|
|
51
|
-
def max_tokens(self):
|
|
48
|
+
@core_ext.bind(engine="neurosymbolic", property="max_context_tokens")
|
|
49
|
+
def max_tokens(self):
|
|
50
|
+
pass
|
|
52
51
|
|
|
53
52
|
def __getstate__(self):
|
|
54
53
|
state = super().__getstate__().copy()
|
|
55
54
|
# Exclude the max_tokens property from being serialized
|
|
56
|
-
state.pop(
|
|
55
|
+
state.pop("_max_tokens", None)
|
|
57
56
|
return state
|
|
58
57
|
|
|
59
58
|
def __setstate__(self, state):
|
|
60
59
|
self.__dict__.update(state)
|
|
60
|
+
|
|
61
61
|
# Initialize _max_tokens as None, it should be set again after deserialization
|
|
62
|
-
@core_ext.bind(engine=
|
|
63
|
-
def _max_tokens(self):
|
|
62
|
+
@core_ext.bind(engine="neurosymbolic", property="max_context_tokens")
|
|
63
|
+
def _max_tokens(self):
|
|
64
|
+
pass
|
|
65
|
+
|
|
64
66
|
self.max_tokens = _max_tokens
|
|
65
67
|
|
|
66
68
|
def history(self):
|
|
67
69
|
return [hist for hist in self._memory.split(self.marker) if hist]
|
|
68
70
|
|
|
69
71
|
def drop(self):
|
|
70
|
-
self._memory =
|
|
72
|
+
self._memory = ""
|
|
71
73
|
|
|
72
74
|
def store(self, query: str):
|
|
73
75
|
# append to string to memory
|
|
74
|
-
self._memory += f
|
|
76
|
+
self._memory += f"{query!s}{self.marker}"
|
|
75
77
|
|
|
76
|
-
def forget(self, query: Symbol, *
|
|
78
|
+
def forget(self, query: Symbol, *_args, **_kwargs):
|
|
77
79
|
# remove substring from memory
|
|
78
80
|
sym = Symbol(self._memory)
|
|
79
81
|
self._memory = str(sym - query)
|
|
80
82
|
|
|
81
83
|
def recall(self, query: str, *args, **kwargs) -> Symbol:
|
|
82
|
-
hist
|
|
83
|
-
memory
|
|
84
|
+
hist = self.history()
|
|
85
|
+
memory = ""
|
|
84
86
|
if len(hist) > 0:
|
|
85
|
-
memory
|
|
86
|
-
val
|
|
87
|
+
memory = "[MEMORY]\n"
|
|
88
|
+
val = "\n".join(hist)
|
|
87
89
|
memory += val
|
|
88
90
|
that = self
|
|
91
|
+
|
|
89
92
|
class Recall(Function):
|
|
90
93
|
@property
|
|
91
94
|
def static_context(self):
|
|
92
95
|
return that.static_context
|
|
96
|
+
|
|
93
97
|
func = Recall(memory)
|
|
94
98
|
return func(query, *args, **kwargs)
|
|
95
99
|
|
|
96
100
|
|
|
97
101
|
class VectorDatabaseMemory(Memory):
|
|
98
|
-
def __init__(
|
|
102
|
+
def __init__(
|
|
103
|
+
self, enabled: bool = True, top_k: int = 3, index_name: str = "defaultindex", **kwargs
|
|
104
|
+
):
|
|
99
105
|
super().__init__(**kwargs)
|
|
100
106
|
self.enabled: bool = enabled
|
|
101
|
-
self.top_k: int
|
|
102
|
-
self.index_name
|
|
107
|
+
self.top_k: int = top_k
|
|
108
|
+
self.index_name = index_name
|
|
103
109
|
|
|
104
|
-
def store(self, query: str
|
|
105
|
-
if not self.enabled:
|
|
110
|
+
def store(self, query: str, *_args, **_kwargs):
|
|
111
|
+
if not self.enabled:
|
|
112
|
+
return
|
|
106
113
|
|
|
107
114
|
self.add(Symbol(query).zip(), index_name=self.index_name)
|
|
108
115
|
|
|
109
|
-
def recall(self, query: str, *
|
|
110
|
-
if not self.enabled:
|
|
116
|
+
def recall(self, query: str, *_args, **_kwargs):
|
|
117
|
+
if not self.enabled:
|
|
118
|
+
return None
|
|
111
119
|
|
|
112
|
-
res = self.get(
|
|
120
|
+
res = self.get(
|
|
121
|
+
Symbol(query).embed().value, index_top_k=self.top_k, index_name=self.index_name
|
|
122
|
+
).ast()
|
|
113
123
|
|
|
114
|
-
return [v[
|
|
124
|
+
return [v["metadata"]["text"] for v in res["matches"]]
|
symai/menu/screen.py
CHANGED
|
@@ -6,42 +6,51 @@ from ..misc.console import ConsoleStyle
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def show_splash_screen(print: callable = print_formatted_text):
|
|
9
|
-
print(
|
|
10
|
-
print(
|
|
11
|
-
print(
|
|
12
|
-
print(
|
|
9
|
+
print("\n\n")
|
|
10
|
+
print("- " * 42)
|
|
11
|
+
print("==" * 41 + "=")
|
|
12
|
+
print(
|
|
13
|
+
r"""
|
|
13
14
|
____| | _) | \ _ _|
|
|
14
15
|
__| \ \ / __| _ \ __ \ __| | __| | | _ \ |
|
|
15
16
|
| ` < | __/ | | \__ \ | | | | ___ \ |
|
|
16
17
|
_____| _/\_\ \__| \___| _| _| ____/ _| \__| \__, | _/ _\ ___|
|
|
17
18
|
____/
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
""",
|
|
20
|
+
escape=True,
|
|
21
|
+
)
|
|
22
|
+
print("- " * 42)
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
def show_info_message(print: callable = print_formatted_text):
|
|
23
|
-
print(
|
|
24
|
-
print(
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
print("Welcome to SymbolicAI!" + "\n")
|
|
27
|
+
print(
|
|
28
|
+
"SymbolicAI is an open-source Python project for building AI-powered applications\nand assistants."
|
|
29
|
+
)
|
|
30
|
+
print("We utilize the power of large language models and the latest research in AI." + "\n")
|
|
31
|
+
print(
|
|
32
|
+
"SymbolicAI is backed by ExtensityAI. We are committed to open research,\nthe democratization of AI tools and much more ..."
|
|
33
|
+
"\n"
|
|
34
|
+
)
|
|
27
35
|
|
|
28
|
-
print(
|
|
29
|
-
print(
|
|
30
|
-
print(
|
|
36
|
+
print("... and we also like peanut butter and jelly sandwiches, and cookies." + "\n\n")
|
|
37
|
+
print("If you like what we are doing please help us achieve our mission!")
|
|
38
|
+
print("More information is available at https://www.extensity.ai" + "\n")
|
|
31
39
|
|
|
32
40
|
|
|
33
41
|
def show_separator(print: callable = print_formatted_text):
|
|
34
|
-
print(
|
|
42
|
+
print("- " * 42 + "\n")
|
|
35
43
|
|
|
36
44
|
|
|
37
45
|
def show_intro_menu():
|
|
38
|
-
if os.environ.get(
|
|
39
|
-
with ConsoleStyle(
|
|
46
|
+
if os.environ.get("SYMAI_WARNINGS", "1") == "1":
|
|
47
|
+
with ConsoleStyle("extensity") as console:
|
|
40
48
|
show_splash_screen(print=console.print)
|
|
41
|
-
with ConsoleStyle(
|
|
49
|
+
with ConsoleStyle("text") as console:
|
|
42
50
|
show_info_message(print=console.print)
|
|
43
|
-
with ConsoleStyle(
|
|
51
|
+
with ConsoleStyle("extensity") as console:
|
|
44
52
|
show_separator(print=console.print)
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
47
56
|
show_intro_menu()
|
symai/misc/console.py
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import pygments
|
|
3
1
|
import logging
|
|
2
|
+
import re
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
# @TODO: refactor to use rich instead of prompt_toolkit
|
|
6
5
|
from html import escape as escape_html
|
|
7
|
-
from
|
|
8
|
-
|
|
6
|
+
from typing import ClassVar
|
|
7
|
+
|
|
8
|
+
import pygments
|
|
9
|
+
from prompt_toolkit import HTML, print_formatted_text
|
|
10
|
+
from prompt_toolkit.formatted_text import PygmentsTokens
|
|
9
11
|
from pygments.lexers.c_cpp import CppLexer
|
|
12
|
+
from pygments.lexers.javascript import JavascriptLexer
|
|
13
|
+
from pygments.lexers.python import PythonLexer
|
|
10
14
|
from pygments.lexers.shell import BashLexer
|
|
11
|
-
from prompt_toolkit import print_formatted_text
|
|
12
|
-
from prompt_toolkit import HTML
|
|
13
|
-
from prompt_toolkit.formatted_text import PygmentsTokens
|
|
14
|
-
|
|
15
15
|
|
|
16
16
|
logger = logging.getLogger(__name__)
|
|
17
|
-
print = print_formatted_text
|
|
17
|
+
print = print_formatted_text # noqa
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
class ConsoleStyle
|
|
21
|
-
style_types = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
class ConsoleStyle:
|
|
21
|
+
style_types: ClassVar[dict[str, str]] = {
|
|
22
|
+
"alert": "orange",
|
|
23
|
+
"error": "ansired",
|
|
24
|
+
"warn": "ansiyellow",
|
|
25
|
+
"info": "ansiblue",
|
|
26
|
+
"success": "ansigreen",
|
|
27
|
+
"extensity": "#009499",
|
|
28
|
+
"text": "ansigray",
|
|
29
|
+
"debug": "gray",
|
|
30
|
+
"custom": "custom",
|
|
31
|
+
"code": "code",
|
|
32
|
+
"default": "",
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
def __init__(self, style_type
|
|
35
|
+
def __init__(self, style_type="", color="", logging: bool = False):
|
|
36
36
|
self.style_type = style_type
|
|
37
|
-
self.color
|
|
38
|
-
self.logging
|
|
37
|
+
self.color = color
|
|
38
|
+
self.logging = logging
|
|
39
39
|
|
|
40
40
|
def __call__(self, message):
|
|
41
41
|
self.print(message)
|
|
@@ -52,35 +52,45 @@ class ConsoleStyle(object):
|
|
|
52
52
|
logger.debug(message)
|
|
53
53
|
# Prepare safe content for HTML printing without mutating the original
|
|
54
54
|
content_for_html = escape_html(message) if escape else message
|
|
55
|
-
style = self.style_types.get(self.style_type, self.style_types[
|
|
55
|
+
style = self.style_types.get(self.style_type, self.style_types["default"])
|
|
56
56
|
|
|
57
|
-
if style == self.style_types[
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for segment in segments:
|
|
62
|
-
if segment == '```':
|
|
63
|
-
is_code = not is_code
|
|
64
|
-
continue
|
|
65
|
-
if is_code:
|
|
66
|
-
# Determine lexer
|
|
67
|
-
if 'python' in segment.lower():
|
|
68
|
-
lexer = PythonLexer()
|
|
69
|
-
elif 'javascript' in segment.lower() or 'typescript' in segment.lower():
|
|
70
|
-
lexer = JavascriptLexer()
|
|
71
|
-
elif 'c++' in segment.lower():
|
|
72
|
-
lexer = CppLexer()
|
|
73
|
-
else:
|
|
74
|
-
lexer = BashLexer()
|
|
75
|
-
# Print highlighted code
|
|
76
|
-
tokens = list(pygments.lex("```" + segment + "```", lexer))
|
|
77
|
-
print(PygmentsTokens(tokens), end='')
|
|
78
|
-
else:
|
|
79
|
-
# Print the segment normally
|
|
80
|
-
print(segment, end='\n')
|
|
81
|
-
elif style == self.style_types['default']:
|
|
57
|
+
if style == self.style_types["code"]:
|
|
58
|
+
self._print_code_message(message)
|
|
59
|
+
return
|
|
60
|
+
if style == self.style_types["default"]:
|
|
82
61
|
print(message)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
62
|
+
return
|
|
63
|
+
if style == self.style_types["custom"]:
|
|
64
|
+
self._print_html(self.color, content_for_html)
|
|
65
|
+
return
|
|
66
|
+
self._print_html(style, content_for_html)
|
|
67
|
+
|
|
68
|
+
def _print_code_message(self, message: str) -> None:
|
|
69
|
+
segments = re.split(r"(```)", message)
|
|
70
|
+
is_code_segment = False
|
|
71
|
+
for segment in segments:
|
|
72
|
+
if segment == "```":
|
|
73
|
+
is_code_segment = not is_code_segment
|
|
74
|
+
continue
|
|
75
|
+
if is_code_segment:
|
|
76
|
+
self._print_code_segment(segment)
|
|
77
|
+
continue
|
|
78
|
+
print(segment, end="\n")
|
|
79
|
+
|
|
80
|
+
def _print_code_segment(self, segment: str) -> None:
|
|
81
|
+
lexer = self._select_lexer(segment)
|
|
82
|
+
tokens = list(pygments.lex("```" + segment + "```", lexer))
|
|
83
|
+
print(PygmentsTokens(tokens), end="")
|
|
84
|
+
|
|
85
|
+
def _select_lexer(self, segment: str):
|
|
86
|
+
lowered_segment = segment.lower()
|
|
87
|
+
if "python" in lowered_segment:
|
|
88
|
+
return PythonLexer()
|
|
89
|
+
if "javascript" in lowered_segment or "typescript" in lowered_segment:
|
|
90
|
+
return JavascriptLexer()
|
|
91
|
+
if "c++" in lowered_segment:
|
|
92
|
+
return CppLexer()
|
|
93
|
+
return BashLexer()
|
|
94
|
+
|
|
95
|
+
def _print_html(self, color: str, content: str) -> None:
|
|
96
|
+
print(HTML(f'<style fg="{color}">{content}</style>'))
|
symai/misc/loader.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from itertools import cycle
|
|
3
3
|
from shutil import get_terminal_size
|
|
4
|
-
from threading import
|
|
4
|
+
from threading import Event, Thread
|
|
5
5
|
from time import sleep
|
|
6
|
+
|
|
6
7
|
from prompt_toolkit import print_formatted_text
|
|
8
|
+
|
|
7
9
|
from .console import ConsoleStyle
|
|
8
10
|
|
|
9
|
-
print = print_formatted_text
|
|
11
|
+
print = print_formatted_text # noqa
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
class Loader:
|
|
12
15
|
def __init__(self, desc="Loading...", end="\n", timeout=0.1):
|
|
@@ -29,7 +32,7 @@ class Loader:
|
|
|
29
32
|
for c in cycle(self.steps):
|
|
30
33
|
if self.done.is_set():
|
|
31
34
|
break
|
|
32
|
-
with ConsoleStyle(
|
|
35
|
+
with ConsoleStyle("debug"):
|
|
33
36
|
sys.stdout.write(f"\r{self.desc} {c} ")
|
|
34
37
|
sys.stdout.flush()
|
|
35
38
|
sys.stdout.write(f"\r{self.end}")
|
|
@@ -44,7 +47,7 @@ class Loader:
|
|
|
44
47
|
self.done.set()
|
|
45
48
|
self._thread.join()
|
|
46
49
|
cols = get_terminal_size((80, 20)).columns
|
|
47
|
-
with ConsoleStyle(
|
|
50
|
+
with ConsoleStyle("debug"):
|
|
48
51
|
sys.stdout.write("\r" + " " * cols)
|
|
49
52
|
sys.stdout.flush()
|
|
50
53
|
sys.stdout.write(f"\r{self.end}")
|
|
@@ -56,4 +59,4 @@ class Loader:
|
|
|
56
59
|
self.stop()
|
|
57
60
|
|
|
58
61
|
def print(self, message):
|
|
59
|
-
print(message, style=
|
|
62
|
+
print(message, style="ansigray")
|
symai/models/__init__.py
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
from .base import
|
|
1
|
+
from .base import (
|
|
2
|
+
Const,
|
|
3
|
+
CustomConstraint,
|
|
4
|
+
LengthConstraint,
|
|
5
|
+
LLMDataModel,
|
|
6
|
+
build_dynamic_llm_datamodel,
|
|
7
|
+
)
|
|
2
8
|
from .errors import ExceptionWithUsage, TypeValidationError
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Const",
|
|
12
|
+
"CustomConstraint",
|
|
13
|
+
"ExceptionWithUsage",
|
|
14
|
+
"LLMDataModel",
|
|
15
|
+
"LengthConstraint",
|
|
16
|
+
"TypeValidationError",
|
|
17
|
+
"build_dynamic_llm_datamodel",
|
|
18
|
+
]
|