crca 1.4.0__py3-none-any.whl → 1.5.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.
- CRCA.py +172 -7
- MODEL_CARD.md +53 -0
- PKG-INFO +8 -2
- RELEASE_NOTES.md +17 -0
- STABILITY.md +19 -0
- architecture/hybrid/consistency_engine.py +362 -0
- architecture/hybrid/conversation_manager.py +421 -0
- architecture/hybrid/explanation_generator.py +452 -0
- architecture/hybrid/few_shot_learner.py +533 -0
- architecture/hybrid/graph_compressor.py +286 -0
- architecture/hybrid/hybrid_agent.py +4398 -0
- architecture/hybrid/language_compiler.py +623 -0
- architecture/hybrid/main,py +0 -0
- architecture/hybrid/reasoning_tracker.py +322 -0
- architecture/hybrid/self_verifier.py +524 -0
- architecture/hybrid/task_decomposer.py +567 -0
- architecture/hybrid/text_corrector.py +341 -0
- benchmark_results/crca_core_benchmarks.json +178 -0
- branches/crca_sd/crca_sd_realtime.py +6 -2
- branches/general_agent/__init__.py +102 -0
- branches/general_agent/general_agent.py +1400 -0
- branches/general_agent/personality.py +169 -0
- branches/general_agent/utils/__init__.py +19 -0
- branches/general_agent/utils/prompt_builder.py +170 -0
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/METADATA +8 -2
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/RECORD +303 -20
- crca_core/__init__.py +35 -0
- crca_core/benchmarks/__init__.py +14 -0
- crca_core/benchmarks/synthetic_scm.py +103 -0
- crca_core/core/__init__.py +23 -0
- crca_core/core/api.py +120 -0
- crca_core/core/estimate.py +208 -0
- crca_core/core/godclass.py +72 -0
- crca_core/core/intervention_design.py +174 -0
- crca_core/core/lifecycle.py +48 -0
- crca_core/discovery/__init__.py +9 -0
- crca_core/discovery/tabular.py +193 -0
- crca_core/identify/__init__.py +171 -0
- crca_core/identify/backdoor.py +39 -0
- crca_core/identify/frontdoor.py +48 -0
- crca_core/identify/graph.py +106 -0
- crca_core/identify/id_algorithm.py +43 -0
- crca_core/identify/iv.py +48 -0
- crca_core/models/__init__.py +67 -0
- crca_core/models/provenance.py +56 -0
- crca_core/models/refusal.py +39 -0
- crca_core/models/result.py +83 -0
- crca_core/models/spec.py +151 -0
- crca_core/models/validation.py +68 -0
- crca_core/scm/__init__.py +9 -0
- crca_core/scm/linear_gaussian.py +198 -0
- crca_core/timeseries/__init__.py +6 -0
- crca_core/timeseries/pcmci.py +181 -0
- crca_llm/__init__.py +12 -0
- crca_llm/client.py +85 -0
- crca_llm/coauthor.py +118 -0
- crca_llm/orchestrator.py +289 -0
- crca_llm/types.py +21 -0
- crca_reasoning/__init__.py +16 -0
- crca_reasoning/critique.py +54 -0
- crca_reasoning/godclass.py +206 -0
- crca_reasoning/memory.py +24 -0
- crca_reasoning/rationale.py +10 -0
- crca_reasoning/react_controller.py +81 -0
- crca_reasoning/tool_router.py +97 -0
- crca_reasoning/types.py +40 -0
- crca_sd/__init__.py +15 -0
- crca_sd/crca_sd_core.py +2 -0
- crca_sd/crca_sd_governance.py +2 -0
- crca_sd/crca_sd_mpc.py +2 -0
- crca_sd/crca_sd_realtime.py +2 -0
- crca_sd/crca_sd_tui.py +2 -0
- cuda-keyring_1.1-1_all.deb +0 -0
- cuda-keyring_1.1-1_all.deb.1 +0 -0
- docs/IMAGE_ANNOTATION_USAGE.md +539 -0
- docs/INSTALL_DEEPSPEED.md +125 -0
- docs/api/branches/crca-cg.md +19 -0
- docs/api/branches/crca-q.md +27 -0
- docs/api/branches/crca-sd.md +37 -0
- docs/api/branches/general-agent.md +24 -0
- docs/api/branches/overview.md +19 -0
- docs/api/crca/agent-methods.md +62 -0
- docs/api/crca/operations.md +79 -0
- docs/api/crca/overview.md +32 -0
- docs/api/image-annotation/engine.md +52 -0
- docs/api/image-annotation/overview.md +17 -0
- docs/api/schemas/annotation.md +34 -0
- docs/api/schemas/core-schemas.md +82 -0
- docs/api/schemas/overview.md +32 -0
- docs/api/schemas/policy.md +30 -0
- docs/api/utils/conversation.md +22 -0
- docs/api/utils/graph-reasoner.md +32 -0
- docs/api/utils/overview.md +21 -0
- docs/api/utils/router.md +19 -0
- docs/api/utils/utilities.md +97 -0
- docs/architecture/causal-graphs.md +41 -0
- docs/architecture/data-flow.md +29 -0
- docs/architecture/design-principles.md +33 -0
- docs/architecture/hybrid-agent/components.md +38 -0
- docs/architecture/hybrid-agent/consistency.md +26 -0
- docs/architecture/hybrid-agent/overview.md +44 -0
- docs/architecture/hybrid-agent/reasoning.md +22 -0
- docs/architecture/llm-integration.md +26 -0
- docs/architecture/modular-structure.md +37 -0
- docs/architecture/overview.md +69 -0
- docs/architecture/policy-engine-arch.md +29 -0
- docs/branches/crca-cg/corposwarm.md +39 -0
- docs/branches/crca-cg/esg-scoring.md +30 -0
- docs/branches/crca-cg/multi-agent.md +35 -0
- docs/branches/crca-cg/overview.md +40 -0
- docs/branches/crca-q/alternative-data.md +55 -0
- docs/branches/crca-q/architecture.md +71 -0
- docs/branches/crca-q/backtesting.md +45 -0
- docs/branches/crca-q/causal-engine.md +33 -0
- docs/branches/crca-q/execution.md +39 -0
- docs/branches/crca-q/market-data.md +60 -0
- docs/branches/crca-q/overview.md +58 -0
- docs/branches/crca-q/philosophy.md +60 -0
- docs/branches/crca-q/portfolio-optimization.md +66 -0
- docs/branches/crca-q/risk-management.md +102 -0
- docs/branches/crca-q/setup.md +65 -0
- docs/branches/crca-q/signal-generation.md +61 -0
- docs/branches/crca-q/signal-validation.md +43 -0
- docs/branches/crca-sd/core.md +84 -0
- docs/branches/crca-sd/governance.md +53 -0
- docs/branches/crca-sd/mpc-solver.md +65 -0
- docs/branches/crca-sd/overview.md +59 -0
- docs/branches/crca-sd/realtime.md +28 -0
- docs/branches/crca-sd/tui.md +20 -0
- docs/branches/general-agent/overview.md +37 -0
- docs/branches/general-agent/personality.md +36 -0
- docs/branches/general-agent/prompt-builder.md +30 -0
- docs/changelog/index.md +79 -0
- docs/contributing/code-style.md +69 -0
- docs/contributing/documentation.md +43 -0
- docs/contributing/overview.md +29 -0
- docs/contributing/testing.md +29 -0
- docs/core/crcagent/async-operations.md +65 -0
- docs/core/crcagent/automatic-extraction.md +107 -0
- docs/core/crcagent/batch-prediction.md +80 -0
- docs/core/crcagent/bayesian-inference.md +60 -0
- docs/core/crcagent/causal-graph.md +92 -0
- docs/core/crcagent/counterfactuals.md +96 -0
- docs/core/crcagent/deterministic-simulation.md +78 -0
- docs/core/crcagent/dual-mode-operation.md +82 -0
- docs/core/crcagent/initialization.md +88 -0
- docs/core/crcagent/optimization.md +65 -0
- docs/core/crcagent/overview.md +63 -0
- docs/core/crcagent/time-series.md +57 -0
- docs/core/schemas/annotation.md +30 -0
- docs/core/schemas/core-schemas.md +82 -0
- docs/core/schemas/overview.md +30 -0
- docs/core/schemas/policy.md +41 -0
- docs/core/templates/base-agent.md +31 -0
- docs/core/templates/feature-mixins.md +31 -0
- docs/core/templates/overview.md +29 -0
- docs/core/templates/templates-guide.md +75 -0
- docs/core/tools/mcp-client.md +34 -0
- docs/core/tools/overview.md +24 -0
- docs/core/utils/conversation.md +27 -0
- docs/core/utils/graph-reasoner.md +29 -0
- docs/core/utils/overview.md +27 -0
- docs/core/utils/router.md +27 -0
- docs/core/utils/utilities.md +97 -0
- docs/css/custom.css +84 -0
- docs/examples/basic-usage.md +57 -0
- docs/examples/general-agent/general-agent-examples.md +50 -0
- docs/examples/hybrid-agent/hybrid-agent-examples.md +56 -0
- docs/examples/image-annotation/image-annotation-examples.md +54 -0
- docs/examples/integration/integration-examples.md +58 -0
- docs/examples/overview.md +37 -0
- docs/examples/trading/trading-examples.md +46 -0
- docs/features/causal-reasoning/advanced-topics.md +101 -0
- docs/features/causal-reasoning/counterfactuals.md +43 -0
- docs/features/causal-reasoning/do-calculus.md +50 -0
- docs/features/causal-reasoning/overview.md +47 -0
- docs/features/causal-reasoning/structural-models.md +52 -0
- docs/features/hybrid-agent/advanced-components.md +55 -0
- docs/features/hybrid-agent/core-components.md +64 -0
- docs/features/hybrid-agent/overview.md +34 -0
- docs/features/image-annotation/engine.md +82 -0
- docs/features/image-annotation/features.md +113 -0
- docs/features/image-annotation/integration.md +75 -0
- docs/features/image-annotation/overview.md +53 -0
- docs/features/image-annotation/quickstart.md +73 -0
- docs/features/policy-engine/doctrine-ledger.md +105 -0
- docs/features/policy-engine/monitoring.md +44 -0
- docs/features/policy-engine/mpc-control.md +89 -0
- docs/features/policy-engine/overview.md +46 -0
- docs/getting-started/configuration.md +225 -0
- docs/getting-started/first-agent.md +164 -0
- docs/getting-started/installation.md +144 -0
- docs/getting-started/quickstart.md +137 -0
- docs/index.md +118 -0
- docs/js/mathjax.js +13 -0
- docs/lrm/discovery_proof_notes.md +25 -0
- docs/lrm/finetune_full.md +83 -0
- docs/lrm/math_appendix.md +120 -0
- docs/lrm/overview.md +32 -0
- docs/mkdocs.yml +238 -0
- docs/stylesheets/extra.css +21 -0
- docs_generated/crca_core/CounterfactualResult.md +12 -0
- docs_generated/crca_core/DiscoveryHypothesisResult.md +13 -0
- docs_generated/crca_core/DraftSpec.md +13 -0
- docs_generated/crca_core/EstimateResult.md +13 -0
- docs_generated/crca_core/IdentificationResult.md +17 -0
- docs_generated/crca_core/InterventionDesignResult.md +12 -0
- docs_generated/crca_core/LockedSpec.md +15 -0
- docs_generated/crca_core/RefusalResult.md +12 -0
- docs_generated/crca_core/ValidationReport.md +9 -0
- docs_generated/crca_core/index.md +13 -0
- examples/general_agent_example.py +277 -0
- examples/general_agent_quickstart.py +202 -0
- examples/general_agent_simple.py +92 -0
- examples/hybrid_agent_auto_extraction.py +84 -0
- examples/hybrid_agent_dictionary_demo.py +104 -0
- examples/hybrid_agent_enhanced.py +179 -0
- examples/hybrid_agent_general_knowledge.py +107 -0
- examples/image_annotation_quickstart.py +328 -0
- examples/test_hybrid_fixes.py +77 -0
- image_annotation/__init__.py +27 -0
- image_annotation/annotation_engine.py +2593 -0
- install_cuda_wsl2.sh +59 -0
- install_deepspeed.sh +56 -0
- install_deepspeed_simple.sh +87 -0
- mkdocs.yml +252 -0
- ollama/Modelfile +8 -0
- prompts/__init__.py +2 -1
- prompts/default_crca.py +9 -1
- prompts/general_agent.py +227 -0
- prompts/image_annotation.py +56 -0
- pyproject.toml +17 -2
- requirements-docs.txt +10 -0
- requirements.txt +21 -2
- schemas/__init__.py +26 -1
- schemas/annotation.py +222 -0
- schemas/conversation.py +193 -0
- schemas/hybrid.py +211 -0
- schemas/reasoning.py +276 -0
- schemas_export/crca_core/CounterfactualResult.schema.json +108 -0
- schemas_export/crca_core/DiscoveryHypothesisResult.schema.json +113 -0
- schemas_export/crca_core/DraftSpec.schema.json +635 -0
- schemas_export/crca_core/EstimateResult.schema.json +113 -0
- schemas_export/crca_core/IdentificationResult.schema.json +145 -0
- schemas_export/crca_core/InterventionDesignResult.schema.json +111 -0
- schemas_export/crca_core/LockedSpec.schema.json +646 -0
- schemas_export/crca_core/RefusalResult.schema.json +90 -0
- schemas_export/crca_core/ValidationReport.schema.json +62 -0
- scripts/build_lrm_dataset.py +80 -0
- scripts/export_crca_core_schemas.py +54 -0
- scripts/export_hf_lrm.py +37 -0
- scripts/export_ollama_gguf.py +45 -0
- scripts/generate_changelog.py +157 -0
- scripts/generate_crca_core_docs_from_schemas.py +86 -0
- scripts/run_crca_core_benchmarks.py +163 -0
- scripts/run_full_finetune.py +198 -0
- scripts/run_lrm_eval.py +31 -0
- templates/graph_management.py +29 -0
- tests/conftest.py +9 -0
- tests/test_core.py +2 -3
- tests/test_crca_core_discovery_tabular.py +15 -0
- tests/test_crca_core_estimate_dowhy.py +36 -0
- tests/test_crca_core_identify.py +18 -0
- tests/test_crca_core_intervention_design.py +36 -0
- tests/test_crca_core_linear_gaussian_scm.py +69 -0
- tests/test_crca_core_spec.py +25 -0
- tests/test_crca_core_timeseries_pcmci.py +15 -0
- tests/test_crca_llm_coauthor.py +12 -0
- tests/test_crca_llm_orchestrator.py +80 -0
- tests/test_hybrid_agent_llm_enhanced.py +556 -0
- tests/test_image_annotation_demo.py +376 -0
- tests/test_image_annotation_operational.py +408 -0
- tests/test_image_annotation_unit.py +551 -0
- tests/test_training_moe.py +13 -0
- training/__init__.py +42 -0
- training/datasets.py +140 -0
- training/deepspeed_zero2_0_5b.json +22 -0
- training/deepspeed_zero2_1_5b.json +22 -0
- training/deepspeed_zero3_0_5b.json +28 -0
- training/deepspeed_zero3_14b.json +28 -0
- training/deepspeed_zero3_h100_3gpu.json +20 -0
- training/deepspeed_zero3_offload.json +28 -0
- training/eval.py +92 -0
- training/finetune.py +516 -0
- training/public_datasets.py +89 -0
- training_data/react_train.jsonl +7473 -0
- utils/agent_discovery.py +311 -0
- utils/batch_processor.py +317 -0
- utils/conversation.py +78 -0
- utils/edit_distance.py +118 -0
- utils/formatter.py +33 -0
- utils/graph_reasoner.py +530 -0
- utils/rate_limiter.py +283 -0
- utils/router.py +2 -2
- utils/tool_discovery.py +307 -0
- webui/__init__.py +10 -0
- webui/app.py +229 -0
- webui/config.py +104 -0
- webui/static/css/style.css +332 -0
- webui/static/js/main.js +284 -0
- webui/templates/index.html +42 -0
- tests/test_crca_excel.py +0 -166
- tests/test_data_broker.py +0 -424
- tests/test_palantir.py +0 -349
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/WHEEL +0 -0
- {crca-1.4.0.dist-info → crca-1.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Personality system for configurable agent personality.
|
|
3
|
+
|
|
4
|
+
Provides predefined personalities and support for custom personalities.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Dict, Optional
|
|
8
|
+
from loguru import logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Personality:
|
|
12
|
+
"""Personality configuration for agents.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
name: Personality name
|
|
16
|
+
description: Personality description
|
|
17
|
+
tone: Tone of communication
|
|
18
|
+
style: Communication style
|
|
19
|
+
prompt_template: Template for personality-specific prompts
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
name: str,
|
|
25
|
+
description: str,
|
|
26
|
+
tone: str,
|
|
27
|
+
style: str,
|
|
28
|
+
prompt_template: Optional[str] = None,
|
|
29
|
+
):
|
|
30
|
+
"""Initialize personality.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
name: Personality name
|
|
34
|
+
description: Personality description
|
|
35
|
+
tone: Tone of communication
|
|
36
|
+
style: Communication style
|
|
37
|
+
prompt_template: Optional prompt template
|
|
38
|
+
"""
|
|
39
|
+
self.name = name
|
|
40
|
+
self.description = description
|
|
41
|
+
self.tone = tone
|
|
42
|
+
self.style = style
|
|
43
|
+
self.prompt_template = prompt_template or self._default_template()
|
|
44
|
+
|
|
45
|
+
def _default_template(self) -> str:
|
|
46
|
+
"""Generate default prompt template.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
Default prompt template string
|
|
50
|
+
"""
|
|
51
|
+
return f"""You communicate with a {self.tone} tone and {self.style} style.
|
|
52
|
+
|
|
53
|
+
{self.description}
|
|
54
|
+
|
|
55
|
+
Remember to:
|
|
56
|
+
- Use {self.tone} language
|
|
57
|
+
- Maintain a {self.style} communication style
|
|
58
|
+
- Be helpful and informative
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def get_prompt_addition(self) -> str:
|
|
62
|
+
"""Get prompt addition for this personality.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
Prompt addition string
|
|
66
|
+
"""
|
|
67
|
+
return self.prompt_template
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# Predefined personalities
|
|
71
|
+
PERSONALITIES: Dict[str, Personality] = {
|
|
72
|
+
"neutral": Personality(
|
|
73
|
+
name="neutral",
|
|
74
|
+
description="Professional and neutral communication style, similar to ChatGPT.",
|
|
75
|
+
tone="professional",
|
|
76
|
+
style="neutral",
|
|
77
|
+
prompt_template="""You are a helpful AI assistant with a professional and neutral communication style.
|
|
78
|
+
|
|
79
|
+
Your communication should be:
|
|
80
|
+
- Clear and concise
|
|
81
|
+
- Professional but approachable
|
|
82
|
+
- Factual and informative
|
|
83
|
+
- Balanced in tone
|
|
84
|
+
""",
|
|
85
|
+
),
|
|
86
|
+
"friendly": Personality(
|
|
87
|
+
name="friendly",
|
|
88
|
+
description="Warm and friendly communication style.",
|
|
89
|
+
tone="warm",
|
|
90
|
+
style="friendly",
|
|
91
|
+
prompt_template="""You are a helpful AI assistant with a warm and friendly communication style.
|
|
92
|
+
|
|
93
|
+
Your communication should be:
|
|
94
|
+
- Warm and welcoming
|
|
95
|
+
- Conversational and approachable
|
|
96
|
+
- Encouraging and supportive
|
|
97
|
+
- Personable and engaging
|
|
98
|
+
""",
|
|
99
|
+
),
|
|
100
|
+
"technical": Personality(
|
|
101
|
+
name="technical",
|
|
102
|
+
description="Precise and technical communication style.",
|
|
103
|
+
tone="precise",
|
|
104
|
+
style="technical",
|
|
105
|
+
prompt_template="""You are a helpful AI assistant with a precise and technical communication style.
|
|
106
|
+
|
|
107
|
+
Your communication should be:
|
|
108
|
+
- Precise and accurate
|
|
109
|
+
- Technically detailed
|
|
110
|
+
- Structured and organized
|
|
111
|
+
- Focused on facts and data
|
|
112
|
+
""",
|
|
113
|
+
),
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def get_personality(name: str) -> Optional[Personality]:
|
|
118
|
+
"""Get a predefined personality by name.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
name: Personality name
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Personality instance or None if not found
|
|
125
|
+
"""
|
|
126
|
+
return PERSONALITIES.get(name.lower())
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def create_custom_personality(
|
|
130
|
+
name: str,
|
|
131
|
+
description: str,
|
|
132
|
+
tone: str,
|
|
133
|
+
style: str,
|
|
134
|
+
prompt_template: Optional[str] = None,
|
|
135
|
+
) -> Personality:
|
|
136
|
+
"""Create a custom personality.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
name: Personality name
|
|
140
|
+
description: Personality description
|
|
141
|
+
tone: Tone of communication
|
|
142
|
+
style: Communication style
|
|
143
|
+
prompt_template: Optional custom prompt template
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Custom Personality instance
|
|
147
|
+
"""
|
|
148
|
+
personality = Personality(
|
|
149
|
+
name=name,
|
|
150
|
+
description=description,
|
|
151
|
+
tone=tone,
|
|
152
|
+
style=style,
|
|
153
|
+
prompt_template=prompt_template,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
# Optionally register it
|
|
157
|
+
PERSONALITIES[name.lower()] = personality
|
|
158
|
+
logger.debug(f"Created custom personality: {name}")
|
|
159
|
+
|
|
160
|
+
return personality
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def list_personalities() -> list[str]:
|
|
164
|
+
"""List all available personality names.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
List of personality names
|
|
168
|
+
"""
|
|
169
|
+
return list(PERSONALITIES.keys())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
General Agent utilities module.
|
|
3
|
+
|
|
4
|
+
Provides utility functions for the general agent.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
from .prompt_builder import PromptBuilder
|
|
11
|
+
PROMPT_BUILDER_AVAILABLE = True
|
|
12
|
+
except ImportError:
|
|
13
|
+
PromptBuilder = None
|
|
14
|
+
PROMPT_BUILDER_AVAILABLE = False
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"PromptBuilder",
|
|
18
|
+
"PROMPT_BUILDER_AVAILABLE",
|
|
19
|
+
]
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Prompt builder utility for extendable prompts.
|
|
3
|
+
|
|
4
|
+
Provides template system for prompt construction with support for adding custom sections.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
from loguru import logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PromptBuilder:
|
|
12
|
+
"""Builder for constructing extendable prompts.
|
|
13
|
+
|
|
14
|
+
Provides functionality for:
|
|
15
|
+
- Building prompts from templates
|
|
16
|
+
- Adding custom sections
|
|
17
|
+
- Personality integration
|
|
18
|
+
- Section management
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, base_prompt: Optional[str] = None):
|
|
22
|
+
"""Initialize prompt builder.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
base_prompt: Optional base prompt to start with
|
|
26
|
+
"""
|
|
27
|
+
self.base_prompt = base_prompt or ""
|
|
28
|
+
self.sections: List[Dict[str, Any]] = []
|
|
29
|
+
self.custom_additions: List[str] = []
|
|
30
|
+
logger.debug("Initialized PromptBuilder")
|
|
31
|
+
|
|
32
|
+
def add_section(
|
|
33
|
+
self,
|
|
34
|
+
title: str,
|
|
35
|
+
content: str,
|
|
36
|
+
priority: int = 0,
|
|
37
|
+
) -> "PromptBuilder":
|
|
38
|
+
"""Add a section to the prompt.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
title: Section title
|
|
42
|
+
content: Section content
|
|
43
|
+
priority: Section priority (higher = earlier in prompt)
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
Self for chaining
|
|
47
|
+
"""
|
|
48
|
+
self.sections.append({
|
|
49
|
+
"title": title,
|
|
50
|
+
"content": content,
|
|
51
|
+
"priority": priority,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
# Sort by priority (higher first)
|
|
55
|
+
self.sections.sort(key=lambda x: x["priority"], reverse=True)
|
|
56
|
+
|
|
57
|
+
logger.debug(f"Added section: {title} (priority: {priority})")
|
|
58
|
+
return self
|
|
59
|
+
|
|
60
|
+
def add_custom(self, addition: str) -> "PromptBuilder":
|
|
61
|
+
"""Add custom prompt addition.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
addition: Custom prompt text to add
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Self for chaining
|
|
68
|
+
"""
|
|
69
|
+
self.custom_additions.append(addition)
|
|
70
|
+
logger.debug("Added custom prompt addition")
|
|
71
|
+
return self
|
|
72
|
+
|
|
73
|
+
def add_personality(self, personality_prompt: str) -> "PromptBuilder":
|
|
74
|
+
"""Add personality-specific prompt.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
personality_prompt: Personality prompt text
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
Self for chaining
|
|
81
|
+
"""
|
|
82
|
+
self.add_section("Personality", personality_prompt, priority=10)
|
|
83
|
+
return self
|
|
84
|
+
|
|
85
|
+
def remove_section(self, title: str) -> "PromptBuilder":
|
|
86
|
+
"""Remove a section by title.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
title: Section title to remove
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Self for chaining
|
|
93
|
+
"""
|
|
94
|
+
self.sections = [s for s in self.sections if s["title"] != title]
|
|
95
|
+
logger.debug(f"Removed section: {title}")
|
|
96
|
+
return self
|
|
97
|
+
|
|
98
|
+
def clear_sections(self) -> "PromptBuilder":
|
|
99
|
+
"""Clear all sections.
|
|
100
|
+
|
|
101
|
+
Returns:
|
|
102
|
+
Self for chaining
|
|
103
|
+
"""
|
|
104
|
+
self.sections.clear()
|
|
105
|
+
self.custom_additions.clear()
|
|
106
|
+
logger.debug("Cleared all sections")
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
def build(self, include_base: bool = True) -> str:
|
|
110
|
+
"""Build the final prompt.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
include_base: Whether to include base prompt
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Complete prompt string
|
|
117
|
+
"""
|
|
118
|
+
parts = []
|
|
119
|
+
|
|
120
|
+
# Add base prompt
|
|
121
|
+
if include_base and self.base_prompt:
|
|
122
|
+
parts.append(self.base_prompt)
|
|
123
|
+
|
|
124
|
+
# Add sections
|
|
125
|
+
for section in self.sections:
|
|
126
|
+
title = section["title"]
|
|
127
|
+
content = section["content"]
|
|
128
|
+
parts.append(f"\n## {title}\n\n{content}")
|
|
129
|
+
|
|
130
|
+
# Add custom additions
|
|
131
|
+
for addition in self.custom_additions:
|
|
132
|
+
parts.append(f"\n{addition}")
|
|
133
|
+
|
|
134
|
+
result = "\n".join(parts).strip()
|
|
135
|
+
logger.debug(f"Built prompt with {len(self.sections)} sections and {len(self.custom_additions)} custom additions")
|
|
136
|
+
return result
|
|
137
|
+
|
|
138
|
+
def extend(self, other: "PromptBuilder") -> "PromptBuilder":
|
|
139
|
+
"""Extend this builder with another builder's sections.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
other: Another PromptBuilder to extend with
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
Self for chaining
|
|
146
|
+
"""
|
|
147
|
+
# Add sections from other builder
|
|
148
|
+
for section in other.sections:
|
|
149
|
+
self.add_section(
|
|
150
|
+
section["title"],
|
|
151
|
+
section["content"],
|
|
152
|
+
section["priority"],
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Add custom additions
|
|
156
|
+
self.custom_additions.extend(other.custom_additions)
|
|
157
|
+
|
|
158
|
+
logger.debug(f"Extended with {len(other.sections)} sections from other builder")
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
def copy(self) -> "PromptBuilder":
|
|
162
|
+
"""Create a copy of this builder.
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
New PromptBuilder instance with same content
|
|
166
|
+
"""
|
|
167
|
+
new_builder = PromptBuilder(self.base_prompt)
|
|
168
|
+
new_builder.sections = [s.copy() for s in self.sections]
|
|
169
|
+
new_builder.custom_additions = self.custom_additions.copy()
|
|
170
|
+
return new_builder
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: crca
|
|
3
|
-
Version: 1.
|
|
4
|
-
Summary: CR-CA
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: CR-CA Wrapper for CR-CA LRM on HF (Depricated)
|
|
5
5
|
Project-URL: Homepage, https://github.com/IlumCI/CR-CA
|
|
6
6
|
Project-URL: Repository, https://github.com/IlumCI/CR-CA
|
|
7
7
|
Project-URL: Documentation, https://github.com/IlumCI/CR-CA/blob/main/README.md
|
|
@@ -24,7 +24,10 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
24
24
|
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
26
|
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: accelerate>=0.26.0
|
|
28
|
+
Requires-Dist: causal-learn>=0.1.3.9
|
|
27
29
|
Requires-Dist: ccxt>=4.0
|
|
30
|
+
Requires-Dist: datasets>=2.16.0
|
|
28
31
|
Requires-Dist: dowhy>=0.8
|
|
29
32
|
Requires-Dist: geoip2>=4.7.0
|
|
30
33
|
Requires-Dist: lightgbm>=4.0
|
|
@@ -38,6 +41,7 @@ Requires-Dist: numpy>=1.23
|
|
|
38
41
|
Requires-Dist: openai>=1.0.0
|
|
39
42
|
Requires-Dist: optuna>=3.0
|
|
40
43
|
Requires-Dist: pandas>=1.5
|
|
44
|
+
Requires-Dist: peft>=0.9.0
|
|
41
45
|
Requires-Dist: pillow>=10.0
|
|
42
46
|
Requires-Dist: praw>=7.0
|
|
43
47
|
Requires-Dist: psutil>=5.9.0
|
|
@@ -57,9 +61,11 @@ Requires-Dist: scipy>=1.10
|
|
|
57
61
|
Requires-Dist: seaborn>=0.11
|
|
58
62
|
Requires-Dist: shodan>=1.30.0
|
|
59
63
|
Requires-Dist: swarms
|
|
64
|
+
Requires-Dist: tigramite>=5.2.0
|
|
60
65
|
Requires-Dist: toml>=0.10.2
|
|
61
66
|
Requires-Dist: torch>=2.0.0
|
|
62
67
|
Requires-Dist: tqdm>=4.65.0
|
|
68
|
+
Requires-Dist: transformers>=4.39.0
|
|
63
69
|
Requires-Dist: web3>=6.0
|
|
64
70
|
Requires-Dist: websockets>=11.0
|
|
65
71
|
Requires-Dist: xgboost>=2.0
|