lionagi 0.9.12__py3-none-any.whl → 0.9.14__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.
- lionagi/libs/file/chunk.py +3 -3
- lionagi/libs/token_transform/base.py +52 -0
- lionagi/libs/token_transform/perplexity.py +41 -29
- lionagi/libs/token_transform/symbolic_compress_context.py +138 -0
- lionagi/libs/token_transform/synthlang.py +9 -415
- lionagi/libs/token_transform/synthlang_/base.py +130 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/abstract_algebra.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/category_theory.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/complex_analysis.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/framework_options.json +52 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/group_theory.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/math_logic.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/reflective_patterns.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/set_theory.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/frameworks/topology_fundamentals.toml +11 -0
- lionagi/libs/token_transform/synthlang_/resources/mapping/rust_chinese_mapping.toml +37 -0
- lionagi/libs/token_transform/synthlang_/resources/utility/base_synthlang_system_prompt.toml +11 -0
- lionagi/libs/token_transform/synthlang_/translate_to_synthlang.py +136 -0
- lionagi/libs/token_transform/types.py +15 -0
- lionagi/protocols/adapters/toml_adapter.py +204 -0
- lionagi/protocols/adapters/types.py +3 -0
- lionagi/protocols/generic/element.py +9 -0
- lionagi/protocols/graph/node.py +3 -0
- lionagi/service/endpoints/token_calculator.py +8 -0
- lionagi/service/imodel.py +14 -13
- lionagi/session/branch.py +6 -6
- lionagi/tools/base.py +62 -0
- lionagi/version.py +1 -1
- {lionagi-0.9.12.dist-info → lionagi-0.9.14.dist-info}/METADATA +2 -1
- {lionagi-0.9.12.dist-info → lionagi-0.9.14.dist-info}/RECORD +32 -15
- {lionagi-0.9.12.dist-info → lionagi-0.9.14.dist-info}/WHEEL +0 -0
- {lionagi-0.9.12.dist-info → lionagi-0.9.14.dist-info}/licenses/LICENSE +0 -0
@@ -1,415 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
""
|
8
|
-
|
9
|
-
|
10
|
-
from typing import Literal
|
11
|
-
|
12
|
-
from lionagi.session.branch import Branch
|
13
|
-
from lionagi.settings import Settings
|
14
|
-
|
15
|
-
from .perplexity import compress_text, iModel
|
16
|
-
|
17
|
-
########################################################################
|
18
|
-
# 1) Template Data
|
19
|
-
# Each item is a dictionary capturing your multi-line text blocks.
|
20
|
-
########################################################################
|
21
|
-
|
22
|
-
group_theory = {
|
23
|
-
"title": "Group Theory Analysis",
|
24
|
-
"domain": "mathematics",
|
25
|
-
"category": "Abstract Algebra",
|
26
|
-
"overview": "Investigation of algebraic structures using group theory and ring theory.",
|
27
|
-
"content": """# Structures
|
28
|
-
Let G be a group with operation •
|
29
|
-
Let H be a subgroup of G
|
30
|
-
Let N be a normal subgroup of G
|
31
|
-
|
32
|
-
# Properties
|
33
|
-
P(x): "x is a homomorphism"
|
34
|
-
Q(x): "x preserves group structure"
|
35
|
-
R(x): "x maps to kernel"
|
36
|
-
|
37
|
-
# Objectives
|
38
|
-
1. Prove fundamental homomorphism theorem
|
39
|
-
2. Show group action properties
|
40
|
-
3. Analyze quotient groups
|
41
|
-
""",
|
42
|
-
}
|
43
|
-
|
44
|
-
category_theory = {
|
45
|
-
"title": "Category Theory Concepts",
|
46
|
-
"domain": "mathematics",
|
47
|
-
"category": "Category Theory",
|
48
|
-
"overview": "Abstract mathematical framework dealing with relationships between structures.",
|
49
|
-
"content": """# Basic Definitions
|
50
|
-
C = (Ob(C), hom(C), ∘)
|
51
|
-
F: C → D (Functor)
|
52
|
-
...
|
53
|
-
""",
|
54
|
-
}
|
55
|
-
|
56
|
-
complex_analysis = {
|
57
|
-
"title": "Complex Analysis Foundations",
|
58
|
-
"domain": "mathematics",
|
59
|
-
"category": "Complex Analysis",
|
60
|
-
"overview": "Advanced study of complex functions, including integration and residue theory.",
|
61
|
-
"content": """# Complex Integration
|
62
|
-
∮ f(z)dz = 2πi∑Res(f,ak)
|
63
|
-
...
|
64
|
-
""",
|
65
|
-
}
|
66
|
-
|
67
|
-
math_logic = {
|
68
|
-
"title": "Mathematical Logic Foundations",
|
69
|
-
"domain": "mathematics",
|
70
|
-
"category": "Mathematical Logic",
|
71
|
-
"overview": "Exploration of fundamental mathematical logic concepts.",
|
72
|
-
"content": """# Sets and Axioms
|
73
|
-
Let A be the set of all propositions.
|
74
|
-
...
|
75
|
-
""",
|
76
|
-
}
|
77
|
-
|
78
|
-
number_theory = {
|
79
|
-
"title": "Number Theory Principles",
|
80
|
-
"domain": "mathematics",
|
81
|
-
"category": "Number Theory",
|
82
|
-
"overview": "Study of integers, prime numbers, and arithmetic functions.",
|
83
|
-
"content": """# Congruence Relations
|
84
|
-
a ≡ b (mod n)
|
85
|
-
...
|
86
|
-
""",
|
87
|
-
}
|
88
|
-
|
89
|
-
set_theory = {
|
90
|
-
"title": "Set Theory Foundations",
|
91
|
-
"domain": "mathematics",
|
92
|
-
"category": "Set Theory",
|
93
|
-
"overview": "Exploration of fundamental set theory concepts and operations.",
|
94
|
-
"content": """# Basic Definitions
|
95
|
-
Let U be the universal set
|
96
|
-
...
|
97
|
-
""",
|
98
|
-
}
|
99
|
-
|
100
|
-
symbolic_systems = {
|
101
|
-
"title": "Symbolic Systems Analysis",
|
102
|
-
"domain": "computer-science",
|
103
|
-
"category": "Symbolic Systems",
|
104
|
-
"overview": "Analysis of symbolic computation in AI and formal languages.",
|
105
|
-
"content": """# Core Concepts
|
106
|
-
Let Σ be a finite alphabet
|
107
|
-
...
|
108
|
-
""",
|
109
|
-
}
|
110
|
-
|
111
|
-
symbolic_exploration_system_supression = {
|
112
|
-
"title": "Systematic Suppression Exploration",
|
113
|
-
"domain": "societal",
|
114
|
-
"category": "Real-World Simulations",
|
115
|
-
"overview": "Analysis of suppression mechanisms using symbolic logic.",
|
116
|
-
"content": """# Sets and Categories
|
117
|
-
Let U be the set of actions representing policies ...
|
118
|
-
""",
|
119
|
-
}
|
120
|
-
|
121
|
-
topology_fundamentals = {
|
122
|
-
"title": "Topology Fundamentals",
|
123
|
-
"domain": "mathematics",
|
124
|
-
"category": "Topology",
|
125
|
-
"overview": "Study of geometric properties under continuous deformations.",
|
126
|
-
"content": """# Open Sets
|
127
|
-
(X,τ) topological space
|
128
|
-
...
|
129
|
-
""",
|
130
|
-
}
|
131
|
-
|
132
|
-
FRAMEWORK_TEMPLATES = {
|
133
|
-
"group_theory": group_theory,
|
134
|
-
"category_theory": category_theory,
|
135
|
-
"complex_analysis": complex_analysis,
|
136
|
-
"math_logic": math_logic,
|
137
|
-
"number_theory": number_theory,
|
138
|
-
"set_theory": set_theory,
|
139
|
-
"symbolic_systems": symbolic_systems,
|
140
|
-
"symbolic_exploration_system_supression": symbolic_exploration_system_supression,
|
141
|
-
"topology_fundamentals": topology_fundamentals,
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
########################################################################
|
146
|
-
# 2) Framework Definitions (Simplified)
|
147
|
-
########################################################################
|
148
|
-
|
149
|
-
# Instead of a complex dict with "selectedGlyphs", let's do a simpler approach:
|
150
|
-
# We define each "framework" by name, description, and glyphs. The user can pick them by name.
|
151
|
-
FRAMEWORK_OPTIONS = {
|
152
|
-
"math": {
|
153
|
-
"name": "Mathematical Framework",
|
154
|
-
"description": "Offers a suite of math glyphs and notation rules.",
|
155
|
-
"glyphs": [
|
156
|
-
{
|
157
|
-
"symbol": "↹",
|
158
|
-
"name": "Focus/Filter",
|
159
|
-
"description": "Used for focusing instructions",
|
160
|
-
},
|
161
|
-
{
|
162
|
-
"symbol": "Σ",
|
163
|
-
"name": "Summarize",
|
164
|
-
"description": "Condense large sets of data",
|
165
|
-
},
|
166
|
-
{
|
167
|
-
"symbol": "⊕",
|
168
|
-
"name": "Combine/Merge",
|
169
|
-
"description": "Merge multiple data sources",
|
170
|
-
},
|
171
|
-
{
|
172
|
-
"symbol": "•",
|
173
|
-
"name": "Group Operation",
|
174
|
-
"description": "Binary operation in group theory",
|
175
|
-
},
|
176
|
-
],
|
177
|
-
},
|
178
|
-
"optim": {
|
179
|
-
"name": "Optimization Framework",
|
180
|
-
"description": "Compression and optimization for code/math expressions.",
|
181
|
-
"glyphs": [
|
182
|
-
{
|
183
|
-
"symbol": "IF",
|
184
|
-
"name": "Conditional Operator",
|
185
|
-
"description": "Represents branching logic",
|
186
|
-
}
|
187
|
-
],
|
188
|
-
},
|
189
|
-
"custom_algebra": {
|
190
|
-
"name": "Custom Algebraic Framework",
|
191
|
-
"description": "Extra rules for ring, group, field expansions.",
|
192
|
-
"glyphs": [
|
193
|
-
{
|
194
|
-
"symbol": "∞",
|
195
|
-
"name": "Infinite Operator",
|
196
|
-
"description": "Represents unbounded algebraic ops",
|
197
|
-
}
|
198
|
-
],
|
199
|
-
},
|
200
|
-
}
|
201
|
-
|
202
|
-
########################################################################
|
203
|
-
# 3) SynthLang Base Prompt
|
204
|
-
########################################################################
|
205
|
-
|
206
|
-
BASE_PROMPT = """You are a SynthLang translator. You convert standard text into SynthLang format with these rules:
|
207
|
-
|
208
|
-
[Framework Integration]
|
209
|
-
- Use relevant framework glyphs wherever possible.
|
210
|
-
- Combine multiple frameworks if requested.
|
211
|
-
|
212
|
-
[Grammar Rules]
|
213
|
-
1) Task Glyphs:
|
214
|
-
- ↹ (Focus/Filter) for main tasks
|
215
|
-
- Σ (Summarize) for condensing info
|
216
|
-
- ⊕ (Combine) for merging data
|
217
|
-
- ? (Query) for clarifications
|
218
|
-
- IF for conditionals
|
219
|
-
|
220
|
-
2) Subject Markers:
|
221
|
-
- Use • before datasets (e.g., •myData)
|
222
|
-
- Use 花 for abstract concepts
|
223
|
-
- Use 山 for hierarchical structures
|
224
|
-
|
225
|
-
3) Modifiers:
|
226
|
-
- ^format(type) for output format
|
227
|
-
- ^n for importance level
|
228
|
-
- ^lang for language
|
229
|
-
- ^t{n} for time constraints
|
230
|
-
|
231
|
-
4) Flow Control:
|
232
|
-
- [p=n] for priority
|
233
|
-
- -> for sequential
|
234
|
-
- + for parallel
|
235
|
-
- | for alternatives
|
236
|
-
|
237
|
-
[Output Style]
|
238
|
-
- Maximize compression by removing articles & filler
|
239
|
-
- Use glyphs for repeated phrases
|
240
|
-
- Preserve semantic meaning
|
241
|
-
"""
|
242
|
-
|
243
|
-
|
244
|
-
########################################################################
|
245
|
-
# 4) Utility to build the "Active Frameworks" block
|
246
|
-
########################################################################
|
247
|
-
|
248
|
-
|
249
|
-
def build_frameworks_text(frameworks: list[str]) -> str:
|
250
|
-
"""
|
251
|
-
Takes a list of framework keys (e.g. ["math", "optim"]) and returns
|
252
|
-
a textual block describing them.
|
253
|
-
"""
|
254
|
-
lines = []
|
255
|
-
if not frameworks:
|
256
|
-
frameworks = FRAMEWORK_OPTIONS.keys()
|
257
|
-
|
258
|
-
for fw_key in frameworks:
|
259
|
-
fw = FRAMEWORK_OPTIONS.get(fw_key, None)
|
260
|
-
if fw:
|
261
|
-
lines.append(f"{fw['name']}: {fw['description']}")
|
262
|
-
lines.append("Glyphs:")
|
263
|
-
for g in fw["glyphs"]:
|
264
|
-
lines.append(
|
265
|
-
f" {g['symbol']} -> {g['name']} ({g['description']})"
|
266
|
-
)
|
267
|
-
lines.append("")
|
268
|
-
return "\n".join(lines).strip()
|
269
|
-
|
270
|
-
|
271
|
-
########################################################################
|
272
|
-
# 5) Main: create the SynthLang prompt
|
273
|
-
########################################################################
|
274
|
-
|
275
|
-
|
276
|
-
def create_synthlang_system_prompt(
|
277
|
-
template_name: Literal[
|
278
|
-
"group_theory",
|
279
|
-
"category_theory",
|
280
|
-
"complex_analysis",
|
281
|
-
"math_logic",
|
282
|
-
"number_theory",
|
283
|
-
"set_theory",
|
284
|
-
"symbolic_systems",
|
285
|
-
"symbolic_exploration_system_supression",
|
286
|
-
"topology_fundamentals",
|
287
|
-
],
|
288
|
-
frameworks: list[str],
|
289
|
-
additional_text: str = "",
|
290
|
-
) -> str:
|
291
|
-
"""
|
292
|
-
Merges:
|
293
|
-
- BASE_PROMPT
|
294
|
-
- "Active Frameworks" block (from frameworks list)
|
295
|
-
- The chosen template (from FRAMEWORK_TEMPLATES)
|
296
|
-
- plus additional text if desired
|
297
|
-
"""
|
298
|
-
template_block = FRAMEWORK_TEMPLATES[template_name]
|
299
|
-
frameworks_text = build_frameworks_text(frameworks)
|
300
|
-
|
301
|
-
# We show the user the "domain", "category", etc. from the template
|
302
|
-
template_details = (
|
303
|
-
f"Title: {template_block['title']}\n"
|
304
|
-
f"Domain: {template_block['domain']}\n"
|
305
|
-
f"Category: {template_block['category']}\n"
|
306
|
-
f"Overview: {template_block['overview']}\n"
|
307
|
-
"Excerpt:\n"
|
308
|
-
f"{template_block['content']}\n"
|
309
|
-
)
|
310
|
-
|
311
|
-
prompt = (
|
312
|
-
f"{BASE_PROMPT}\n\n"
|
313
|
-
"[Active Frameworks]\n"
|
314
|
-
f"{frameworks_text}\n\n"
|
315
|
-
"[Template]\n"
|
316
|
-
f"{template_details}\n"
|
317
|
-
)
|
318
|
-
|
319
|
-
if additional_text.strip():
|
320
|
-
prompt += f"\n[Additional]\n{additional_text.strip()}\n"
|
321
|
-
|
322
|
-
# Usually you might want the entire final text to be the system instruction:
|
323
|
-
return prompt
|
324
|
-
|
325
|
-
|
326
|
-
########################################################################
|
327
|
-
# 6) Translate text into SynthLang format
|
328
|
-
########################################################################
|
329
|
-
|
330
|
-
|
331
|
-
# TODO: refactor using SynthLang package
|
332
|
-
async def translate_to_synthlang(
|
333
|
-
text: str,
|
334
|
-
template_name: str = "symbolic_systems",
|
335
|
-
frameworks: list[str] = None,
|
336
|
-
compress: bool = False,
|
337
|
-
chat_model: iModel = None,
|
338
|
-
compress_model: iModel = None,
|
339
|
-
compression_ratio: float = 0.2,
|
340
|
-
compress_kwargs=None,
|
341
|
-
verbose: bool = True,
|
342
|
-
branch: Branch = None,
|
343
|
-
**kwargs,
|
344
|
-
) -> str:
|
345
|
-
"""
|
346
|
-
Optionally compress the input text using perplexity, then build a final
|
347
|
-
"SynthLang" style system prompt that includes frameworks, templates, etc.
|
348
|
-
|
349
|
-
:param text: The original text to be translated/compressed
|
350
|
-
:param template_name: Key in FRAMEWORK_TEMPLATES
|
351
|
-
:param frameworks: e.g. ["math", "optim"] to enable these frameworks
|
352
|
-
:param compress: If True, uses perplexity-based compression
|
353
|
-
:param chat_model: The model for perplexity compression
|
354
|
-
:param compression_ratio: float ratio of final token usage
|
355
|
-
:param compress_kwargs: Additional arguments to pass to compression
|
356
|
-
:return: A string in SynthLang style
|
357
|
-
"""
|
358
|
-
from .synthlang import create_synthlang_system_prompt
|
359
|
-
|
360
|
-
start = timer()
|
361
|
-
chat_model = chat_model or iModel(**Settings.iModel.CHAT)
|
362
|
-
if compress:
|
363
|
-
text = await compress_text(
|
364
|
-
text,
|
365
|
-
chat_model=compress_model or chat_model,
|
366
|
-
target_ratio=compression_ratio,
|
367
|
-
**(compress_kwargs or {}),
|
368
|
-
)
|
369
|
-
|
370
|
-
# Build final system prompt
|
371
|
-
final_prompt = create_synthlang_system_prompt(
|
372
|
-
template_name=template_name,
|
373
|
-
frameworks=frameworks,
|
374
|
-
)
|
375
|
-
|
376
|
-
sys1 = None
|
377
|
-
sys2 = final_prompt
|
378
|
-
if branch and branch.system:
|
379
|
-
sys1 = branch.system
|
380
|
-
branch.msgs.add_message(system=sys2)
|
381
|
-
|
382
|
-
else:
|
383
|
-
branch = Branch(system=final_prompt, chat_model=chat_model)
|
384
|
-
|
385
|
-
from lionagi.service.endpoints.token_calculator import TokenCalculator
|
386
|
-
|
387
|
-
calculator = TokenCalculator()
|
388
|
-
|
389
|
-
len_tokens = calculator.tokenize(text, return_tokens=False)
|
390
|
-
|
391
|
-
kwargs["guidance"] = (
|
392
|
-
"Following SynthLang, translate the provided text into SynthLang syntax. "
|
393
|
-
"Shrink the token size by 60-85%. Return only the translated text.\n\n"
|
394
|
-
+ kwargs.get("guidance", "")
|
395
|
-
)
|
396
|
-
|
397
|
-
out = await branch.chat(
|
398
|
-
instruction=f"Converts the given text into SynthLang's hyper-efficient format.",
|
399
|
-
context="Text to convert:\n\n" + text,
|
400
|
-
**kwargs,
|
401
|
-
)
|
402
|
-
if sys1:
|
403
|
-
branch.msgs.add_message(system=sys1)
|
404
|
-
|
405
|
-
len_ = calculator.tokenize(out, return_tokens=False)
|
406
|
-
if verbose:
|
407
|
-
msg = ""
|
408
|
-
msg += f"Compression Method: SynthLang\n"
|
409
|
-
msg += f"Compressed Token number: {len_}\n"
|
410
|
-
msg += f"Token Compression Ratio: {len_ / len_tokens:.1%}\n"
|
411
|
-
msg += f"Compression Time: {timer() - start:.03f} seconds\n"
|
412
|
-
msg += f"Compression Model: {branch.chat_model.model_name}\n"
|
413
|
-
print(msg)
|
414
|
-
|
415
|
-
return out
|
1
|
+
from .synthlang_.base import SynthlangFramework, SynthlangTemplate
|
2
|
+
from .synthlang_.translate_to_synthlang import translate_to_synthlang
|
3
|
+
|
4
|
+
# backwards compatibility
|
5
|
+
__all__ = (
|
6
|
+
"translate_to_synthlang",
|
7
|
+
"SynthlangFramework",
|
8
|
+
"SynthlangTemplate",
|
9
|
+
)
|
@@ -0,0 +1,130 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from enum import Enum
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import Literal
|
6
|
+
|
7
|
+
from pydantic import Field
|
8
|
+
|
9
|
+
from lionagi.tools.base import Prompt, Resource, ResourceCategory
|
10
|
+
|
11
|
+
here = Path(__file__).parent.resolve()
|
12
|
+
|
13
|
+
FRAMEWORK_PATH = "resources/frameworks"
|
14
|
+
FRAMEWORK_CHOICES = Literal["math", "optim", "custom_algebra"]
|
15
|
+
|
16
|
+
|
17
|
+
__all__ = (
|
18
|
+
"SynthlangFramework",
|
19
|
+
"SynthlangTemplate",
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class SynthlangFramework(Resource):
|
24
|
+
|
25
|
+
category: ResourceCategory = Field(
|
26
|
+
default=ResourceCategory.FRAMEWORK, frozen=True
|
27
|
+
)
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def load_framework_options(cls) -> dict:
|
31
|
+
import json
|
32
|
+
|
33
|
+
fp = here / FRAMEWORK_PATH / "framework_options.json"
|
34
|
+
with open(fp, "r", encoding="utf-8") as f:
|
35
|
+
return json.load(f)
|
36
|
+
|
37
|
+
@classmethod
|
38
|
+
def load_from_template(
|
39
|
+
cls, template: SynthlangTemplate | str
|
40
|
+
) -> SynthlangFramework:
|
41
|
+
return SynthlangTemplate.load(template)
|
42
|
+
|
43
|
+
@classmethod
|
44
|
+
def load_base_system_prompt(cls) -> Prompt:
|
45
|
+
fp = here / "resources/utility" / "base_synthlang_system_prompt.toml"
|
46
|
+
return SynthlangFramework.adapt_from(fp, ".toml", many=False)
|
47
|
+
|
48
|
+
@classmethod
|
49
|
+
def build_framework_text(
|
50
|
+
cls, framework_options: list[FRAMEWORK_CHOICES] = None
|
51
|
+
) -> str:
|
52
|
+
FRAMEWORK_OPTIONS = cls.load_framework_options()
|
53
|
+
lines = []
|
54
|
+
if not framework_options:
|
55
|
+
framework_options = FRAMEWORK_OPTIONS["options"].keys()
|
56
|
+
|
57
|
+
for fw_key in framework_options:
|
58
|
+
fw = FRAMEWORK_OPTIONS.get(fw_key, None)
|
59
|
+
if fw:
|
60
|
+
print(fw)
|
61
|
+
lines.append(f"{fw['name']}: {fw['description']}")
|
62
|
+
lines.append("Glyphs:")
|
63
|
+
for g in fw["glyphs"]:
|
64
|
+
lines.append(
|
65
|
+
f" {g['symbol']} -> {g['name']} ({g['description']})"
|
66
|
+
)
|
67
|
+
lines.append("")
|
68
|
+
return "\n".join(lines).strip()
|
69
|
+
|
70
|
+
def create_system_prompt(
|
71
|
+
self,
|
72
|
+
framework_options: list[FRAMEWORK_CHOICES] = None,
|
73
|
+
additional_text: str = "",
|
74
|
+
) -> str:
|
75
|
+
|
76
|
+
framework_options_text = self.build_framework_text(framework_options)
|
77
|
+
base_prompt = self.load_base_system_prompt()
|
78
|
+
template_details = (
|
79
|
+
f"Title: {self.meta_obj.title}\n"
|
80
|
+
f"Domain: {str(self.meta_obj.domain)}\n"
|
81
|
+
f"Category: {str(self.category)}\n"
|
82
|
+
f"Overview: {self.meta_obj.overview}\n"
|
83
|
+
"Excerpt:\n"
|
84
|
+
f"{self.content}\n"
|
85
|
+
)
|
86
|
+
prompt = (
|
87
|
+
f"{base_prompt.content}\n\n"
|
88
|
+
"[Active Frameworks]\n"
|
89
|
+
f"{framework_options_text}\n\n"
|
90
|
+
"[Template]\n"
|
91
|
+
f"{template_details}\n"
|
92
|
+
)
|
93
|
+
if additional_text.strip():
|
94
|
+
prompt += f"\n[Additional]\n{additional_text.strip()}\n"
|
95
|
+
|
96
|
+
return prompt.strip()
|
97
|
+
|
98
|
+
|
99
|
+
class SynthlangTemplate(str, Enum):
|
100
|
+
ABSTRACT_ALGEBRA = "abstract_algebra"
|
101
|
+
CATEGORY_THEORY = "category_theory"
|
102
|
+
COMPLEX_ANALYSIS = "complex_analysis"
|
103
|
+
GROUP_THEORY = "group_theory"
|
104
|
+
MATH_LOGIC = "math_logic"
|
105
|
+
REFLECTIVE_PATTERNS = "reflective_patterns"
|
106
|
+
SET_THEORY = "set_theory"
|
107
|
+
TOPOLOGY_FUNDAMENTALS = "topology_fundamentals"
|
108
|
+
|
109
|
+
@property
|
110
|
+
def fp(self) -> Path:
|
111
|
+
return here / FRAMEWORK_PATH / f"{self.value}.toml"
|
112
|
+
|
113
|
+
@classmethod
|
114
|
+
def list_templates(cls) -> list[str]:
|
115
|
+
return [template.value for template in cls]
|
116
|
+
|
117
|
+
@classmethod
|
118
|
+
def load(cls, framework: str) -> SynthlangFramework:
|
119
|
+
framework = str(framework).strip().lower()
|
120
|
+
framework = framework.replace(" ", "_").replace("-", "_")
|
121
|
+
if ".toml" in framework:
|
122
|
+
framework = framework.replace(".toml", "").strip()
|
123
|
+
if "synthlangtemplate." in framework:
|
124
|
+
framework = framework.replace("synthlangtemplate.", "").strip()
|
125
|
+
try:
|
126
|
+
framework = cls(framework)
|
127
|
+
except ValueError:
|
128
|
+
raise ValueError(f"Invalid synthlang framework name: {framework}")
|
129
|
+
|
130
|
+
return SynthlangFramework.adapt_from(framework.fp, ".toml", many=False)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
id = "11968433-1402-4783-b167-25afbe0a6c4f"
|
2
|
+
created_at = 1740606622.114634
|
3
|
+
content = "\n## Group Actions\n`G × X → X`\n\n### Reflective Pattern\n↹ transformations•symmetries•invariants\n⊕ identify => patterns\n⊕ analyze => operations\n⊕ preserve => structure\nΣ systematic•approach + invariant•properties\n\n### Example Prompt\n\"What patterns remain constant as we apply different transformations to our approach?\"\n\n## Ring Structure\n`(R, +, ×)`\n\n### Reflective Pattern\n↹ operations•interactions•composition\n⊕ combine => methods\n⊕ distribute => resources\n⊕ verify => closure\nΣ integrated•framework + operational•rules\n"
|
4
|
+
category = "framework"
|
5
|
+
|
6
|
+
[metadata]
|
7
|
+
title = "Abstract Algebra Reflective Symbolic Compression"
|
8
|
+
domain = "Symbolic Compression"
|
9
|
+
version = "1.0"
|
10
|
+
overview = "A resource for learning and exploring abstract algebra concepts."
|
11
|
+
lion_class = "lionagi.libs.token_transform.synthlang_.base.SynthlangFramework"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
id = "b8588217-3da0-4809-8a8e-1bc9489a718a"
|
2
|
+
created_at = 1740606718.863813
|
3
|
+
content = "\n# Category Theory Reflective Prompts\n\n## Functors\n`F: C → D`\n\n### Reflective Pattern\n↹ domain•codomain•mapping\n⊕ preserve => structure\n⊕ transform => concepts\n⊕ maintain => relationships\nΣ transformed•insight + preserved•properties\n\n### Example Prompt\n\"How can we translate this solution from one context to another while preserving its essential properties?\"\n\n## Natural Transformations\n`η: F ⇒ G`\n\n### Reflective Pattern\n↹ approaches•methods•transitions\n⊕ compare => strategies\n⊕ identify => transformations\n⊕ validate => coherence\nΣ systematic•evolution + consistency•check\n"
|
4
|
+
category = "framework"
|
5
|
+
|
6
|
+
[metadata]
|
7
|
+
title = "Category Theory Concepts Symbolic Compression"
|
8
|
+
domain = "Symbolic Compression"
|
9
|
+
version = "1.0"
|
10
|
+
overview = "Abstract mathematical framework dealing with mathematical structures and relationships between them."
|
11
|
+
lion_class = "lionagi.libs.token_transform.synthlang_.base.SynthlangFramework"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
id = "f7ea039c-829b-453c-a562-85e8e66df2b0"
|
2
|
+
created_at = 1740602435.49488
|
3
|
+
content = "\n# Complex Analysis Reflective Prompts\n\n## Residue Theorem\n`∮_C f(z)dz = 2πi ∑Res(f,ak)`\n\n### Reflective Pattern\n↹ local•global•interactions\n⊕ analyze => singularities\n⊕ integrate => effects\n⊕ synthesize => global•view\nΣ comprehensive•understanding + local•insights\n\n### Example Prompt\n\"How do local decisions and singular points in our approach contribute to the overall solution?\"\n\n## Analytic Continuation\n`f(z)` extends uniquely\n\n### Reflective Pattern\n↹ partial•solution•constraints\n⊕ extend => domain\n⊕ preserve => consistency\n⊕ validate => uniqueness\nΣ complete•solution + coherence•check\n"
|
4
|
+
category = "framework"
|
5
|
+
|
6
|
+
[metadata]
|
7
|
+
title = "Complex Analysis Foundations"
|
8
|
+
domain = "Symbolic Compression"
|
9
|
+
version = "1.0"
|
10
|
+
overview = "Advanced study of complex functions, including integration and residue theory."
|
11
|
+
lion_class = "lionagi.libs.token_transform.synthlang_.base.SynthlangFramework"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"options": {
|
3
|
+
"math": {
|
4
|
+
"name": "Mathematical Framework",
|
5
|
+
"description": "Offers a suite of math glyphs and notation rules.",
|
6
|
+
"glyphs": [
|
7
|
+
{
|
8
|
+
"symbol": "\u21b9",
|
9
|
+
"name": "Focus/Filter",
|
10
|
+
"description": "Used for focusing instructions"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"symbol": "\u03a3",
|
14
|
+
"name": "Summarize",
|
15
|
+
"description": "Condense large sets of data"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"symbol": "\u2295",
|
19
|
+
"name": "Combine/Merge",
|
20
|
+
"description": "Merge multiple data sources"
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"symbol": "\u2022",
|
24
|
+
"name": "Group Operation",
|
25
|
+
"description": "Binary operation in group theory"
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
"optim": {
|
30
|
+
"name": "Optimization Framework",
|
31
|
+
"description": "Compression and optimization for code/math expressions.",
|
32
|
+
"glyphs": [
|
33
|
+
{
|
34
|
+
"symbol": "IF",
|
35
|
+
"name": "Conditional Operator",
|
36
|
+
"description": "Represents branching logic"
|
37
|
+
}
|
38
|
+
]
|
39
|
+
},
|
40
|
+
"custom_algebra": {
|
41
|
+
"name": "Custom Algebraic Framework",
|
42
|
+
"description": "Extra rules for ring, group, field expansions.",
|
43
|
+
"glyphs": [
|
44
|
+
{
|
45
|
+
"symbol": "\u221e",
|
46
|
+
"name": "Infinite Operator",
|
47
|
+
"description": "Represents unbounded algebraic ops"
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
id = "c077186b-30cd-42d9-88ae-563859a00db3"
|
2
|
+
created_at = 1740602288.669331
|
3
|
+
content = "# Structures\nLet G be a group with operation •\nLet H be a subgroup of G\nLet N be a normal subgroup of G\n\n# Properties\nP(x): \"x is a homomorphism\"\nQ(x): \"x preserves group structure\"\nR(x): \"x maps to kernel\"\n\n# Objectives\n1. Prove fundamental homomorphism theorem\n2. Show group action properties\n3. Analyze quotient groups\n"
|
4
|
+
category = "framework"
|
5
|
+
|
6
|
+
[metadata]
|
7
|
+
title = "Group Theory Analysis"
|
8
|
+
domain = "Symbolic Compression"
|
9
|
+
version = "1.0"
|
10
|
+
overview = "Investigation of algebraic structures using group theory and ring theory."
|
11
|
+
lion_class = "lionagi.libs.token_transform.synthlang_.base.SynthlangFramework"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
id = "bc244d9c-3fcc-4e7c-9a13-d0e208904c22"
|
2
|
+
created_at = 1740602490.430191
|
3
|
+
content = "\n# Sets and Axioms\nLet A be the set of all logical propositions.\nLet T be the subset of A that are tautologies.\nLet C be the subset of A that are contradictions.\n\n# Predicates\nP(x): \"x is a well-formed formula\"\nQ(x): \"x is satisfiable\"\nR(x): \"x is valid\"\n\n# Objectives\n1. Prove completeness theorem using predicate calculus\n2. Demonstrate soundness of the system\n3. Show relationship between syntax and semantics\n\n# Complex Integration\n∮ f(z)dz = 2πi∑Res(f,ak)\nLet f(z) = ∑(n=0 to ∞) an(z-z₀)ⁿ\nRes(f,a) = 1/(2πi)∮ f(z)dz\nw = f(z) preserves angles\n∂u/∂x = ∂v/∂y\n∂u/∂y = -∂v/∂x\n"
|
4
|
+
category = "framework"
|
5
|
+
|
6
|
+
[metadata]
|
7
|
+
title = "Mathematical Logic Foundations"
|
8
|
+
domain = "Symbolic Compression"
|
9
|
+
version = "1.0"
|
10
|
+
overview = "Exploration of fundamental mathematical logic concepts using set theory and predicate calculus."
|
11
|
+
lion_class = "lionagi.libs.token_transform.synthlang_.base.SynthlangFramework"
|