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
@@ -8,22 +8,23 @@ from loguru import logger
8
8
 
9
9
  from ... import config_manager
10
10
  from ...imports import Import
11
+ from ...utils import UserMessage
11
12
 
12
13
 
13
- class PackageHandler():
14
+ class PackageHandler:
14
15
  def __init__(self):
15
- self.package_dir = Path(config_manager.config_dir) / 'packages'
16
+ self.package_dir = Path(config_manager.config_dir) / "packages"
16
17
 
17
- if not os.path.exists(self.package_dir):
18
- os.makedirs(self.package_dir)
18
+ if not self.package_dir.exists():
19
+ self.package_dir.mkdir(parents=True)
19
20
 
20
21
  os.chdir(self.package_dir)
21
22
 
22
23
  parser = argparse.ArgumentParser(
23
- description='''SymbolicAI package manager.
24
+ description="""SymbolicAI package manager.
24
25
  Manage extensions from the command line.
25
- You can (i) install, (r) remove, (l) list installed, (u) update a module or (U) update all modules.''',
26
- usage='''sympkg <command> [<args>]
26
+ You can (i) install, (r) remove, (l) list installed, (u) update a module or (U) update all modules.""",
27
+ usage="""sympkg <command> [<args>]
27
28
 
28
29
  The most commonly used sympkg commands are:
29
30
  i Install a new package (--local-path PATH, --submodules)
@@ -31,29 +32,33 @@ class PackageHandler():
31
32
  l List all installed packages
32
33
  u Update an installed package (--submodules)
33
34
  U Update all installed packages (--submodules)
34
- '''
35
+ """,
35
36
  )
36
37
 
37
- parser.add_argument('command', help='Subcommand to run')
38
+ parser.add_argument("command", help="Subcommand to run")
38
39
  args = parser.parse_args(sys.argv[1:2])
39
- if len(args.command) > 1 and not hasattr(self, args.command):
40
- setattr(args, 'package', args.command)
40
+ command_aliases = {"l": "list_packages"}
41
+ command = command_aliases.get(args.command, args.command)
42
+ if len(command) > 1 and not hasattr(self, command):
43
+ args.package = args.command
41
44
  self.i(args)
42
- elif len(args.command) == 1 and not hasattr(self, args.command):
43
- logger.error('Unrecognized command')
45
+ elif len(command) == 1 and not hasattr(self, command):
46
+ logger.error("Unrecognized command")
44
47
  parser.print_help()
45
48
  exit(1)
46
49
  else:
47
- getattr(self, args.command)()
50
+ getattr(self, command)()
48
51
 
49
- def i(self, args = None):
52
+ def i(self, args=None):
50
53
  parser = argparse.ArgumentParser(
51
- description='Install a new package',
52
- usage='sympkg i [package] [--local-path PATH] [--submodules]'
54
+ description="Install a new package",
55
+ usage="sympkg i [package] [--local-path PATH] [--submodules]",
56
+ )
57
+ parser.add_argument("package", help="Name of package to install")
58
+ parser.add_argument("--local-path", "-l", help="Local path to package directory")
59
+ parser.add_argument(
60
+ "--submodules", "-s", action="store_true", help="Initialize submodules for GitHub repos"
53
61
  )
54
- parser.add_argument('package', help='Name of package to install')
55
- parser.add_argument('--local-path', '-l', help='Local path to package directory')
56
- parser.add_argument('--submodules', '-s', action='store_true', help='Initialize submodules for GitHub repos')
57
62
 
58
63
  if args is None:
59
64
  args = parser.parse_args(sys.argv[2:])
@@ -62,46 +67,47 @@ class PackageHandler():
62
67
 
63
68
  def r(self):
64
69
  parser = argparse.ArgumentParser(
65
- description='Remove an installed package',
66
- usage='sympkg r [package]'
70
+ description="Remove an installed package", usage="sympkg r [package]"
67
71
  )
68
- parser.add_argument('package', help='Name of package to remove')
72
+ parser.add_argument("package", help="Name of package to remove")
69
73
  args = parser.parse_args(sys.argv[2:])
70
74
  Import.remove(args.package)
71
75
 
72
- def l(self):
73
- pprint.pprint(Import.list_installed())
76
+ def list_packages(self):
77
+ UserMessage(pprint.pformat(Import.list_installed()))
74
78
 
75
79
  def u(self):
76
80
  parser = argparse.ArgumentParser(
77
- description='Update an installed package',
78
- usage='sympkg u [package] [--submodules]'
81
+ description="Update an installed package", usage="sympkg u [package] [--submodules]"
82
+ )
83
+ parser.add_argument("package", help="Name of package to update")
84
+ parser.add_argument(
85
+ "--submodules", "-s", action="store_true", help="Update submodules as well"
79
86
  )
80
- parser.add_argument('package', help='Name of package to update')
81
- parser.add_argument('--submodules', '-s', action='store_true', help='Update submodules as well')
82
87
  args = parser.parse_args(sys.argv[2:])
83
88
  Import.update(args.package, args.submodules)
84
89
 
85
90
  def U(self):
86
91
  parser = argparse.ArgumentParser(
87
- description='Update all installed packages',
88
- usage='sympkg U [--submodules]'
92
+ description="Update all installed packages", usage="sympkg U [--submodules]"
93
+ )
94
+ parser.add_argument(
95
+ "--submodules", "-s", action="store_true", help="Update submodules as well"
89
96
  )
90
- parser.add_argument('--submodules', '-s', action='store_true', help='Update submodules as well')
91
97
  args = parser.parse_args(sys.argv[2:])
92
98
 
93
99
  packages = Import.list_installed()
94
100
  for package in packages:
95
101
  try:
96
- logger.info(f'[UPDATE]: Updating {package}...')
102
+ logger.info(f"[UPDATE]: Updating {package}...")
97
103
  Import.update(package, args.submodules)
98
104
  except Exception as e:
99
- logger.error(f'[SKIP]: Error updating {package}: {e}')
105
+ logger.error(f"[SKIP]: Error updating {package}: {e}")
100
106
 
101
107
 
102
108
  def run() -> None:
103
109
  PackageHandler()
104
110
 
105
111
 
106
- if __name__ == '__main__':
112
+ if __name__ == "__main__":
107
113
  run()
@@ -3,7 +3,6 @@ import json
3
3
  import os
4
4
  import sys
5
5
  from pathlib import Path
6
- from typing import Optional
7
6
 
8
7
  from loguru import logger
9
8
 
@@ -13,33 +12,35 @@ from ...misc.console import ConsoleStyle
13
12
  from ...misc.loader import Loader
14
13
 
15
14
 
16
- class PackageRunner():
15
+ class PackageRunner:
17
16
  def __init__(self):
18
- self.package_dir = Path(config_manager.config_dir) / 'packages'
19
- self.aliases_file = self.package_dir / 'aliases.json'
17
+ self.package_dir = Path(config_manager.config_dir) / "packages"
18
+ self.aliases_file = self.package_dir / "aliases.json"
20
19
 
21
- if not os.path.exists(self.package_dir):
22
- os.makedirs(self.package_dir)
20
+ if not self.package_dir.exists():
21
+ self.package_dir.mkdir(parents=True)
23
22
 
24
23
  os.chdir(self.package_dir)
25
24
 
26
25
  try:
27
26
  parser = argparse.ArgumentParser(
28
- description='''SymbolicAI package runner.
29
- Run a package in command line.''',
30
- usage='''symrun <alias> [<args>] | <command> <alias> [<package>]
27
+ description="""SymbolicAI package runner.
28
+ Run a package in command line.""",
29
+ usage="""symrun <alias> [<args>] | <command> <alias> [<package>]
31
30
  The most commonly used symrun commands are:
32
31
  <alias> [<args>] Run an alias
33
32
  c <alias> <package> Create a new alias
34
33
  l List all aliases
35
34
  r <alias> Remove an alias
36
- '''
35
+ """,
37
36
  )
38
37
 
39
- parser.add_argument('command', help='Subcommand to run')
38
+ parser.add_argument("command", help="Subcommand to run")
40
39
  args = parser.parse_args(sys.argv[1:2])
41
- getattr(self, args.command)()
42
- except:
40
+ command_aliases = {"l": "list_aliases"}
41
+ command = command_aliases.get(args.command, args.command)
42
+ getattr(self, command)()
43
+ except Exception:
43
44
  if len(sys.argv) > 1:
44
45
  self.run_alias()
45
46
  else:
@@ -47,68 +48,75 @@ class PackageRunner():
47
48
  exit(1)
48
49
 
49
50
  def load_aliases(self):
50
- if not os.path.exists(self.aliases_file):
51
+ if not self.aliases_file.exists():
51
52
  return {}
52
53
 
53
- with open(self.aliases_file, 'r') as f:
54
+ with self.aliases_file.open() as f:
54
55
  return json.load(f)
55
56
 
56
57
  def save_aliases(self, aliases):
57
- with open(self.aliases_file, 'w') as f:
58
+ with self.aliases_file.open("w") as f:
58
59
  json.dump(aliases, f)
59
60
 
60
- def console(self, header: str, output: Optional[object] = None):
61
- with ConsoleStyle('success'):
61
+ def console(self, header: str, output: object | None = None):
62
+ with ConsoleStyle("success"):
62
63
  logger.success(header)
63
64
  if output is not None:
64
- with ConsoleStyle('info'):
65
+ with ConsoleStyle("info"):
65
66
  logger.info(str(output))
66
67
 
67
68
  def run_alias(self):
68
69
  parser = argparse.ArgumentParser(
69
- description='This command runs the alias from the aliases.json file. If the alias is not found, it will run the command as a package.',
70
- usage='symrun <alias> [<args> | <kwargs>]*'
70
+ description="This command runs the alias from the aliases.json file. If the alias is not found, it will run the command as a package.",
71
+ usage="symrun <alias> [<args> | <kwargs>]*",
72
+ )
73
+ parser.add_argument("alias", help="Name of alias to run")
74
+ parser.add_argument("params", nargs=argparse.REMAINDER)
75
+ parser.add_argument(
76
+ "--submodules", "-s", action="store_true", help="Initialize submodules for GitHub repos"
71
77
  )
72
- parser.add_argument('alias', help='Name of alias to run')
73
- parser.add_argument('params', nargs=argparse.REMAINDER)
74
- parser.add_argument('--submodules', '-s', action='store_true', help='Initialize submodules for GitHub repos')
75
78
  args = parser.parse_args(sys.argv[1:])
76
79
 
77
80
  aliases = self.load_aliases()
78
81
  # try running the alias or as package
79
82
  package = aliases.get(args.alias) or args.alias
80
83
 
81
- arg_values = [arg for arg in args.params if '=' not in arg]
82
- kwargs = {arg.split('=')[0]: arg.split('=')[1] for arg in args.params if '=' in arg}
84
+ arg_values = [arg for arg in args.params if "=" not in arg]
85
+ kwargs = {arg.split("=")[0]: arg.split("=")[1] for arg in args.params if "=" in arg}
83
86
 
84
87
  if package is None:
85
- with ConsoleStyle('error'):
86
- logger.error("Alias run of `{}` not found. Please check your command {}".format(args.alias, args))
88
+ with ConsoleStyle("error"):
89
+ logger.error(
90
+ f"Alias run of `{args.alias}` not found. Please check your command {args}"
91
+ )
87
92
  parser.print_help()
88
- return
93
+ return None
89
94
 
90
- arg_values = [arg for arg in args.params if '=' not in arg]
91
- kwargs = {arg.split('=')[0]: arg.split('=')[1] for arg in args.params if '=' in arg}
95
+ arg_values = [arg for arg in args.params if "=" not in arg]
96
+ kwargs = {arg.split("=")[0]: arg.split("=")[1] for arg in args.params if "=" in arg}
92
97
 
93
98
  try:
94
99
  # Add submodules to kwargs if specified
95
100
  if args.submodules:
96
- kwargs['submodules'] = True
101
+ kwargs["submodules"] = True
97
102
 
98
103
  # Check if package is a local path
99
- if os.path.exists(package) and os.path.isdir(package):
104
+ package_path = Path(package)
105
+ if package_path.exists() and package_path.is_dir():
100
106
  # Local path - pass directly
101
107
  expr = Import(package, **kwargs)
102
108
  else:
103
109
  # GitHub reference
104
110
  expr = Import(package, **kwargs)
105
111
  except Exception as e:
106
- with ConsoleStyle('error'):
107
- logger.error("Error: {} in package `{}`.\nPlease check your command {} or if package is available.".format(str(e), package, args))
112
+ with ConsoleStyle("error"):
113
+ logger.error(
114
+ f"Error: {e!s} in package `{package}`.\nPlease check your command {args} or if package is available."
115
+ )
108
116
  parser.print_help()
109
- return
117
+ return None
110
118
 
111
- if '--disable-pbar' not in arg_values:
119
+ if "--disable-pbar" not in arg_values:
112
120
  with Loader(desc="Inference ...", end=""):
113
121
  result = expr(*arg_values, **kwargs)
114
122
  else:
@@ -117,50 +125,55 @@ class PackageRunner():
117
125
  if result is not None:
118
126
  self.console(result)
119
127
  else:
120
- self.console("Execution of {} => {} completed successfully.".format(args.alias, package))
128
+ self.console(f"Execution of {args.alias} => {package} completed successfully.")
121
129
 
122
130
  return result
123
131
 
124
132
  def c(self):
125
133
  parser = argparse.ArgumentParser(
126
- description='This will create a new alias entry in the alias json file. Exsisting aliases will be overwritten.',
127
- usage='symrun c <alias> <package>'
134
+ description="This will create a new alias entry in the alias json file. Exsisting aliases will be overwritten.",
135
+ usage="symrun c <alias> <package>",
136
+ )
137
+ parser.add_argument(
138
+ "alias", help="Name of user based on GitHub username and package to install"
139
+ )
140
+ parser.add_argument(
141
+ "package",
142
+ help="Name of the package: <user>/<package> where user is based on GitHub username and package to install",
128
143
  )
129
- parser.add_argument('alias', help='Name of user based on GitHub username and package to install')
130
- parser.add_argument('package', help='Name of the package: <user>/<package> where user is based on GitHub username and package to install')
131
144
  args = parser.parse_args(sys.argv[2:])
132
145
 
133
146
  aliases = self.load_aliases()
134
147
  aliases[args.alias] = args.package
135
148
  self.save_aliases(aliases)
136
- self.console("Alias {} => {} created successfully.".format(args.alias, args.package))
149
+ self.console(f"Alias {args.alias} => {args.package} created successfully.")
137
150
 
138
- def l(self):
151
+ def list_aliases(self):
139
152
  aliases = self.load_aliases()
140
153
  # format the aliases output as a table of key value pairs
141
154
  self.console("Aliases:\n------------------")
142
155
  for alias, package in aliases.items():
143
- self.console(f'{alias} => {package}')
156
+ self.console(f"{alias} => {package}")
144
157
  self.console("------------------")
145
158
 
146
159
  def r(self):
147
160
  parser = argparse.ArgumentParser(
148
- description='This will remove the alias name from the alias json file.',
149
- usage='symrun r <alias>'
161
+ description="This will remove the alias name from the alias json file.",
162
+ usage="symrun r <alias>",
150
163
  )
151
- parser.add_argument('alias', help='Name of alias to remove')
164
+ parser.add_argument("alias", help="Name of alias to remove")
152
165
  args = parser.parse_args(sys.argv[2:])
153
166
 
154
167
  aliases = self.load_aliases()
155
168
  if args.alias in aliases:
156
169
  del aliases[args.alias]
157
170
  self.save_aliases(aliases)
158
- self.console("Alias {} removed successfully.".format(args.alias))
171
+ self.console(f"Alias {args.alias} removed successfully.")
159
172
 
160
173
 
161
174
  def run() -> None:
162
175
  PackageRunner()
163
176
 
164
177
 
165
- if __name__ == '__main__':
178
+ if __name__ == "__main__":
166
179
  run()
@@ -1,9 +1,10 @@
1
1
  from pathlib import Path
2
- from typing import Optional
2
+
3
3
  from git import Repo
4
4
 
5
- from ..symbol import Expression
6
5
  from ..backend.settings import HOME_PATH
6
+ from ..symbol import Expression
7
+ from ..utils import UserMessage
7
8
 
8
9
 
9
10
  class RepositoryCloner(Expression):
@@ -16,9 +17,10 @@ class RepositoryCloner(Expression):
16
17
  repo_path (Optional[str]): The path where to clone the repository.
17
18
  By default it will be at '~/.symai/repos/'.
18
19
  """
19
- def __init__(self, repo_path: Optional[str] = None, **kwargs):
20
+
21
+ def __init__(self, repo_path: str | None = None, **kwargs):
20
22
  super().__init__(**kwargs)
21
- self.repo_dir = HOME_PATH / 'repos/' if repo_path is None else Path(repo_path)
23
+ self.repo_dir = HOME_PATH / "repos/" if repo_path is None else Path(repo_path)
22
24
  if not self.repo_dir.exists():
23
25
  self.repo_dir.mkdir(parents=True, exist_ok=True)
24
26
 
@@ -33,26 +35,26 @@ class RepositoryCloner(Expression):
33
35
  Returns:
34
36
  str: The root path of the cloned repository.
35
37
  """
36
- repo_name = url.split('/')[-1].replace('.git', '')
38
+ repo_name = url.split("/")[-1].replace(".git", "")
37
39
  if (self.repo_dir / repo_name).is_dir():
38
- print(f'Repository {repo_name} already exists. Checking for updates...')
40
+ UserMessage(f"Repository {repo_name} already exists. Checking for updates...")
39
41
  try:
40
42
  repo = Repo(self.repo_dir / repo_name)
41
43
  current = repo.head.commit
42
44
  repo.remotes.origin.pull()
43
45
  if current != repo.head.commit:
44
- print(f'Repository {repo_name} updated.')
46
+ UserMessage(f"Repository {repo_name} updated.")
45
47
  else:
46
- print(f'Repository {repo_name} is up-to-date.')
48
+ UserMessage(f"Repository {repo_name} is up-to-date.")
47
49
  except Exception as e:
48
- print(f'An error occurred: {e}')
50
+ UserMessage(f"An error occurred: {e}")
49
51
  raise e
50
52
  else:
51
- print(f'Cloning repository {repo_name}...')
53
+ UserMessage(f"Cloning repository {repo_name}...")
52
54
  try:
53
55
  Repo.clone_from(url, self.repo_dir / repo_name)
54
- print(f'Repository {repo_name} cloned successfully.')
56
+ UserMessage(f"Repository {repo_name} cloned successfully.")
55
57
  except Exception as e:
56
- print(f'Failed to clone the repository. An error occurred: {e}')
58
+ UserMessage(f"Failed to clone the repository. An error occurred: {e}")
57
59
  raise e
58
60
  return str(self.repo_dir / repo_name)
@@ -4,7 +4,6 @@ from ..pre_processors import PreProcessor
4
4
  from ..prompts import Prompt
5
5
  from ..symbol import Expression, Symbol
6
6
 
7
-
8
7
  SEO_OPTIMIZER_DESCRIPTION = """[Description]
9
8
  You are a SEO query optimizer. You are given a list of queries, phrases or sentences and you need to optimize them for search engines.
10
9
  Assume your search engines are based on vector databases and contain indices of GitHub repositories, papers and other resources.
@@ -17,7 +16,7 @@ The number of resulting queries should be between 1 and 8 statements separated b
17
16
 
18
17
  class SEOQueryOptimizerPreProcessor(PreProcessor):
19
18
  def __call__(self, argument):
20
- return '$> {} =>'.format(str(argument.args[0]))
19
+ return f"$> {argument.args[0]!s} =>"
21
20
 
22
21
 
23
22
  class SEOQueryOptimizer(Expression):
@@ -30,18 +29,21 @@ class SEOQueryOptimizer(Expression):
30
29
  self.sym_return_type = SEOQueryOptimizer
31
30
 
32
31
  def forward(self, sym: Symbol, **kwargs) -> Symbol:
33
- @core.few_shot(prompt="Extract relationships between entities:\n",
34
- examples=Prompt([
35
- '$> John has a dog. =>John dog EOF',
36
- '$> How can i find on wikipedia an article about programming? Preferably about python programming. =>Wikipedia python programming tutorial EOF',
37
- '$> Similarly, the term general linguistics is used to distinguish core linguistics from other types of study =>general linguistics term, core linguistics from other types of study EOF',
38
- ]),
39
- pre_processors=[SEOQueryOptimizerPreProcessor()],
40
- post_processors=[StripPostProcessor()],
41
- stop=['EOF'], **kwargs)
32
+ @core.few_shot(
33
+ prompt="Extract relationships between entities:\n",
34
+ examples=Prompt(
35
+ [
36
+ "$> John has a dog. =>John dog EOF",
37
+ "$> How can i find on wikipedia an article about programming? Preferably about python programming. =>Wikipedia python programming tutorial EOF",
38
+ "$> Similarly, the term general linguistics is used to distinguish core linguistics from other types of study =>general linguistics term, core linguistics from other types of study EOF",
39
+ ]
40
+ ),
41
+ pre_processors=[SEOQueryOptimizerPreProcessor()],
42
+ post_processors=[StripPostProcessor()],
43
+ stop=["EOF"],
44
+ **kwargs,
45
+ )
42
46
  def _func(_, text) -> str:
43
47
  pass
44
48
 
45
49
  return _func(self, sym)
46
-
47
-