dialectical-framework 0.4.4__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.
- dialectical_framework/__init__.py +43 -0
- dialectical_framework/ai_dto/__init__.py +0 -0
- dialectical_framework/ai_dto/causal_cycle_assessment_dto.py +16 -0
- dialectical_framework/ai_dto/causal_cycle_dto.py +16 -0
- dialectical_framework/ai_dto/causal_cycles_deck_dto.py +11 -0
- dialectical_framework/ai_dto/dialectical_component_dto.py +16 -0
- dialectical_framework/ai_dto/dialectical_components_deck_dto.py +12 -0
- dialectical_framework/ai_dto/dto_mapper.py +103 -0
- dialectical_framework/ai_dto/reciprocal_solution_dto.py +24 -0
- dialectical_framework/analyst/__init__.py +1 -0
- dialectical_framework/analyst/audit/__init__.py +0 -0
- dialectical_framework/analyst/consultant.py +30 -0
- dialectical_framework/analyst/decorator_action_reflection.py +28 -0
- dialectical_framework/analyst/decorator_discrete_spiral.py +30 -0
- dialectical_framework/analyst/domain/__init__.py +0 -0
- dialectical_framework/analyst/domain/assessable_cycle.py +128 -0
- dialectical_framework/analyst/domain/cycle.py +133 -0
- dialectical_framework/analyst/domain/interpretation.py +16 -0
- dialectical_framework/analyst/domain/rationale.py +116 -0
- dialectical_framework/analyst/domain/spiral.py +47 -0
- dialectical_framework/analyst/domain/transformation.py +24 -0
- dialectical_framework/analyst/domain/transition.py +160 -0
- dialectical_framework/analyst/domain/transition_cell_to_cell.py +29 -0
- dialectical_framework/analyst/domain/transition_segment_to_segment.py +16 -0
- dialectical_framework/analyst/strategic_consultant.py +32 -0
- dialectical_framework/analyst/think_action_reflection.py +217 -0
- dialectical_framework/analyst/think_constructive_convergence.py +87 -0
- dialectical_framework/analyst/wheel_builder_transition_calculator.py +157 -0
- dialectical_framework/brain.py +81 -0
- dialectical_framework/dialectical_analysis.py +14 -0
- dialectical_framework/dialectical_component.py +111 -0
- dialectical_framework/dialectical_components_deck.py +48 -0
- dialectical_framework/dialectical_reasoning.py +105 -0
- dialectical_framework/directed_graph.py +419 -0
- dialectical_framework/enums/__init__.py +0 -0
- dialectical_framework/enums/causality_type.py +10 -0
- dialectical_framework/enums/di.py +11 -0
- dialectical_framework/enums/dialectical_reasoning_mode.py +9 -0
- dialectical_framework/enums/predicate.py +9 -0
- dialectical_framework/protocols/__init__.py +0 -0
- dialectical_framework/protocols/assessable.py +141 -0
- dialectical_framework/protocols/causality_sequencer.py +111 -0
- dialectical_framework/protocols/content_fidelity_evaluator.py +16 -0
- dialectical_framework/protocols/has_brain.py +18 -0
- dialectical_framework/protocols/has_config.py +18 -0
- dialectical_framework/protocols/ratable.py +79 -0
- dialectical_framework/protocols/reloadable.py +7 -0
- dialectical_framework/protocols/thesis_extractor.py +15 -0
- dialectical_framework/settings.py +77 -0
- dialectical_framework/synthesis.py +7 -0
- dialectical_framework/synthesist/__init__.py +1 -0
- dialectical_framework/synthesist/causality/__init__.py +0 -0
- dialectical_framework/synthesist/causality/causality_sequencer_balanced.py +398 -0
- dialectical_framework/synthesist/causality/causality_sequencer_desirable.py +55 -0
- dialectical_framework/synthesist/causality/causality_sequencer_feasible.py +55 -0
- dialectical_framework/synthesist/causality/causality_sequencer_realistic.py +56 -0
- dialectical_framework/synthesist/concepts/__init__.py +0 -0
- dialectical_framework/synthesist/concepts/thesis_extractor_basic.py +135 -0
- dialectical_framework/synthesist/polarity/__init__.py +0 -0
- dialectical_framework/synthesist/polarity/polarity_reasoner.py +700 -0
- dialectical_framework/synthesist/polarity/reason_blind.py +62 -0
- dialectical_framework/synthesist/polarity/reason_conversational.py +91 -0
- dialectical_framework/synthesist/polarity/reason_fast.py +177 -0
- dialectical_framework/synthesist/polarity/reason_fast_and_simple.py +52 -0
- dialectical_framework/synthesist/polarity/reason_fast_polarized_conflict.py +55 -0
- dialectical_framework/synthesist/reverse_engineer.py +401 -0
- dialectical_framework/synthesist/wheel_builder.py +337 -0
- dialectical_framework/utils/__init__.py +1 -0
- dialectical_framework/utils/dc_replace.py +42 -0
- dialectical_framework/utils/decompose_probability_uniformly.py +15 -0
- dialectical_framework/utils/extend_tpl.py +12 -0
- dialectical_framework/utils/gm.py +12 -0
- dialectical_framework/utils/is_async.py +13 -0
- dialectical_framework/utils/use_brain.py +80 -0
- dialectical_framework/validator/__init__.py +1 -0
- dialectical_framework/validator/basic_checks.py +75 -0
- dialectical_framework/validator/check.py +12 -0
- dialectical_framework/wheel.py +395 -0
- dialectical_framework/wheel_segment.py +203 -0
- dialectical_framework/wisdom_unit.py +185 -0
- dialectical_framework-0.4.4.dist-info/LICENSE +21 -0
- dialectical_framework-0.4.4.dist-info/METADATA +123 -0
- dialectical_framework-0.4.4.dist-info/RECORD +84 -0
- dialectical_framework-0.4.4.dist-info/WHEEL +4 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
from typing import Self
|
2
|
+
|
3
|
+
from mirascope import Messages, prompt_template
|
4
|
+
from mirascope.integrations.langfuse import with_langfuse
|
5
|
+
|
6
|
+
from dialectical_framework.ai_dto.dialectical_component_dto import \
|
7
|
+
DialecticalComponentDto
|
8
|
+
from dialectical_framework.ai_dto.dialectical_components_deck_dto import \
|
9
|
+
DialecticalComponentsDeckDto
|
10
|
+
from dialectical_framework.ai_dto.dto_mapper import (map_from_dto,
|
11
|
+
map_list_from_dto)
|
12
|
+
from dialectical_framework.dialectical_component import DialecticalComponent
|
13
|
+
from dialectical_framework.dialectical_components_deck import \
|
14
|
+
DialecticalComponentsDeck
|
15
|
+
from dialectical_framework.protocols.has_brain import HasBrain
|
16
|
+
from dialectical_framework.protocols.has_config import SettingsAware
|
17
|
+
from dialectical_framework.protocols.thesis_extractor import ThesisExtractor
|
18
|
+
from dialectical_framework.utils.use_brain import use_brain
|
19
|
+
|
20
|
+
|
21
|
+
class ThesisExtractorBasic(ThesisExtractor, HasBrain, SettingsAware):
|
22
|
+
def __init__(self, *, text: str = ""):
|
23
|
+
self.__text = text
|
24
|
+
|
25
|
+
@property
|
26
|
+
def text(self) -> str:
|
27
|
+
return self.__text
|
28
|
+
|
29
|
+
@text.setter
|
30
|
+
def text(self, value: str):
|
31
|
+
self.__text = value
|
32
|
+
|
33
|
+
def reload(self, *, text: str) -> Self:
|
34
|
+
self.text = text
|
35
|
+
return self
|
36
|
+
|
37
|
+
@prompt_template(
|
38
|
+
"""
|
39
|
+
USER:
|
40
|
+
<context>{text}</context>
|
41
|
+
|
42
|
+
USER:
|
43
|
+
Extract the central idea or the primary thesis (denote it as T) of the context with minimal distortion. If already concise (single word/phrase/clear thesis), keep it intact; only condense verbose messages while preserving original meaning.
|
44
|
+
|
45
|
+
Output the dialectical component T within {component_length} word(s), the shorter, the better. Compose the explanation how it was derived in the passive voice. Don't mention any special denotations such as "T" in the explanation.
|
46
|
+
"""
|
47
|
+
)
|
48
|
+
def prompt_single_thesis(self) -> Messages.Type:
|
49
|
+
return {
|
50
|
+
"computed_fields": {
|
51
|
+
"text": self.text,
|
52
|
+
"component_length": self.settings.component_length,
|
53
|
+
},
|
54
|
+
}
|
55
|
+
|
56
|
+
@prompt_template(
|
57
|
+
"""
|
58
|
+
USER:
|
59
|
+
<context>{text}</context>
|
60
|
+
|
61
|
+
USER:
|
62
|
+
For the given context extract **{count}** distinct, essential **concepts** that best capture the core dynamics of the text.
|
63
|
+
|
64
|
+
**For strategic/philosophical texts, focus on:**
|
65
|
+
- Big-picture or recurring ideas that reflect the **essence** of the content
|
66
|
+
- **Abstract or strategic drivers** of the text
|
67
|
+
- Terms that **structure the argument** or explain system-level dynamics
|
68
|
+
|
69
|
+
**For technical/operational texts, focus on:**
|
70
|
+
- **Process stages, steps, or functional components** that form the system
|
71
|
+
- **Sequential elements** that flow into or cause each other
|
72
|
+
- **Operational phases** or mechanisms that drive the system forward
|
73
|
+
|
74
|
+
**Guidelines:**
|
75
|
+
- Let the content guide whether to extract high-level themes or operational stages
|
76
|
+
- If the text describes processes/systems, identify functional components
|
77
|
+
- If the text presents arguments/strategies, identify conceptual themes
|
78
|
+
- Aim for concepts that are **interdependent** and form a coherent framework
|
79
|
+
|
80
|
+
**Output Format:**
|
81
|
+
T1 = [concept in 1-{component_length} words]
|
82
|
+
Explanation: [The explanation how it was derived in the passive voice]
|
83
|
+
|
84
|
+
T2 = [concept in 1-{component_length} words]
|
85
|
+
Explanation: [The explanation how it was derived in the passive voice]
|
86
|
+
|
87
|
+
...
|
88
|
+
|
89
|
+
Tx = [concept in 1-{component_length} words]
|
90
|
+
Explanation: [The explanation how it was derived in the passive voice]
|
91
|
+
|
92
|
+
**Rules**
|
93
|
+
Make sure to output {count} concepts, no more no less.
|
94
|
+
"""
|
95
|
+
)
|
96
|
+
def prompt_multiple_theses(self, count: int) -> Messages.Type:
|
97
|
+
return {
|
98
|
+
"computed_fields": {
|
99
|
+
"text": self.text,
|
100
|
+
"count": count,
|
101
|
+
"component_length": self.settings.component_length,
|
102
|
+
},
|
103
|
+
}
|
104
|
+
|
105
|
+
async def extract_multiple_theses(
|
106
|
+
self, *, count: int = 2
|
107
|
+
) -> DialecticalComponentsDeck:
|
108
|
+
if count > 4 or count < 1:
|
109
|
+
raise ValueError(
|
110
|
+
f"Incorrect number of theses requested. Max 4 theses are supported."
|
111
|
+
)
|
112
|
+
|
113
|
+
@with_langfuse()
|
114
|
+
@use_brain(brain=self.brain, response_model=DialecticalComponentsDeckDto)
|
115
|
+
async def _find_theses():
|
116
|
+
return self.prompt_multiple_theses(count=count)
|
117
|
+
|
118
|
+
if count <= 4:
|
119
|
+
deck_dto = await _find_theses()
|
120
|
+
deck = DialecticalComponentsDeck(dialectical_components=map_list_from_dto(deck_dto.dialectical_components, DialecticalComponent))
|
121
|
+
if count == 1 and len(deck.dialectical_components) == 1:
|
122
|
+
dc: DialecticalComponent = deck.dialectical_components[0]
|
123
|
+
dc.set_human_friendly_index(0)
|
124
|
+
else:
|
125
|
+
raise ValueError(f"More than 4 theses are not supported yet.")
|
126
|
+
return deck
|
127
|
+
|
128
|
+
async def extract_single_thesis(self) -> DialecticalComponent:
|
129
|
+
@with_langfuse()
|
130
|
+
@use_brain(brain=self.brain, response_model=DialecticalComponentDto)
|
131
|
+
async def _find_thesis():
|
132
|
+
return self.prompt_single_thesis()
|
133
|
+
|
134
|
+
dc_dto = await _find_thesis()
|
135
|
+
return map_from_dto(dc_dto, DialecticalComponent)
|
File without changes
|