jaclang 0.7.14__py3-none-any.whl → 0.7.16__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.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/cli/cli.py +15 -10
- jaclang/cli/cmdreg.py +9 -12
- jaclang/compiler/__init__.py +19 -53
- jaclang/compiler/absyntree.py +86 -13
- jaclang/compiler/jac.lark +4 -3
- jaclang/compiler/parser.py +31 -23
- jaclang/compiler/passes/ir_pass.py +4 -13
- jaclang/compiler/passes/main/access_modifier_pass.py +1 -1
- jaclang/compiler/passes/main/fuse_typeinfo_pass.py +4 -5
- jaclang/compiler/passes/main/import_pass.py +18 -23
- jaclang/compiler/passes/main/pyast_gen_pass.py +307 -559
- jaclang/compiler/passes/main/pyast_load_pass.py +32 -6
- jaclang/compiler/passes/main/registry_pass.py +37 -3
- jaclang/compiler/passes/main/sym_tab_build_pass.py +1 -1
- jaclang/compiler/passes/main/tests/__init__.py +1 -1
- jaclang/compiler/passes/main/type_check_pass.py +7 -0
- jaclang/compiler/passes/tool/jac_formatter_pass.py +124 -86
- jaclang/compiler/passes/tool/tests/fixtures/corelib_fmt.jac +0 -1
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/architype_test.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comment_alignment.jac +11 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/comments.jac +13 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/decorator_stack.jac +37 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/esc_keywords.jac +5 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/long_names.jac +19 -0
- jaclang/compiler/passes/tool/tests/fixtures/general_format_checks/triple_quoted_string.jac +6 -0
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +11 -0
- jaclang/compiler/passes/tool/tests/test_unparse_validate.py +33 -39
- jaclang/compiler/passes/transform.py +4 -0
- jaclang/compiler/semtable.py +31 -7
- jaclang/compiler/tests/test_importer.py +12 -5
- jaclang/langserve/engine.py +65 -118
- jaclang/langserve/sem_manager.py +379 -0
- jaclang/langserve/server.py +8 -10
- jaclang/langserve/tests/fixtures/base_module_structure.jac +27 -6
- jaclang/langserve/tests/fixtures/circle.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_err.jac +3 -3
- jaclang/langserve/tests/fixtures/circle_pure.test.jac +3 -3
- jaclang/langserve/tests/fixtures/import_include_statements.jac +1 -1
- jaclang/langserve/tests/test_sem_tokens.py +277 -0
- jaclang/langserve/tests/test_server.py +72 -16
- jaclang/langserve/utils.py +163 -96
- jaclang/plugin/builtin.py +1 -1
- jaclang/plugin/default.py +212 -24
- jaclang/plugin/feature.py +59 -11
- jaclang/plugin/spec.py +58 -6
- jaclang/{core → runtimelib}/architype.py +1 -1
- jaclang/{core → runtimelib}/context.py +8 -1
- jaclang/runtimelib/importer.py +361 -0
- jaclang/runtimelib/machine.py +94 -0
- jaclang/{core → runtimelib}/utils.py +13 -5
- jaclang/settings.py +4 -1
- jaclang/tests/fixtures/abc.jac +3 -3
- jaclang/tests/fixtures/byllmissue.jac +1 -5
- jaclang/tests/fixtures/chandra_bugs2.jac +11 -10
- jaclang/tests/fixtures/cls_method.jac +41 -0
- jaclang/tests/fixtures/dblhello.jac +6 -0
- jaclang/tests/fixtures/deep/one_lev.jac +3 -3
- jaclang/tests/fixtures/deep/one_lev_dup.jac +2 -3
- jaclang/tests/fixtures/deep_import_mods.jac +13 -0
- jaclang/tests/fixtures/err.impl.jac +3 -0
- jaclang/tests/fixtures/err.jac +4 -2
- jaclang/tests/fixtures/err.test.jac +3 -0
- jaclang/tests/fixtures/err_runtime.jac +15 -0
- jaclang/tests/fixtures/game1.jac +1 -1
- jaclang/tests/fixtures/hello.jac +4 -0
- jaclang/tests/fixtures/impl_grab.impl.jac +2 -1
- jaclang/tests/fixtures/impl_grab.jac +4 -1
- jaclang/tests/fixtures/jp_importer_auto.jac +14 -0
- jaclang/tests/fixtures/maxfail_run_test.jac +4 -4
- jaclang/tests/fixtures/needs_import.jac +2 -2
- jaclang/tests/fixtures/pyfunc_2.py +3 -0
- jaclang/tests/fixtures/registry.jac +9 -0
- jaclang/tests/fixtures/run_test.jac +4 -4
- jaclang/tests/fixtures/semstr.jac +1 -4
- jaclang/tests/fixtures/simple_archs.jac +1 -1
- jaclang/tests/test_cli.py +65 -2
- jaclang/tests/test_language.py +74 -7
- jaclang/tests/test_reference.py +6 -0
- jaclang/utils/helpers.py +45 -21
- jaclang/utils/test.py +9 -0
- jaclang/utils/treeprinter.py +0 -4
- {jaclang-0.7.14.dist-info → jaclang-0.7.16.dist-info}/METADATA +3 -2
- {jaclang-0.7.14.dist-info → jaclang-0.7.16.dist-info}/RECORD +89 -74
- jaclang/core/importer.py +0 -344
- jaclang/tests/fixtures/aott_raise.jac +0 -25
- jaclang/tests/fixtures/package_import.jac +0 -6
- /jaclang/{core → runtimelib}/__init__.py +0 -0
- /jaclang/{core → runtimelib}/constructs.py +0 -0
- /jaclang/{core → runtimelib}/memory.py +0 -0
- /jaclang/{core → runtimelib}/test.py +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.16.dist-info}/WHEEL +0 -0
- {jaclang-0.7.14.dist-info → jaclang-0.7.16.dist-info}/entry_points.txt +0 -0
jaclang/core/importer.py
DELETED
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
"""Special Imports for Jac Code."""
|
|
2
|
-
|
|
3
|
-
import importlib
|
|
4
|
-
import marshal
|
|
5
|
-
import os
|
|
6
|
-
import sys
|
|
7
|
-
import types
|
|
8
|
-
from os import getcwd, path
|
|
9
|
-
from typing import Optional, Union
|
|
10
|
-
|
|
11
|
-
from jaclang.compiler.absyntree import Module
|
|
12
|
-
from jaclang.compiler.compile import compile_jac
|
|
13
|
-
from jaclang.compiler.constant import Constants as Con
|
|
14
|
-
from jaclang.core.utils import sys_path_context
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def handle_directory(
|
|
18
|
-
module_name: str, full_mod_path: str, mod_bundle: Optional[Module]
|
|
19
|
-
) -> types.ModuleType:
|
|
20
|
-
"""Import from a directory that potentially contains multiple Jac modules."""
|
|
21
|
-
module = types.ModuleType(module_name)
|
|
22
|
-
module.__name__ = module_name
|
|
23
|
-
module.__path__ = [full_mod_path]
|
|
24
|
-
module.__file__ = None
|
|
25
|
-
module.__dict__["__jac_mod_bundle__"] = mod_bundle
|
|
26
|
-
if module_name not in sys.modules:
|
|
27
|
-
sys.modules[module_name] = module
|
|
28
|
-
return module
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def process_items(
|
|
32
|
-
module: types.ModuleType,
|
|
33
|
-
items: dict[str, Union[str, Optional[str]]],
|
|
34
|
-
caller_dir: str,
|
|
35
|
-
lang: Optional[str],
|
|
36
|
-
mod_bundle: Optional[Module] = None,
|
|
37
|
-
cachable: bool = True,
|
|
38
|
-
) -> list:
|
|
39
|
-
"""Process items within a module by handling renaming and potentially loading missing attributes."""
|
|
40
|
-
unique_loaded_items = []
|
|
41
|
-
|
|
42
|
-
def handle_item_loading(item: str, alias: Union[str, Optional[str]]) -> None:
|
|
43
|
-
if item:
|
|
44
|
-
unique_loaded_items.append(item)
|
|
45
|
-
setattr(module, name, item)
|
|
46
|
-
if alias and alias != name and not isinstance(alias, bool):
|
|
47
|
-
setattr(module, alias, item)
|
|
48
|
-
|
|
49
|
-
for name, alias in items.items():
|
|
50
|
-
try:
|
|
51
|
-
item = getattr(module, name)
|
|
52
|
-
handle_item_loading(item, alias)
|
|
53
|
-
except AttributeError:
|
|
54
|
-
if lang == "jac":
|
|
55
|
-
jac_file_path = (
|
|
56
|
-
os.path.join(module.__path__[0], f"{name}.jac")
|
|
57
|
-
if hasattr(module, "__path__")
|
|
58
|
-
else module.__file__
|
|
59
|
-
)
|
|
60
|
-
if jac_file_path and os.path.isfile(jac_file_path):
|
|
61
|
-
item = load_jac_file(
|
|
62
|
-
module=module,
|
|
63
|
-
name=name,
|
|
64
|
-
jac_file_path=jac_file_path,
|
|
65
|
-
mod_bundle=mod_bundle,
|
|
66
|
-
cachable=cachable,
|
|
67
|
-
caller_dir=caller_dir,
|
|
68
|
-
)
|
|
69
|
-
handle_item_loading(item, alias)
|
|
70
|
-
elif jac_file_path and os.path.isdir(jac_file_path[:-4]):
|
|
71
|
-
item = handle_directory(name, jac_file_path[:-4], mod_bundle)
|
|
72
|
-
handle_item_loading(item, alias)
|
|
73
|
-
else:
|
|
74
|
-
if hasattr(module, "__path__"):
|
|
75
|
-
full_module_name = f"{module.__name__}.{name}"
|
|
76
|
-
item = importlib.import_module(full_module_name)
|
|
77
|
-
handle_item_loading(item, alias)
|
|
78
|
-
return unique_loaded_items
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def load_jac_file(
|
|
82
|
-
module: types.ModuleType,
|
|
83
|
-
name: str,
|
|
84
|
-
jac_file_path: str,
|
|
85
|
-
mod_bundle: Optional[Module],
|
|
86
|
-
cachable: bool,
|
|
87
|
-
caller_dir: str,
|
|
88
|
-
) -> Optional[types.ModuleType]:
|
|
89
|
-
"""Load a single .jac file into the specified module component."""
|
|
90
|
-
try:
|
|
91
|
-
package_name = (
|
|
92
|
-
f"{module.__name__}.{name}"
|
|
93
|
-
if hasattr(module, "__path__")
|
|
94
|
-
else module.__name__
|
|
95
|
-
)
|
|
96
|
-
new_module = sys.modules.get(
|
|
97
|
-
package_name,
|
|
98
|
-
create_jac_py_module(mod_bundle, name, module.__name__, jac_file_path),
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
codeobj = get_codeobj(
|
|
102
|
-
full_target=jac_file_path,
|
|
103
|
-
module_name=name,
|
|
104
|
-
mod_bundle=mod_bundle,
|
|
105
|
-
cachable=cachable,
|
|
106
|
-
caller_dir=caller_dir,
|
|
107
|
-
)
|
|
108
|
-
if not codeobj:
|
|
109
|
-
raise ImportError(f"No bytecode found for {jac_file_path}")
|
|
110
|
-
|
|
111
|
-
exec(codeobj, new_module.__dict__)
|
|
112
|
-
return getattr(new_module, name, new_module)
|
|
113
|
-
except ImportError as e:
|
|
114
|
-
print(
|
|
115
|
-
f"Failed to load {name} from {jac_file_path} in {module.__name__}: {str(e)}"
|
|
116
|
-
)
|
|
117
|
-
return None
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
def get_codeobj(
|
|
121
|
-
full_target: str,
|
|
122
|
-
module_name: str,
|
|
123
|
-
mod_bundle: Optional[Module],
|
|
124
|
-
cachable: bool,
|
|
125
|
-
caller_dir: str,
|
|
126
|
-
) -> Optional[types.CodeType]:
|
|
127
|
-
"""Execcutes the code for a given module."""
|
|
128
|
-
if mod_bundle:
|
|
129
|
-
codeobj = mod_bundle.mod_deps[full_target].gen.py_bytecode
|
|
130
|
-
return marshal.loads(codeobj) if isinstance(codeobj, bytes) else None
|
|
131
|
-
gen_dir = os.path.join(caller_dir, Con.JAC_GEN_DIR)
|
|
132
|
-
pyc_file_path = os.path.join(gen_dir, module_name + ".jbc")
|
|
133
|
-
if cachable and os.path.exists(pyc_file_path):
|
|
134
|
-
with open(pyc_file_path, "rb") as f:
|
|
135
|
-
return marshal.load(f)
|
|
136
|
-
|
|
137
|
-
result = compile_jac(full_target, cache_result=cachable)
|
|
138
|
-
if result.errors_had or not result.ir.gen.py_bytecode:
|
|
139
|
-
for e in result.errors_had:
|
|
140
|
-
print(e)
|
|
141
|
-
return None
|
|
142
|
-
if result.ir.gen.py_bytecode is not None:
|
|
143
|
-
return marshal.loads(result.ir.gen.py_bytecode)
|
|
144
|
-
else:
|
|
145
|
-
return None
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def jac_importer(
|
|
149
|
-
target: str,
|
|
150
|
-
base_path: str,
|
|
151
|
-
absorb: bool = False,
|
|
152
|
-
cachable: bool = True,
|
|
153
|
-
mdl_alias: Optional[str] = None,
|
|
154
|
-
override_name: Optional[str] = None,
|
|
155
|
-
mod_bundle: Optional[Module | str] = None,
|
|
156
|
-
lng: Optional[str] = "jac",
|
|
157
|
-
items: Optional[dict[str, Union[str, Optional[str]]]] = None,
|
|
158
|
-
) -> tuple[types.ModuleType, ...]:
|
|
159
|
-
"""Core Import Process."""
|
|
160
|
-
unique_loaded_items = []
|
|
161
|
-
dir_path, file_name = path.split(path.join(*(target.split("."))))
|
|
162
|
-
module_name = path.splitext(file_name)[0]
|
|
163
|
-
package_path = dir_path.replace(path.sep, ".")
|
|
164
|
-
if (
|
|
165
|
-
not override_name
|
|
166
|
-
and package_path
|
|
167
|
-
and f"{package_path}.{module_name}" in sys.modules
|
|
168
|
-
):
|
|
169
|
-
module = sys.modules[f"{package_path}.{module_name}"]
|
|
170
|
-
elif not override_name and not package_path and module_name in sys.modules:
|
|
171
|
-
module = sys.modules[module_name]
|
|
172
|
-
else:
|
|
173
|
-
module = None
|
|
174
|
-
valid_mod_bundle = (
|
|
175
|
-
sys.modules[mod_bundle].__jac_mod_bundle__
|
|
176
|
-
if isinstance(mod_bundle, str)
|
|
177
|
-
and mod_bundle in sys.modules
|
|
178
|
-
and "__jac_mod_bundle__" in sys.modules[mod_bundle].__dict__
|
|
179
|
-
else None
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
caller_dir = get_caller_dir(target, base_path, dir_path)
|
|
183
|
-
full_target = path.normpath(path.join(caller_dir, file_name))
|
|
184
|
-
if not module:
|
|
185
|
-
if os.path.isdir(full_target):
|
|
186
|
-
module = handle_directory(module_name, full_target, valid_mod_bundle)
|
|
187
|
-
else:
|
|
188
|
-
full_target += ".jac" if lng == "jac" else ".py"
|
|
189
|
-
module_name = path.splitext(file_name)[0]
|
|
190
|
-
package_path = dir_path.replace(path.sep, ".")
|
|
191
|
-
|
|
192
|
-
if lng == "py":
|
|
193
|
-
module, *unique_loaded_items = py_import(
|
|
194
|
-
target=target,
|
|
195
|
-
items=items,
|
|
196
|
-
absorb=absorb,
|
|
197
|
-
mdl_alias=mdl_alias,
|
|
198
|
-
caller_dir=caller_dir,
|
|
199
|
-
)
|
|
200
|
-
else:
|
|
201
|
-
module_name = override_name if override_name else module_name
|
|
202
|
-
module = create_jac_py_module(
|
|
203
|
-
valid_mod_bundle,
|
|
204
|
-
module_name,
|
|
205
|
-
package_path,
|
|
206
|
-
full_target,
|
|
207
|
-
)
|
|
208
|
-
codeobj = get_codeobj(
|
|
209
|
-
full_target,
|
|
210
|
-
module_name,
|
|
211
|
-
valid_mod_bundle,
|
|
212
|
-
cachable,
|
|
213
|
-
caller_dir=caller_dir,
|
|
214
|
-
)
|
|
215
|
-
try:
|
|
216
|
-
if not codeobj:
|
|
217
|
-
raise ImportError(f"No bytecode found for {full_target}")
|
|
218
|
-
with sys_path_context(caller_dir):
|
|
219
|
-
exec(codeobj, module.__dict__)
|
|
220
|
-
except Exception as e:
|
|
221
|
-
raise ImportError(f"Error importing {full_target}: {str(e)}")
|
|
222
|
-
unique_loaded_items = (
|
|
223
|
-
process_items(
|
|
224
|
-
module=module,
|
|
225
|
-
items=items,
|
|
226
|
-
caller_dir=caller_dir,
|
|
227
|
-
mod_bundle=valid_mod_bundle,
|
|
228
|
-
cachable=cachable,
|
|
229
|
-
lang=lng,
|
|
230
|
-
)
|
|
231
|
-
if items
|
|
232
|
-
else []
|
|
233
|
-
)
|
|
234
|
-
return (module,) if absorb or not items else tuple(unique_loaded_items)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
def create_jac_py_module(
|
|
238
|
-
mod_bundle: Optional[Module],
|
|
239
|
-
module_name: str,
|
|
240
|
-
package_path: str,
|
|
241
|
-
full_target: str,
|
|
242
|
-
) -> types.ModuleType:
|
|
243
|
-
"""Create a module."""
|
|
244
|
-
module = types.ModuleType(module_name)
|
|
245
|
-
module.__file__ = full_target
|
|
246
|
-
module.__name__ = module_name
|
|
247
|
-
module.__dict__["__jac_mod_bundle__"] = mod_bundle
|
|
248
|
-
if package_path:
|
|
249
|
-
parts = package_path.split(".")
|
|
250
|
-
base_path = full_target.split(package_path.replace(".", path.sep))[0]
|
|
251
|
-
for i in range(len(parts)):
|
|
252
|
-
package_name = ".".join(parts[: i + 1])
|
|
253
|
-
if package_name not in sys.modules:
|
|
254
|
-
full_mod_path = path.join(
|
|
255
|
-
base_path, package_name.replace(".", path.sep)
|
|
256
|
-
)
|
|
257
|
-
handle_directory(
|
|
258
|
-
module_name=package_name,
|
|
259
|
-
full_mod_path=full_mod_path,
|
|
260
|
-
mod_bundle=mod_bundle,
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
setattr(sys.modules[package_path], module_name, module)
|
|
264
|
-
sys.modules[f"{package_path}.{module_name}"] = module
|
|
265
|
-
sys.modules[module_name] = module
|
|
266
|
-
return module
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
def get_caller_dir(target: str, base_path: str, dir_path: str) -> str:
|
|
270
|
-
"""Get the directory of the caller."""
|
|
271
|
-
caller_dir = base_path if path.isdir(base_path) else path.dirname(base_path)
|
|
272
|
-
caller_dir = caller_dir if caller_dir else getcwd()
|
|
273
|
-
chomp_target = target
|
|
274
|
-
if chomp_target.startswith("."):
|
|
275
|
-
chomp_target = chomp_target[1:]
|
|
276
|
-
while chomp_target.startswith("."):
|
|
277
|
-
caller_dir = path.dirname(caller_dir)
|
|
278
|
-
chomp_target = chomp_target[1:]
|
|
279
|
-
caller_dir = path.join(caller_dir, dir_path)
|
|
280
|
-
return caller_dir
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
def py_import(
|
|
284
|
-
target: str,
|
|
285
|
-
caller_dir: str,
|
|
286
|
-
items: Optional[dict[str, Union[str, Optional[str]]]] = None,
|
|
287
|
-
absorb: bool = False,
|
|
288
|
-
mdl_alias: Optional[str] = None,
|
|
289
|
-
) -> tuple[types.ModuleType, ...]:
|
|
290
|
-
"""Import a Python module."""
|
|
291
|
-
try:
|
|
292
|
-
loaded_items: list = []
|
|
293
|
-
if target.startswith("."):
|
|
294
|
-
target = target.lstrip(".")
|
|
295
|
-
full_target = path.normpath(path.join(caller_dir, target))
|
|
296
|
-
spec = importlib.util.spec_from_file_location(target, full_target + ".py")
|
|
297
|
-
if spec and spec.loader:
|
|
298
|
-
imported_module = importlib.util.module_from_spec(spec)
|
|
299
|
-
sys.modules[spec.name] = imported_module
|
|
300
|
-
spec.loader.exec_module(imported_module)
|
|
301
|
-
else:
|
|
302
|
-
raise ImportError(f"Cannot find module {target} at {full_target}")
|
|
303
|
-
else:
|
|
304
|
-
imported_module = importlib.import_module(name=target)
|
|
305
|
-
main_module = __import__("__main__")
|
|
306
|
-
if absorb:
|
|
307
|
-
for name in dir(imported_module):
|
|
308
|
-
if not name.startswith("_"):
|
|
309
|
-
setattr(main_module, name, getattr(imported_module, name))
|
|
310
|
-
|
|
311
|
-
elif items:
|
|
312
|
-
for name, alias in items.items():
|
|
313
|
-
if isinstance(alias, bool):
|
|
314
|
-
alias = name
|
|
315
|
-
try:
|
|
316
|
-
item = getattr(imported_module, name)
|
|
317
|
-
if item not in loaded_items:
|
|
318
|
-
setattr(
|
|
319
|
-
main_module, alias if isinstance(alias, str) else name, item
|
|
320
|
-
)
|
|
321
|
-
loaded_items.append(item)
|
|
322
|
-
except AttributeError as e:
|
|
323
|
-
if hasattr(imported_module, "__path__"):
|
|
324
|
-
item = importlib.import_module(f"{target}.{name}")
|
|
325
|
-
if item not in loaded_items:
|
|
326
|
-
setattr(
|
|
327
|
-
main_module,
|
|
328
|
-
alias if isinstance(alias, str) else name,
|
|
329
|
-
item,
|
|
330
|
-
)
|
|
331
|
-
loaded_items.append(item)
|
|
332
|
-
else:
|
|
333
|
-
raise e
|
|
334
|
-
|
|
335
|
-
else:
|
|
336
|
-
setattr(
|
|
337
|
-
__import__("__main__"),
|
|
338
|
-
mdl_alias if isinstance(mdl_alias, str) else target,
|
|
339
|
-
imported_module,
|
|
340
|
-
)
|
|
341
|
-
return (imported_module, *loaded_items)
|
|
342
|
-
|
|
343
|
-
except ImportError as e:
|
|
344
|
-
raise e
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import:py from mtllm.llms.base, BaseLLM;
|
|
2
|
-
|
|
3
|
-
obj model:BaseLLM: {
|
|
4
|
-
can __infer__(meaning_in: str, **kwargs: dict) {
|
|
5
|
-
return "The calculated age is 145";
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
glob llm = model();
|
|
9
|
-
glob theresa: 'mother theresa':list[str, str] = ["Mother Theresa", "1910-08-26"];
|
|
10
|
-
obj 'Person'
|
|
11
|
-
Person {
|
|
12
|
-
has name: 'Name' :str,
|
|
13
|
-
dob: 'Date of Birth': str,
|
|
14
|
-
age: 'Age': int = None;
|
|
15
|
-
|
|
16
|
-
can 'Calculate the Age of a Person'
|
|
17
|
-
calculate (cur_year: 'Current Year': int)
|
|
18
|
-
-> 'Calculated Age' :int by llm(temperature=0.7, reason=True,incl_info=(self), excl_info=(self.age));
|
|
19
|
-
}
|
|
20
|
-
with entry{
|
|
21
|
-
Einstein = Person(name="Einstein", dob="1879-03-14");
|
|
22
|
-
age = Einstein.calculate(cur_year=2024);
|
|
23
|
-
Einstein.age = age;
|
|
24
|
-
print(Einstein.age);
|
|
25
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|