symbolicai 1.5.0__py3-none-any.whl → 1.7.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 (52) hide show
  1. symai/__init__.py +21 -71
  2. symai/backend/base.py +0 -26
  3. symai/backend/engines/drawing/engine_gemini_image.py +101 -0
  4. symai/backend/engines/embedding/engine_openai.py +11 -8
  5. symai/backend/engines/neurosymbolic/__init__.py +8 -0
  6. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_chat.py +1 -0
  7. symai/backend/engines/neurosymbolic/engine_anthropic_claudeX_reasoning.py +48 -1
  8. symai/backend/engines/neurosymbolic/engine_cerebras.py +1 -0
  9. symai/backend/engines/neurosymbolic/engine_google_geminiX_reasoning.py +14 -1
  10. symai/backend/engines/neurosymbolic/engine_openrouter.py +294 -0
  11. symai/backend/mixin/__init__.py +4 -0
  12. symai/backend/mixin/anthropic.py +37 -16
  13. symai/backend/mixin/openrouter.py +2 -0
  14. symai/components.py +203 -13
  15. symai/extended/interfaces/nanobanana.py +23 -0
  16. symai/interfaces.py +2 -0
  17. symai/ops/primitives.py +0 -18
  18. symai/shellsv.py +2 -7
  19. symai/strategy.py +44 -4
  20. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/METADATA +3 -10
  21. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/RECORD +25 -48
  22. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/WHEEL +1 -1
  23. symai/backend/driver/webclient.py +0 -217
  24. symai/backend/engines/crawler/engine_selenium.py +0 -94
  25. symai/backend/engines/drawing/engine_dall_e.py +0 -131
  26. symai/backend/engines/embedding/engine_plugin_embeddings.py +0 -12
  27. symai/backend/engines/experiments/engine_bard_wrapper.py +0 -131
  28. symai/backend/engines/experiments/engine_gptfinetuner.py +0 -32
  29. symai/backend/engines/experiments/engine_llamacpp_completion.py +0 -142
  30. symai/backend/engines/neurosymbolic/engine_openai_gptX_completion.py +0 -277
  31. symai/collect/__init__.py +0 -8
  32. symai/collect/dynamic.py +0 -117
  33. symai/collect/pipeline.py +0 -156
  34. symai/collect/stats.py +0 -434
  35. symai/extended/crawler.py +0 -21
  36. symai/extended/interfaces/selenium.py +0 -18
  37. symai/extended/interfaces/vectordb.py +0 -21
  38. symai/extended/personas/__init__.py +0 -3
  39. symai/extended/personas/builder.py +0 -105
  40. symai/extended/personas/dialogue.py +0 -126
  41. symai/extended/personas/persona.py +0 -154
  42. symai/extended/personas/research/__init__.py +0 -1
  43. symai/extended/personas/research/yann_lecun.py +0 -62
  44. symai/extended/personas/sales/__init__.py +0 -1
  45. symai/extended/personas/sales/erik_james.py +0 -62
  46. symai/extended/personas/student/__init__.py +0 -1
  47. symai/extended/personas/student/max_tenner.py +0 -51
  48. symai/extended/strategies/__init__.py +0 -1
  49. symai/extended/strategies/cot.py +0 -40
  50. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/entry_points.txt +0 -0
  51. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/licenses/LICENSE +0 -0
  52. {symbolicai-1.5.0.dist-info → symbolicai-1.7.0.dist-info}/top_level.txt +0 -0
@@ -1,94 +0,0 @@
1
- from typing import Callable
2
- from bs4 import BeautifulSoup
3
-
4
- from ...base import Engine
5
- from ...driver.webclient import connect_browsers, dump_page_source, page_loaded
6
- from ....symbol import Result
7
-
8
-
9
- class SeleniumResult(Result):
10
- def __init__(self, value, **kwargs) -> None:
11
- super().__init__(value, **kwargs)
12
- if value is not None:
13
- self.raw = value
14
- self._value = self.extract()
15
-
16
- def extract(self):
17
- tmp = self.value if isinstance(self.value, list) else [self.value]
18
- res = []
19
- for r in tmp:
20
- if r is None:
21
- continue
22
- soup = BeautifulSoup(r, 'html.parser')
23
- text = soup.getText()
24
- res.append(text)
25
- res = None if len(res) == 0 else '\n'.join(res)
26
- return res
27
-
28
-
29
- class SeleniumEngine(Engine):
30
- def __init__(self, debug: bool = False):
31
- super().__init__()
32
- self.debug = debug
33
- self.driver_handler = None
34
- self.name = self.__class__.__name__
35
-
36
- def _init_crawler_engine(self):
37
- self.driver_handler = connect_browsers(debug=False, proxy=None)
38
-
39
- def get_page_source(self, url: str, pattern: str, script: Callable = None) -> str:
40
- # deprecated
41
- driver = self.driver_handler()
42
- try:
43
- driver.get(url)
44
- with page_loaded(driver, pattern, debug=self.debug):
45
- if script: driver.execute_script(script)
46
- return driver.page_source
47
- except Exception as ex:
48
- if self.debug: dump_page_source(driver)
49
- if self.debug: print(ex)
50
- return f"Sorry, I cannot find the page you are looking for: {ex}"
51
-
52
- def id(self) -> str:
53
- return 'crawler'
54
-
55
- def forward(self, argument):
56
- urls, patterns = argument.prop.prepared_input
57
- urls = urls if isinstance(urls, list) else [urls]
58
-
59
- patterns = patterns if isinstance(patterns, list) else [patterns]
60
- assert len(urls) == len(patterns)
61
- rsp = []
62
-
63
- self._init_crawler_engine()
64
-
65
- for url, p in zip(urls, patterns):
66
- page = self.get_page_source(url=url, pattern=p)
67
- rsp.append(page)
68
-
69
- metadata = {}
70
- rsp = SeleniumResult(rsp)
71
- return [rsp], metadata
72
-
73
- def prepare(self, argument):
74
- assert not argument.prop.processed_input, "CrawlerEngine does not support processed_input."
75
- assert argument.prop.urls, "CrawlerEngine requires urls."
76
-
77
- argument.prop.urls = [str(argument.prop.url)]
78
- argument.prop.patterns = [str(argument.prop.pattern)]
79
-
80
- # be tolerant to kwarg or arg and assign values of urls and patterns
81
- # assign urls
82
- if len(argument.args) >= 1:
83
- argument.prop.urls = argument.args[0]
84
- elif len(argument.kwargs) >= 1:
85
- keys = list(argument.kwargs.keys())
86
- argument.prop.urls = argument.kwargs[keys[0]]
87
- # assign patterns
88
- if len(argument.args) >= 2:
89
- argument.prop.patterns = argument.args[1]
90
- elif len(argument.kwargs) >= 2:
91
- keys = list(argument.kwargs.keys())
92
- argument.prop.patterns = argument.kwargs[keys[1]]
93
-
94
- argument.prop.prepared_input = (argument.prop.urls, argument.prop.patterns)
@@ -1,131 +0,0 @@
1
- import logging
2
- import openai
3
- import requests
4
- import tempfile
5
-
6
- from typing import Optional
7
-
8
- from ...base import Engine
9
- from ...settings import SYMAI_CONFIG
10
- from ....symbol import Result
11
-
12
-
13
- logging.getLogger("openai").setLevel(logging.ERROR)
14
- logging.getLogger("requests").setLevel(logging.ERROR)
15
- logging.getLogger("urllib").setLevel(logging.ERROR)
16
- logging.getLogger("httpx").setLevel(logging.ERROR)
17
- logging.getLogger("httpcore").setLevel(logging.ERROR)
18
-
19
-
20
- class DalleResult(Result):
21
- def __init__(self, value, **kwargs) -> None:
22
- super().__init__(value, **kwargs)
23
- # unpack the result
24
- if hasattr(value, 'data') and len(value.data) > 0:
25
- self._value = value.data[0].url
26
-
27
- # use tempfile to download the image
28
- def download_images(self):
29
- if not hasattr(self.value, 'data') or len(self.value.data) <= 0:
30
- return None
31
- files = []
32
- # download the images
33
- for url in enumerate(self.value.data):
34
- path = tempfile.NamedTemporaryFile(suffix='.png').name
35
- r = requests.get(url, allow_redirects=True)
36
- with open(path, 'wb') as f:
37
- f.write(r.content)
38
- files.append(path)
39
- return files
40
-
41
-
42
- class DrawingEngine(Engine):
43
- def __init__(self, size: int = 1024, api_key: Optional[str] = None, model: Optional[str] = None):
44
- super().__init__()
45
- self.config = SYMAI_CONFIG
46
- openai.api_key = self.config['DRAWING_ENGINE_API_KEY'] if api_key is None else api_key
47
- self.model = self.config['DRAWING_ENGINE_MODEL'] if model is None else model
48
- logger = logging.getLogger('openai')
49
- logger.setLevel(logging.WARNING)
50
- self.size = size # defaults to 1024 instead of 512 because dall-e-3 requires 1024
51
-
52
- def id(self) -> str:
53
- if self.config['DRAWING_ENGINE_API_KEY'] and self.config['DRAWING_ENGINE_MODEL'].startswith("dall-e"):
54
- return 'drawing'
55
- return super().id() # default to unregistered
56
-
57
- def command(self, *args, **kwargs):
58
- super().command(*args, **kwargs)
59
- if 'DRAWING_ENGINE_API_KEY' in kwargs:
60
- openai.api_key = kwargs['DRAWING_ENGINE_API_KEY']
61
- if 'DRAWING_ENGINE_MODEL' in kwargs:
62
- self.model = kwargs['DRAWING_ENGINE_MODEL']
63
-
64
- def forward(self, argument):
65
- prompt = argument.prop.prepared_input
66
- kwargs = argument.kwargs
67
- model = kwargs.get('model', self.model)
68
- size = f"{kwargs['image_size']}x{kwargs['image_size']}" if 'image_size' in kwargs else f"{self.size}x{self.size}"
69
- n = kwargs.get('n', 1)
70
- quality = kwargs.get('quality', 'standard')
71
- response_format = kwargs.get('response_format', 'url')
72
- style = kwargs.get('style', 'vivid')
73
- except_remedy = kwargs['except_remedy'] if 'except_remedy' in kwargs else None
74
-
75
- callback = None
76
- try:
77
- if kwargs['operation'] == 'create':
78
-
79
- callback = openai.images.generate
80
- res = openai.images.generate(
81
- model=model,
82
- prompt=prompt,
83
- n=n,
84
- size=size,
85
- quality=quality,
86
- response_format=response_format,
87
- style=style,
88
- )
89
- elif kwargs['operation'] == 'variation':
90
- assert 'image_path' in kwargs
91
- image_path = kwargs['image_path']
92
-
93
- callback = openai.images.create_variation
94
- res = openai.images.create_variation(
95
- model=model,
96
- image=open(image_path, "rb"),
97
- n=n,
98
- size=size,
99
- response_format=response_format,
100
- )
101
- elif kwargs['operation'] == 'edit':
102
- assert 'mask_path' in kwargs
103
- assert 'image_path' in kwargs
104
- mask_path = kwargs['mask_path']
105
- image_path = kwargs['image_path']
106
-
107
- callback = openai.images.edit
108
- res = openai.images.edit(
109
- model=model,
110
- image=open(image_path, "rb"),
111
- mask=open(mask_path, "rb"),
112
- prompt=prompt,
113
- n=n,
114
- size=size,
115
- response_format=response_format,
116
- )
117
- else:
118
- raise Exception(f"Unknown operation: {kwargs['operation']}")
119
-
120
- except Exception as e:
121
- if except_remedy is None:
122
- raise e
123
- res = except_remedy(self, e, callback, argument)
124
-
125
- metadata = {}
126
-
127
- rsp = DalleResult(res)
128
- return [rsp], metadata
129
-
130
- def prepare(self, argument):
131
- argument.prop.prepared_input = str(argument.prop.processed_input)
@@ -1,12 +0,0 @@
1
- from ...base import Engine
2
- from ...settings import SYMAI_CONFIG
3
-
4
-
5
- class PluginEmbeddingEngine(Engine):
6
- def id(self) -> str:
7
- if not SYMAI_CONFIG['EMBEDDING_ENGINE_API_KEY'] and not SYMAI_CONFIG['EMBEDDING_ENGINE_MODEL'].startswith("llama"):
8
- from ....functional import EngineRepository
9
-
10
- # Register the embedding engine from the plugin
11
- EngineRepository.register_from_plugin('embedding', plugin='ExtensityAI/embeddings', kwargs={'model': 'all-mpnet-base-v2'}, allow_engine_override=True)
12
- return super().id() # do not register this engine as we want the plugin to be used
@@ -1,131 +0,0 @@
1
- import logging
2
- from typing import List
3
-
4
- import requests
5
- import tiktoken
6
- from bardapi import Bard
7
-
8
- from ...base import Engine
9
- from ...mixin.openai import OpenAIMixin
10
- from ...settings import SYMAI_CONFIG
11
-
12
-
13
- class BardEngine(Engine, OpenAIMixin):
14
- def __init__(self, timeout: int = 30):
15
- super().__init__()
16
- self.timeout = timeout
17
- config = SYMAI_CONFIG
18
- self.api_key = config['NEUROSYMBOLIC_ENGINE_API_KEY']
19
- self.model = config['NEUROSYMBOLIC_ENGINE_MODEL']
20
- logger = logging.getLogger('openai')
21
- self.tokenizer = tiktoken.encoding_for_model(self.model)
22
- self.max_tokens = self.api_max_tokens()
23
- self.bard = None
24
- logger.setLevel(logging.WARNING)
25
-
26
- def init_session(self):
27
- self.session = requests.Session()
28
- self.session.headers = {
29
- "Host": "bard.google.com",
30
- "X-Same-Domain": "1",
31
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
32
- "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
33
- "Origin": "https://bard.google.com",
34
- "Referer": "https://bard.google.com/",
35
- }
36
- self.session.cookies.set("__Secure-1PSID", self.api_key)
37
- self.bard = Bard(token=self.api_key,
38
- session=self.session,
39
- timeout=self.timeout)
40
-
41
- def id(self) -> str:
42
- if self.config['NEUROSYMBOLIC_ENGINE_MODEL'] and \
43
- (self.config['NEUROSYMBOLIC_ENGINE_MODEL'].startswith('bard')):
44
- return 'neurosymbolic'
45
- return super().id() # default to unregistered
46
-
47
- def command(self, *args, **kwargs):
48
- super().command(*args, **kwargs)
49
- if 'NEUROSYMBOLIC_ENGINE_API_KEY' in kwargs:
50
- self.api_key = kwargs['NEUROSYMBOLIC_ENGINE_API_KEY']
51
- if 'NEUROSYMBOLIC_ENGINE_MODEL' in kwargs:
52
- self.model = kwargs['NEUROSYMBOLIC_ENGINE_MODEL']
53
-
54
- def compute_remaining_tokens(self, prompts: list) -> int:
55
- # iterate over prompts and compute number of tokens
56
- prompt = prompts[0]
57
- val = len(self.tokenizer.encode(prompt))
58
- return int((self.max_tokens - val) * 0.98)
59
-
60
- def forward(self, argument):
61
- if self.bard is None:
62
- self.init_session()
63
-
64
- kwargs = argument.kwargs
65
- prompts_ = argument.prop.prepared_input
66
- prompts_ = prompts_ if isinstance(prompts_, list) else [prompts_]
67
- except_remedy = kwargs['except_remedy'] if 'except_remedy' in kwargs else None
68
-
69
- try:
70
- res = self.bard.get_answer(prompts_[0])
71
- except Exception as e:
72
- if except_remedy is None:
73
- raise e
74
- callback = self.connection.root.predict
75
- res = except_remedy(self, e, callback, argument)
76
-
77
- metadata = {}
78
-
79
- rsp = [res['content']]
80
- output = rsp if isinstance(prompts_, list) else rsp[0]
81
- return output, metadata
82
-
83
- def prepare(self, argument):
84
- if argument.prop.raw_input:
85
- if not argument.prop.processed_input:
86
- raise ValueError('Need to provide a prompt instruction to the engine if raw_input is enabled.')
87
- argument.prop.prepared_input = argument.prop.processed_input
88
- return
89
-
90
- user: str = ""
91
- system: str = ""
92
- system = f'{system}\n' if system and len(system) > 0 else ''
93
-
94
- ref = argument.prop.instance
95
- static_ctxt, dyn_ctxt = ref.global_context
96
- if len(static_ctxt) > 0:
97
- system += f"[STATIC CONTEXT]\n{static_ctxt}\n\n"
98
-
99
- if len(dyn_ctxt) > 0:
100
- system += f"[DYNAMIC CONTEXT]\n{dyn_ctxt}\n\n"
101
-
102
- payload = argument.prop.payload
103
- if payload is not None:
104
- system += f"[ADDITIONAL CONTEXT]\n{payload}\n\n"
105
-
106
- examples: List[str] = argument.prop.examples
107
- if examples and len(examples) > 0:
108
- system += f"[EXAMPLES]\n{str(examples)}\n\n"
109
-
110
- if argument.prop.prompt is not None and len(argument.prop.prompt) > 0:
111
- val = str(argument.prop.prompt)
112
- system += f"[INSTRUCTION]\n{val}"
113
-
114
- suffix: str = str(argument.prop.processed_input)
115
- if '=>' in suffix:
116
- user += f"[LAST TASK]\n"
117
-
118
- if '[SYSTEM_INSTRUCTION::]: <<<' in suffix and argument.prop.parse_system_instructions:
119
- parts = suffix.split('\n>>>\n')
120
- # first parts are the system instructions
121
- for p in parts[:-1]:
122
- system += f"{p}\n"
123
- # last part is the user input
124
- suffix = parts[-1]
125
- user += f"{suffix}"
126
-
127
- if argument.prop.template_suffix is not None:
128
- user += f"\n[[PLACEHOLDER]]\n{argument.prop.template_suffix}\n\n"
129
- user += f"Only generate content for the placeholder `[[PLACEHOLDER]]` following the instructions and context information. Do NOT write `[[PLACEHOLDER]]` or anything else in your output.\n\n"
130
-
131
- argument.prop.prepared_input = [f'---------SYSTEM BEHAVIOR--------\n{system}\n\n---------USER REQUEST--------\n{user}']
@@ -1,32 +0,0 @@
1
- import os
2
- from typing import List
3
-
4
- import openai
5
-
6
- from ....utils import Args
7
- from ...base import Engine
8
- from ...settings import SYMAI_CONFIG
9
-
10
-
11
- class GPTFineTuner(Engine):
12
- def __init__(self):
13
- super().__init__()
14
- config = SYMAI_CONFIG
15
- openai.api_key = config['NEUROSYMBOLIC_ENGINE_API_KEY']
16
- self.base_model = "babbage"
17
-
18
- def forward(self, argument):
19
- kwargs = argument.kwargs
20
- assert '__cmd__' in kwargs, "Missing __cmd__ argument"
21
- rsp = None
22
-
23
- raise NotImplementedError("GPTFineTuner is not implemented yet")
24
-
25
- del kwargs['__cmd__']
26
-
27
- metadata = {}
28
-
29
- return [rsp], metadata
30
-
31
- def prepare(self, argument):
32
- assert not argument.prop.processed_input, "GPTFineTuner does not support processed_input."
@@ -1,142 +0,0 @@
1
- import logging
2
- from typing import List
3
-
4
- from ...base import Engine
5
- from ...settings import SYMAI_CONFIG
6
-
7
- import requests
8
- import json
9
-
10
-
11
- class LLaMACppCompletionClient():
12
- def __init__(self, base_url="http://localhost:8000"):
13
- self.base_url = base_url
14
-
15
- def create_completion(self, completion_request):
16
- # Preparing header information
17
- headers = {
18
- 'Content-Type': 'application/json',
19
- 'Accept': 'application/json'
20
- }
21
-
22
- # Performing POST request
23
- response = requests.post(f"{self.base_url}/v1/engines/copilot-codex/completions",
24
- data=json.dumps(completion_request),
25
- headers=headers)
26
-
27
- print(response)
28
-
29
- # Parsing response
30
- if response.status_code == 200:
31
- return json.loads(response.text)
32
- else:
33
- raise Exception(f"Request failed with status code {response.status_code}")
34
-
35
-
36
- class LLaMACppCompletionEngine(Engine):
37
- def __init__(self):
38
- super().__init__()
39
- config = SYMAI_CONFIG
40
- self.model = config['NEUROSYMBOLIC_ENGINE_MODEL']
41
- logger = logging.getLogger('LLaMA')
42
- logger.setLevel(logging.WARNING)
43
-
44
- self.client = LLaMACppCompletionClient() # Initialize LLaMACpp client here
45
-
46
- def command(self, *args, **kwargs):
47
- super().command(*args, **kwargs)
48
- if 'NEUROSYMBOLIC_ENGINE_MODEL' in kwargs:
49
- self.model = kwargs['NEUROSYMBOLIC_ENGINE_MODEL']
50
-
51
- def forward(self, argument):
52
- prompts_ = argument.prop.prepared_input
53
- prompts_ = prompts_ if isinstance(prompts_, list) else [prompts_]
54
- kwargs = argument.kwargs
55
- max_tokens = kwargs['max_tokens'] if 'max_tokens' in kwargs else 4096
56
- temperature = kwargs['temperature'] if 'temperature' in kwargs else 0.7
57
- top_p = kwargs['top_p'] if 'top_p' in kwargs else 1
58
- except_remedy = kwargs['except_remedy'] if 'except_remedy' in kwargs else None
59
-
60
- completion_request = {
61
- "prompt": prompts_,
62
- "stop": ["\n\n", "-------"]
63
- #"max_tokens": max_tokens,
64
- #"temperature": temperature,
65
- #"top_p": top_p,
66
- #"mirostat_mode": 0,
67
- #"mirostat_tau": 0.2,
68
- #"mirostat_eta": 0.5,
69
- #"echo": False
70
- }
71
-
72
- try:
73
- print(completion_request)
74
- res = self.client.create_completion(completion_request)
75
- except Exception as e:
76
- if except_remedy is None:
77
- raise e
78
- callback = self.connection.root.predict
79
- res = except_remedy(self, e, callback, argument)
80
-
81
-
82
- metadata = {}
83
-
84
- rsp = [r['text'] for r in res['choices']]
85
- output = rsp if isinstance(prompts_, list) else rsp[0]
86
- return output, metadata
87
-
88
- def prepare(self, argument):
89
- if argument.prop.raw_input:
90
- if not argument.prop.processed_input:
91
- raise ValueError('Need to provide a prompt instruction to the engine if raw_input is enabled.')
92
- argument.prop.prepared_input = argument.prop.processed_input
93
- return
94
-
95
- user: str = ""
96
- system: str = ""
97
- system = f'{system}\n' if system and len(system) > 0 else ''
98
-
99
- ref = argument.prop.instance
100
- static_ctxt, dyn_ctxt = ref.global_context
101
- if len(static_ctxt) > 0:
102
- system += f"[STATIC CONTEXT]\n{static_ctxt}\n\n"
103
-
104
- if len(dyn_ctxt) > 0:
105
- system += f"[DYNAMIC CONTEXT]\n{dyn_ctxt}\n\n"
106
-
107
- payload = argument.prop.payload
108
- if payload is not None:
109
- system += f"[ADDITIONAL CONTEXT]\n{str(payload)}\n\n"
110
-
111
- examples: List[str] = argument.prop.examples
112
- if examples and len(examples) > 0:
113
- system += f"[EXAMPLES]\n{str(examples)}\n\n"
114
-
115
- if argument.prop.prompt is not None and len(argument.prop.prompt) > 0:
116
- val = str(argument.prop.prompt)
117
- system += f"[INSTRUCTION]\n{val}"
118
-
119
- suffix: str = str(argument.prop.processed_input)
120
- if '=>' in suffix:
121
- user += f"[LAST TASK]\n"
122
-
123
- if '[SYSTEM_INSTRUCTION::]: <<<' in suffix and argument.prop.parse_system_instructions:
124
- parts = suffix.split('\n>>>\n')
125
- # first parts are the system instructions
126
- for p in parts[:-1]:
127
- system += f"{p}\n"
128
- # last part is the user input
129
- suffix = parts[-1]
130
- user += f"{suffix}"
131
-
132
- if argument.prop.template_suffix is not None:
133
- user += f"\n[[PLACEHOLDER]]\n{str(argument.prop.template_suffix)}\n\n"
134
- user += f"Only generate content for the placeholder `[[PLACEHOLDER]]` following the instructions and context information. Do NOT write `[[PLACEHOLDER]]` or anything else in your output.\n\n"
135
-
136
- argument.prop.prepared_input = [f'---------SYSTEM BEHAVIOR--------\n{system}\n\n---------USER REQUEST--------\n{user}']
137
-
138
-
139
- if __name__ == '__main__':
140
- engine = LLaMACppCompletionEngine()
141
- res = engine.forward(["\n\n### Instructions:\nWhat is the capital of Romania?\n\n### Response:\n"])
142
- print(res)