quantnodes 3.0.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.
- QuantNodes/__init__.py +15 -0
- QuantNodes/__main__.py +14 -0
- QuantNodes/agent/__init__.py +158 -0
- QuantNodes/agent/agents/__init__.py +13 -0
- QuantNodes/agent/agents/definition.py +180 -0
- QuantNodes/agent/agents/manager.py +73 -0
- QuantNodes/agent/config/__init__.py +34 -0
- QuantNodes/agent/config/executor.py +958 -0
- QuantNodes/agent/config/loader.py +427 -0
- QuantNodes/agent/config/templates/bollinger_bands.yaml +84 -0
- QuantNodes/agent/config/templates/dual_ma.yaml +72 -0
- QuantNodes/agent/config/templates/empty.yaml +56 -0
- QuantNodes/agent/config/templates/mean_reversion.yaml +47 -0
- QuantNodes/agent/config/templates/mean_reversion_zscore.yaml +90 -0
- QuantNodes/agent/config/templates/momentum.yaml +81 -0
- QuantNodes/agent/config/templates/momentum_breakout.yaml +84 -0
- QuantNodes/agent/config/templates/rsi_strategy.yaml +72 -0
- QuantNodes/agent/config/templates/volume_price.yaml +86 -0
- QuantNodes/agent/config/types.py +156 -0
- QuantNodes/agent/config_mapper.py +293 -0
- QuantNodes/agent/core/__init__.py +19 -0
- QuantNodes/agent/core/dream.py +47 -0
- QuantNodes/agent/core/quant_dream.py +274 -0
- QuantNodes/agent/cron_jobs.py +314 -0
- QuantNodes/agent/nanobot_bridge.py +242 -0
- QuantNodes/agent/permission/__init__.py +30 -0
- QuantNodes/agent/permission/defaults.py +36 -0
- QuantNodes/agent/permission/evaluate.py +41 -0
- QuantNodes/agent/permission/models.py +59 -0
- QuantNodes/agent/permission/service.py +133 -0
- QuantNodes/agent/providers/__init__.py +11 -0
- QuantNodes/agent/providers/base.py +102 -0
- QuantNodes/agent/providers/quantnodes.py +610 -0
- QuantNodes/agent/providers/rate_limiter.py +326 -0
- QuantNodes/agent/providers/registry.py +163 -0
- QuantNodes/agent/skills/__init__.py +20 -0
- QuantNodes/agent/skills/base.py +118 -0
- QuantNodes/agent/skills/bridge.py +73 -0
- QuantNodes/agent/skills/factor/__init__.py +14 -0
- QuantNodes/agent/skills/factor/correlation.py +99 -0
- QuantNodes/agent/skills/factor/group_backtest.py +114 -0
- QuantNodes/agent/skills/factor/ic_analysis.py +106 -0
- QuantNodes/agent/skills/loader.py +107 -0
- QuantNodes/agent/skills/registry.py +105 -0
- QuantNodes/agent/skills/strategy/__init__.py +16 -0
- QuantNodes/agent/skills/strategy/bollinger.py +86 -0
- QuantNodes/agent/skills/strategy/dual_ma.py +82 -0
- QuantNodes/agent/skills/strategy/momentum.py +74 -0
- QuantNodes/agent/skills/strategy/rsi_reversal.py +99 -0
- QuantNodes/agent/skills_quant/__init__.py +14 -0
- QuantNodes/agent/skills_quant/backtest-analyze/SKILL.md +42 -0
- QuantNodes/agent/skills_quant/config-driven/SKILL.md +72 -0
- QuantNodes/agent/skills_quant/factor-research/SKILL.md +40 -0
- QuantNodes/agent/skills_quant/quant-dream/SKILL.md +55 -0
- QuantNodes/agent/skills_quant/risk-management/SKILL.md +45 -0
- QuantNodes/agent/skills_quant/strategy-design/SKILL.md +43 -0
- QuantNodes/agent/templates/__init__.py +4 -0
- QuantNodes/agent/tools/__init__.py +173 -0
- QuantNodes/agent/tools/_workspace.py +51 -0
- QuantNodes/agent/tools/alpha_backtest.py +328 -0
- QuantNodes/agent/tools/alpha_evaluate.py +493 -0
- QuantNodes/agent/tools/backtest.py +226 -0
- QuantNodes/agent/tools/base.py +133 -0
- QuantNodes/agent/tools/code_search.py +207 -0
- QuantNodes/agent/tools/config_backtest.py +401 -0
- QuantNodes/agent/tools/context.py +97 -0
- QuantNodes/agent/tools/dream_skill.py +77 -0
- QuantNodes/agent/tools/echo.py +38 -0
- QuantNodes/agent/tools/factor.py +231 -0
- QuantNodes/agent/tools/file_ops.py +201 -0
- QuantNodes/agent/tools/git_ops.py +190 -0
- QuantNodes/agent/tools/operator_lookup.py +218 -0
- QuantNodes/agent/tools/output_truncation.py +77 -0
- QuantNodes/agent/tools/path_check.py +43 -0
- QuantNodes/agent/tools/pipeline.py +62 -0
- QuantNodes/agent/tools/registry.py +150 -0
- QuantNodes/agent/tools/sandbox.py +62 -0
- QuantNodes/agent/tools/shell_safety.py +63 -0
- QuantNodes/agent/tools/strategy.py +106 -0
- QuantNodes/agent/tools/task.py +171 -0
- QuantNodes/agent/tools/web_fetch.py +142 -0
- QuantNodes/agent/tools/web_search.py +114 -0
- QuantNodes/agent/tools/wiki.py +370 -0
- QuantNodes/agent/utils/__init__.py +11 -0
- QuantNodes/agent/utils/helpers.py +43 -0
- QuantNodes/agent/utils/prompt_templates.py +30 -0
- QuantNodes/agent/workflows/__init__.py +20 -0
- QuantNodes/agent/workflows/implementations/__init__.py +8 -0
- QuantNodes/agent/workflows/implementations/alpha_gpt.py +508 -0
- QuantNodes/agent/workflows/implementations/mcts.py +442 -0
- QuantNodes/agent/workflows/parsers.py +44 -0
- QuantNodes/agent/workflows/registry.py +119 -0
- QuantNodes/agent/workflows/step_agent.py +219 -0
- QuantNodes/agent/workflows/tool.py +198 -0
- QuantNodes/ai/__init__.py +93 -0
- QuantNodes/ai/llm/__init__.py +75 -0
- QuantNodes/ai/llm/base.py +233 -0
- QuantNodes/ai/llm/decorators.py +281 -0
- QuantNodes/ai/llm/gateway.py +571 -0
- QuantNodes/ai/llm/null.py +76 -0
- QuantNodes/ai/llm/openai.py +435 -0
- QuantNodes/ai/optimizer.py +405 -0
- QuantNodes/ai/prompts/__init__.py +229 -0
- QuantNodes/ai/sandbox.py +371 -0
- QuantNodes/ai/sandbox_pandas_bridge.py +150 -0
- QuantNodes/ai/strategy_gen.py +396 -0
- QuantNodes/backtest/__init__.py +64 -0
- QuantNodes/backtest/backtest_node.py +188 -0
- QuantNodes/backtest/broker_node.py +378 -0
- QuantNodes/backtest/config_runner.py +397 -0
- QuantNodes/backtest/config_strategy.py +64 -0
- QuantNodes/backtest/risk_node.py +360 -0
- QuantNodes/backtest/strategy_node.py +268 -0
- QuantNodes/cache_node/__init__.py +19 -0
- QuantNodes/cache_node/base.py +244 -0
- QuantNodes/cache_node/cache_store.py +99 -0
- QuantNodes/cache_node/metadata.py +100 -0
- QuantNodes/cli/__init__.py +109 -0
- QuantNodes/cli/_helpers.py +511 -0
- QuantNodes/cli/command.py +110 -0
- QuantNodes/cli/commands/__init__.py +69 -0
- QuantNodes/cli/commands/agent.py +158 -0
- QuantNodes/cli/commands/alpha.py +951 -0
- QuantNodes/cli/commands/chat.py +38 -0
- QuantNodes/cli/commands/evolve.py +120 -0
- QuantNodes/cli/commands/factor.py +569 -0
- QuantNodes/cli/commands/init.py +190 -0
- QuantNodes/cli/commands/run.py +259 -0
- QuantNodes/cli/commands/serve.py +398 -0
- QuantNodes/cli/commands/version.py +120 -0
- QuantNodes/cli/enhanced.py +146 -0
- QuantNodes/conf_node/__init__.py +37 -0
- QuantNodes/conf_node/base.py +120 -0
- QuantNodes/conf_node/env_config.py +132 -0
- QuantNodes/conf_node/ini_config.py +70 -0
- QuantNodes/conf_node/json_config.py +69 -0
- QuantNodes/conf_node/yaml_config.py +78 -0
- QuantNodes/constants.py +17 -0
- QuantNodes/core/__init__.py +196 -0
- QuantNodes/core/_lookback_helpers.py +49 -0
- QuantNodes/core/ast_parser.py +198 -0
- QuantNodes/core/base.py +61 -0
- QuantNodes/core/cache_manager.py +344 -0
- QuantNodes/core/cache_utils.py +150 -0
- QuantNodes/core/cond_builder.py +53 -0
- QuantNodes/core/config.py +170 -0
- QuantNodes/core/constants.py +48 -0
- QuantNodes/core/control.py +412 -0
- QuantNodes/core/data_preprocessing.py +453 -0
- QuantNodes/core/data_source.py +46 -0
- QuantNodes/core/events.py +178 -0
- QuantNodes/core/evolution/__init__.py +22 -0
- QuantNodes/core/evolution/loop.py +583 -0
- QuantNodes/core/evolution/operators.py +289 -0
- QuantNodes/core/evolution/settings.py +44 -0
- QuantNodes/core/expression.py +841 -0
- QuantNodes/core/feedback/__init__.py +38 -0
- QuantNodes/core/feedback/channels.py +182 -0
- QuantNodes/core/feedback/collector.py +91 -0
- QuantNodes/core/feedback/dataclass.py +239 -0
- QuantNodes/core/feedback/llm_judge.py +138 -0
- QuantNodes/core/knowledge/__init__.py +69 -0
- QuantNodes/core/knowledge/knowledge_base.py +217 -0
- QuantNodes/core/knowledge/lineage_compress.py +196 -0
- QuantNodes/core/knowledge/lineage_expand.py +123 -0
- QuantNodes/core/knowledge/metrics/__init__.py +43 -0
- QuantNodes/core/knowledge/metrics/evaluator.py +176 -0
- QuantNodes/core/knowledge/metrics/metrics.py +220 -0
- QuantNodes/core/knowledge/rag_prompt.py +196 -0
- QuantNodes/core/knowledge/retriever.py +209 -0
- QuantNodes/core/lambda_node.py +81 -0
- QuantNodes/core/monitoring/__init__.py +22 -0
- QuantNodes/core/monitoring/collector.py +292 -0
- QuantNodes/core/monitoring/dashboard.py +365 -0
- QuantNodes/core/node.py +375 -0
- QuantNodes/core/pandas_utils.py +504 -0
- QuantNodes/core/parallel/__init__.py +15 -0
- QuantNodes/core/parallel/worker.py +140 -0
- QuantNodes/core/parallel/worker_process.py +265 -0
- QuantNodes/core/path_utils.py +73 -0
- QuantNodes/core/pipeline.py +328 -0
- QuantNodes/core/plugin.py +135 -0
- QuantNodes/core/quality_gate/__init__.py +32 -0
- QuantNodes/core/quality_gate/complexity.py +94 -0
- QuantNodes/core/quality_gate/consistency.py +26 -0
- QuantNodes/core/quality_gate/node.py +97 -0
- QuantNodes/core/quality_gate/redundancy.py +51 -0
- QuantNodes/core/quality_gate/settings.py +43 -0
- QuantNodes/core/quality_gate/zoo.py +98 -0
- QuantNodes/core/serializable.py +116 -0
- QuantNodes/core/serialization.py +673 -0
- QuantNodes/core/tools.py +333 -0
- QuantNodes/core/trajectory/__init__.py +25 -0
- QuantNodes/core/trajectory/entry.py +116 -0
- QuantNodes/core/trajectory/lineage.py +67 -0
- QuantNodes/core/trajectory/pool.py +211 -0
- QuantNodes/core/trajectory/selector.py +140 -0
- QuantNodes/core/visualization/__init__.py +33 -0
- QuantNodes/core/visualization/builder.py +233 -0
- QuantNodes/core/visualization/gate_breakdown.py +140 -0
- QuantNodes/core/visualization/lineage_dag.py +203 -0
- QuantNodes/core/visualization/metric_distribution.py +125 -0
- QuantNodes/core/visualization/report.py +68 -0
- QuantNodes/database_node/__init__.py +69 -0
- QuantNodes/database_node/base.py +135 -0
- QuantNodes/database_node/clickhouse_node.py +272 -0
- QuantNodes/database_node/csv_node.py +83 -0
- QuantNodes/database_node/duckdb_node.py +86 -0
- QuantNodes/database_node/factory.py +83 -0
- QuantNodes/database_node/mysql_node.py +100 -0
- QuantNodes/database_node/parquet_node.py +75 -0
- QuantNodes/database_node/sqlite_node.py +67 -0
- QuantNodes/factor_node/__init__.py +50 -0
- QuantNodes/factor_node/factor.py +563 -0
- QuantNodes/factor_node/factor_db.py +421 -0
- QuantNodes/factor_node/factor_functions/__init__.py +252 -0
- QuantNodes/factor_node/factor_functions/_helpers.py +358 -0
- QuantNodes/factor_node/factor_functions/_helpers_debug.py +317 -0
- QuantNodes/factor_node/factor_functions/composite_ops.py +136 -0
- QuantNodes/factor_node/factor_functions/math_ops.py +433 -0
- QuantNodes/factor_node/factor_functions/section_ops.py +290 -0
- QuantNodes/factor_node/factor_functions/talib_ops.py +1293 -0
- QuantNodes/factor_node/factor_functions/time_ops.py +535 -0
- QuantNodes/factor_node/factor_operation.py +1115 -0
- QuantNodes/factor_node/factor_table.py +1073 -0
- QuantNodes/factor_node/quant_nodes_object.py +60 -0
- QuantNodes/mcp_server/__init__.py +27 -0
- QuantNodes/mcp_server/__main__.py +4 -0
- QuantNodes/mcp_server/server.py +272 -0
- QuantNodes/methods/__init__.py +28 -0
- QuantNodes/methods/pipeline.py +100 -0
- QuantNodes/methods/sandbox.py +102 -0
- QuantNodes/monitor/__init__.py +27 -0
- QuantNodes/monitor/agent_tools/__init__.py +5 -0
- QuantNodes/monitor/agent_tools/monitor_tool.py +98 -0
- QuantNodes/monitor/agent_tools/schedule_tool.py +98 -0
- QuantNodes/monitor/agent_tools/version_tool.py +133 -0
- QuantNodes/monitor/monitor/__init__.py +6 -0
- QuantNodes/monitor/monitor/alerter.py +60 -0
- QuantNodes/monitor/monitor/collector.py +164 -0
- QuantNodes/monitor/monitor/dashboard.py +115 -0
- QuantNodes/monitor/monitor/drift.py +190 -0
- QuantNodes/monitor/scheduler/__init__.py +4 -0
- QuantNodes/monitor/scheduler/runner.py +133 -0
- QuantNodes/monitor/scheduler/scheduler.py +184 -0
- QuantNodes/monitor/storage/__init__.py +16 -0
- QuantNodes/monitor/storage/models.py +70 -0
- QuantNodes/monitor/storage/repository.py +407 -0
- QuantNodes/monitor/version/__init__.py +4 -0
- QuantNodes/monitor/version/diff.py +81 -0
- QuantNodes/monitor/version/version_manager.py +182 -0
- QuantNodes/operator_node/__init__.py +28 -0
- QuantNodes/operator_node/base.py +97 -0
- QuantNodes/operator_node/query_node.py +129 -0
- QuantNodes/operator_node/sql_builder.py +125 -0
- QuantNodes/operator_node/sql_utils.py +172 -0
- QuantNodes/operator_node/transform.py +130 -0
- QuantNodes/operators/__init__.py +90 -0
- QuantNodes/operators/_engine.py +108 -0
- QuantNodes/operators/composite.py +161 -0
- QuantNodes/operators/composite_dag.py +667 -0
- QuantNodes/operators/composite_dag_ops.py +343 -0
- QuantNodes/operators/composite_dag_pandas_ops.py +382 -0
- QuantNodes/operators/custom.py +408 -0
- QuantNodes/operators/facade.py +164 -0
- QuantNodes/operators/math.py +163 -0
- QuantNodes/operators/proxy.py +29 -0
- QuantNodes/operators/registry.py +144 -0
- QuantNodes/operators/section.py +99 -0
- QuantNodes/operators/talib.py +757 -0
- QuantNodes/operators/templates.py +95 -0
- QuantNodes/operators/time_series.py +136 -0
- QuantNodes/prompts/__init__.py +20 -0
- QuantNodes/prompts/backtest/__init__.py +12 -0
- QuantNodes/prompts/backtest/factor_based.py +86 -0
- QuantNodes/prompts/backtest/standard.py +73 -0
- QuantNodes/prompts/factor/__init__.py +14 -0
- QuantNodes/prompts/factor/correlation.py +77 -0
- QuantNodes/prompts/factor/group_backtest.py +86 -0
- QuantNodes/prompts/factor/ic_analysis.py +91 -0
- QuantNodes/prompts/strategy/__init__.py +18 -0
- QuantNodes/prompts/strategy/market_neutral.py +96 -0
- QuantNodes/prompts/strategy/mean_reversion.py +107 -0
- QuantNodes/prompts/strategy/momentum.py +160 -0
- QuantNodes/prompts/strategy/pairs_trading.py +107 -0
- QuantNodes/prompts/strategy/trend_following.py +96 -0
- QuantNodes/research/README.md +106 -0
- QuantNodes/research/__init__.py +154 -0
- QuantNodes/research/_legacy_3c/__init__.py +61 -0
- QuantNodes/research/_legacy_3c/auto_researcher.py +289 -0
- QuantNodes/research/_legacy_3c/factor_evaluator.py +560 -0
- QuantNodes/research/_legacy_3c/factor_miner.py +318 -0
- QuantNodes/research/_legacy_3c/mcts_search.py +324 -0
- QuantNodes/research/factor_test/__init__.py +25 -0
- QuantNodes/research/factor_test/config.py +184 -0
- QuantNodes/research/factor_test/config_builder.py +276 -0
- QuantNodes/research/factor_test/e2e/data_prep.py +163 -0
- QuantNodes/research/factor_test/e2e/run_evolution_e2e.py +309 -0
- QuantNodes/research/factor_test/evolution_adapter.py +231 -0
- QuantNodes/research/factor_test/feedback_wrapper.py +102 -0
- QuantNodes/research/factor_test/ifind_db/__init__.py +7 -0
- QuantNodes/research/factor_test/ifind_db/fetcher.py +224 -0
- QuantNodes/research/factor_test/ifind_db/ifind_database.py +689 -0
- QuantNodes/research/factor_test/nodes/__init__.py +1 -0
- QuantNodes/research/factor_test/nodes/_base.py +91 -0
- QuantNodes/research/factor_test/nodes/adjust_date_node.py +48 -0
- QuantNodes/research/factor_test/nodes/configs.py +240 -0
- QuantNodes/research/factor_test/nodes/factor_neutralize_node.py +87 -0
- QuantNodes/research/factor_test/nodes/factor_preprocess_node.py +222 -0
- QuantNodes/research/factor_test/nodes/factor_score_node.py +141 -0
- QuantNodes/research/factor_test/nodes/factor_test_report_node.py +153 -0
- QuantNodes/research/factor_test/nodes/group_analyzer_node.py +317 -0
- QuantNodes/research/factor_test/nodes/ic_analyzer_node.py +112 -0
- QuantNodes/research/factor_test/nodes/load_data_node.py +100 -0
- QuantNodes/research/factor_test/nodes/long_short_node.py +93 -0
- QuantNodes/research/factor_test/nodes/neutralizers.py +222 -0
- QuantNodes/research/factor_test/nodes/preprocess_strategies.py +277 -0
- QuantNodes/research/factor_test/nodes/risk_correlation_node.py +112 -0
- QuantNodes/research/factor_test/nodes/sample_pool_filter_node.py +110 -0
- QuantNodes/research/factor_test/nodes/tradability_filter_node.py +92 -0
- QuantNodes/research/factor_test/pipeline_runner.py +305 -0
- QuantNodes/research/factor_test/pipeline_spec.py +216 -0
- QuantNodes/research/factor_test/utils/__init__.py +26 -0
- QuantNodes/research/factor_test/utils/constants.py +86 -0
- QuantNodes/research/factor_test/utils/data_loader.py +141 -0
- QuantNodes/research/factor_test/utils/date_utils.py +232 -0
- QuantNodes/research/factor_test/utils/file_loaders.py +150 -0
- QuantNodes/research/factor_test/utils/labels.py +37 -0
- QuantNodes/research/factor_test/utils/metrics_extractor.py +55 -0
- QuantNodes/research/factor_test/utils/performance_metrics.py +175 -0
- QuantNodes/research/factor_test/utils/safe_load.py +106 -0
- QuantNodes/research/quant_alpha/CHANGELOG.md +80 -0
- QuantNodes/research/quant_alpha/README.md +142 -0
- QuantNodes/research/quant_alpha/__init__.py +45 -0
- QuantNodes/research/quant_alpha/adapters/__init__.py +99 -0
- QuantNodes/research/quant_alpha/adapters/calculator.py +503 -0
- QuantNodes/research/quant_alpha/adapters/expression.py +387 -0
- QuantNodes/research/quant_alpha/alpha101_design/__init__.py +50 -0
- QuantNodes/research/quant_alpha/alpha101_design/few_shot_examples.py +243 -0
- QuantNodes/research/quant_alpha/alpha101_design/philosophy.py +474 -0
- QuantNodes/research/quant_alpha/alpha158_design/__init__.py +63 -0
- QuantNodes/research/quant_alpha/alpha158_design/few_shot_examples.py +219 -0
- QuantNodes/research/quant_alpha/alpha158_design/philosophy.py +240 -0
- QuantNodes/research/quant_alpha/evaluation/__init__.py +47 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/__init__.py +8 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g1_handcrafted.py +135 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g2_llm_only.py +269 -0
- QuantNodes/research/quant_alpha/evaluation/baselines/g3_alpha_gpt.py +152 -0
- QuantNodes/research/quant_alpha/evaluation/clickhouse_data_loader.py +227 -0
- QuantNodes/research/quant_alpha/evaluation/contracts.py +376 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/__init__.py +6 -0
- QuantNodes/research/quant_alpha/evaluation/evaluators/polars_evaluator.py +545 -0
- QuantNodes/research/quant_alpha/evaluation/mock_data_loader.py +226 -0
- QuantNodes/research/quant_alpha/evaluation/runner.py +243 -0
- QuantNodes/research/quant_alpha/llm/__init__.py +38 -0
- QuantNodes/research/quant_alpha/llm/parser.py +681 -0
- QuantNodes/research/quant_alpha/logic_driven_pipeline.py +411 -0
- QuantNodes/research/quant_alpha/logic_mining/__init__.py +74 -0
- QuantNodes/research/quant_alpha/logic_mining/compiler.py +457 -0
- QuantNodes/research/quant_alpha/logic_mining/generator.py +366 -0
- QuantNodes/research/quant_alpha/logic_mining/models.py +252 -0
- QuantNodes/research/quant_alpha/logic_mining/parser.py +287 -0
- QuantNodes/research/quant_alpha/logic_mining/pipelines.py +297 -0
- QuantNodes/research/quant_alpha/logic_mining/sources.py +149 -0
- QuantNodes/research/quant_alpha/mcts/__init__.py +66 -0
- QuantNodes/research/quant_alpha/mcts/cache.py +262 -0
- QuantNodes/research/quant_alpha/mcts/extension_ops.py +320 -0
- QuantNodes/research/quant_alpha/mcts/feedback.py +825 -0
- QuantNodes/research/quant_alpha/mcts/op_prior.py +180 -0
- QuantNodes/research/quant_alpha/mcts/search.py +540 -0
- QuantNodes/research/quant_alpha/mcts/tree.py +201 -0
- QuantNodes/research/quant_alpha/operator_vocab/__init__.py +50 -0
- QuantNodes/research/quant_alpha/operator_vocab/config.py +54 -0
- QuantNodes/research/quant_alpha/operator_vocab/metadata.py +263 -0
- QuantNodes/research/quant_alpha/operator_vocab/vocabulary.py +481 -0
- QuantNodes/research/quant_alpha/pipeline.py +1027 -0
- QuantNodes/research/quant_alpha/types/__init__.py +27 -0
- QuantNodes/research/quant_alpha/types/constants.py +28 -0
- QuantNodes/research/quant_alpha/types/state.py +205 -0
- QuantNodes/research/quant_alpha/workflow/__init__.py +32 -0
- QuantNodes/research/quant_alpha/workflow/alpha_gpt.py +911 -0
- QuantNodes/research/quant_alpha/workflow/alpha_logics.py +416 -0
- QuantNodes/research/quant_alpha/workflow/state.py +27 -0
- QuantNodes/research/report_reproducer.py +485 -0
- QuantNodes/research/wiki.py +1155 -0
- QuantNodes/symbolic/__init__.py +51 -0
- QuantNodes/symbolic/compiler.py +113 -0
- QuantNodes/symbolic/dialect.py +260 -0
- QuantNodes/symbolic/executor.py +147 -0
- QuantNodes/symbolic/expression.py +234 -0
- QuantNodes/symbolic/functions.py +433 -0
- QuantNodes/symbolic/optimizer.py +165 -0
- QuantNodes/ui_node/__init__.py +30 -0
- QuantNodes/ui_node/base.py +222 -0
- quantnodes-3.0.0.dist-info/METADATA +463 -0
- quantnodes-3.0.0.dist-info/RECORD +399 -0
- quantnodes-3.0.0.dist-info/WHEEL +5 -0
- quantnodes-3.0.0.dist-info/entry_points.txt +24 -0
- quantnodes-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""StepAgent — 轻量级单次 LLM 步骤。
|
|
3
|
+
|
|
4
|
+
无工具循环、无会话历史、无 Hook/Streaming。
|
|
5
|
+
用于 WorkflowTool 内部的 pipeline 步骤执行。
|
|
6
|
+
|
|
7
|
+
Usage::
|
|
8
|
+
|
|
9
|
+
from QuantNodes.agent.workflows.step_agent import StepAgent, StepAgentSpec
|
|
10
|
+
|
|
11
|
+
spec = StepAgentSpec(
|
|
12
|
+
agent_id="my-step",
|
|
13
|
+
prompt_builder=lambda **ctx: "do something",
|
|
14
|
+
output_parser=lambda raw: ParseResult(ok=True, data=json.loads(raw)),
|
|
15
|
+
output_key="results",
|
|
16
|
+
record_factory=lambda d: d,
|
|
17
|
+
)
|
|
18
|
+
agent = StepAgent(spec, llm_client=my_provider)
|
|
19
|
+
records = agent.run(state=state, round_idx=1, **config)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import asyncio
|
|
25
|
+
import json
|
|
26
|
+
import logging
|
|
27
|
+
from dataclasses import dataclass, field
|
|
28
|
+
from typing import Any, Callable, Optional
|
|
29
|
+
|
|
30
|
+
from QuantNodes.research.quant_alpha.llm.parser import ParseResult
|
|
31
|
+
|
|
32
|
+
logger = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class StepAgentSpec:
|
|
37
|
+
"""单个 pipeline 步骤的规格定义。"""
|
|
38
|
+
|
|
39
|
+
agent_id: str
|
|
40
|
+
"""步骤标识,如 "alpha-gpt-idea-generator"。"""
|
|
41
|
+
|
|
42
|
+
prompt_builder: Optional[Callable[..., str]] = None
|
|
43
|
+
"""(**ctx) -> prompt str。evaluator 步骤为 None。"""
|
|
44
|
+
|
|
45
|
+
output_parser: Optional[Callable[[str], ParseResult]] = None
|
|
46
|
+
"""(raw) -> ParseResult。evaluator 步骤为 None。"""
|
|
47
|
+
|
|
48
|
+
output_key: str = ""
|
|
49
|
+
"""JSON 输出的 key,如 "ideas", "formulas"。"""
|
|
50
|
+
|
|
51
|
+
record_factory: Optional[Callable[[dict], Any]] = None
|
|
52
|
+
"""(dict) -> Record。evaluator 步骤为 None(tool_executor 直接返回 records)。"""
|
|
53
|
+
|
|
54
|
+
state_output: Optional[str] = None
|
|
55
|
+
"""写入 state 的字段名,如 "all_ideas"。None = 不更新 state。"""
|
|
56
|
+
|
|
57
|
+
state_input: Optional[str] = None
|
|
58
|
+
"""从 state 读取的字段名,注入到 prompt_builder 的 context。"""
|
|
59
|
+
|
|
60
|
+
tool_executor: Optional[Callable[..., list[Any]]] = None
|
|
61
|
+
"""直接调用的工具函数(跳过 LLM)。evaluator 步骤用。"""
|
|
62
|
+
|
|
63
|
+
max_retries: int = 2
|
|
64
|
+
"""解析失败重试次数。总共尝试 max_retries + 1 次。"""
|
|
65
|
+
|
|
66
|
+
skip_on_last: bool = False
|
|
67
|
+
"""最后一轮是否跳过。reflector 步骤用。"""
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class StepAgent:
|
|
71
|
+
"""轻量级单次 LLM 步骤。无工具循环、无会话历史。
|
|
72
|
+
|
|
73
|
+
由 WorkflowTool 的 execute() 循环调用。
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
def __init__(self, spec: StepAgentSpec, llm_client: Any = None) -> None:
|
|
77
|
+
self.spec = spec
|
|
78
|
+
self.llm_client = llm_client
|
|
79
|
+
|
|
80
|
+
def run(
|
|
81
|
+
self,
|
|
82
|
+
state: Any = None,
|
|
83
|
+
round_idx: Optional[int] = None,
|
|
84
|
+
prev_output: Optional[list[Any]] = None,
|
|
85
|
+
**context: Any,
|
|
86
|
+
) -> list[Any]:
|
|
87
|
+
"""执行: prompt → LLM → parse(带重试+修复) → records。
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
state: workflow 状态对象。prompt_builder 可从中读取累积数据。
|
|
91
|
+
round_idx: 当前轮次 (多轮 workflow 用)。
|
|
92
|
+
prev_output: 上一步的输出 (轮内链式传递)。
|
|
93
|
+
**context: 其他参数 (config 等)。
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
解析后的 records 列表。失败时返回空列表。
|
|
97
|
+
"""
|
|
98
|
+
# 从 state 读取 state_input
|
|
99
|
+
if self.spec.state_input and state is not None:
|
|
100
|
+
context[self.spec.state_input] = getattr(state, self.spec.state_input)
|
|
101
|
+
|
|
102
|
+
# 轮内上一步输出
|
|
103
|
+
if prev_output is not None:
|
|
104
|
+
context["prev_output"] = prev_output
|
|
105
|
+
|
|
106
|
+
context["state"] = state
|
|
107
|
+
context["round_idx"] = round_idx
|
|
108
|
+
|
|
109
|
+
# tool_executor 路径 (evaluator)
|
|
110
|
+
if self.spec.tool_executor is not None:
|
|
111
|
+
return self._run_tool(**context)
|
|
112
|
+
|
|
113
|
+
# LLM 路径 (带重试)
|
|
114
|
+
if self.spec.prompt_builder is None or self.spec.output_parser is None:
|
|
115
|
+
logger.warning("StepAgent %s: no prompt_builder or output_parser", self.spec.agent_id)
|
|
116
|
+
return []
|
|
117
|
+
|
|
118
|
+
result = self._run_with_retry(**context)
|
|
119
|
+
if not result.ok:
|
|
120
|
+
logger.warning(
|
|
121
|
+
"StepAgent %s: all %d attempts failed. Last error: %s",
|
|
122
|
+
self.spec.agent_id,
|
|
123
|
+
self.spec.max_retries + 1,
|
|
124
|
+
result.error,
|
|
125
|
+
)
|
|
126
|
+
return []
|
|
127
|
+
|
|
128
|
+
items = (result.data or {}).get(self.spec.output_key, [])
|
|
129
|
+
if self.spec.record_factory is not None:
|
|
130
|
+
return [self.spec.record_factory(item) for item in items]
|
|
131
|
+
return items
|
|
132
|
+
|
|
133
|
+
def _run_tool(self, **context: Any) -> list[Any]:
|
|
134
|
+
"""调用 tool_executor(同步或异步)。"""
|
|
135
|
+
result = self.spec.tool_executor(**context)
|
|
136
|
+
if asyncio.iscoroutine(result) or asyncio.isfuture(result):
|
|
137
|
+
return _run_async(result)
|
|
138
|
+
return result
|
|
139
|
+
|
|
140
|
+
def _run_with_retry(self, **context: Any) -> ParseResult:
|
|
141
|
+
"""重试逻辑: 解析失败时注入完整 raw + error 到 prompt。"""
|
|
142
|
+
prompt = self.spec.prompt_builder(**context)
|
|
143
|
+
result: Optional[ParseResult] = None
|
|
144
|
+
|
|
145
|
+
for attempt in range(self.spec.max_retries + 1):
|
|
146
|
+
raw = self._call_llm(prompt)
|
|
147
|
+
result = self.spec.output_parser(raw)
|
|
148
|
+
if result.ok:
|
|
149
|
+
return result
|
|
150
|
+
|
|
151
|
+
if attempt < self.spec.max_retries:
|
|
152
|
+
logger.info(
|
|
153
|
+
"StepAgent %s: attempt %d/%d parse failed, retrying with error context",
|
|
154
|
+
self.spec.agent_id,
|
|
155
|
+
attempt + 1,
|
|
156
|
+
self.spec.max_retries + 1,
|
|
157
|
+
)
|
|
158
|
+
prompt = self.spec.prompt_builder(
|
|
159
|
+
**context,
|
|
160
|
+
_prev_error=result.error,
|
|
161
|
+
_prev_raw=result.raw,
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
return result # type: ignore[return-value]
|
|
165
|
+
|
|
166
|
+
def _call_llm(self, prompt: str) -> str:
|
|
167
|
+
"""调用 LLM。
|
|
168
|
+
|
|
169
|
+
优先级: client.complete(agent_id, prompt) → client(prompt) → mock。
|
|
170
|
+
"""
|
|
171
|
+
client = self.llm_client
|
|
172
|
+
if client is None:
|
|
173
|
+
return self._mock_response(prompt)
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
if hasattr(client, "complete"):
|
|
177
|
+
return client.complete(agent_id=self.spec.agent_id, prompt=prompt)
|
|
178
|
+
if callable(client):
|
|
179
|
+
return client(prompt)
|
|
180
|
+
except Exception as exc:
|
|
181
|
+
logger.error("StepAgent %s: LLM call failed: %s", self.spec.agent_id, exc)
|
|
182
|
+
return ""
|
|
183
|
+
|
|
184
|
+
return self._mock_response(prompt)
|
|
185
|
+
|
|
186
|
+
def _mock_response(self, prompt: str) -> str:
|
|
187
|
+
"""无 LLM 时返回空 JSON。测试用。"""
|
|
188
|
+
return "{}"
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _run_async(coro: Any) -> Any:
|
|
192
|
+
"""在同步上下文中运行异步协程。
|
|
193
|
+
|
|
194
|
+
处理三种情况:
|
|
195
|
+
1. 没有 event loop → asyncio.run()
|
|
196
|
+
2. 有 event loop 但不在其中 → loop.run_until_complete()
|
|
197
|
+
3. 在 event loop 中(如 Jupyter)→ ThreadPoolExecutor
|
|
198
|
+
"""
|
|
199
|
+
try:
|
|
200
|
+
loop = asyncio.get_running_loop()
|
|
201
|
+
except RuntimeError:
|
|
202
|
+
loop = None
|
|
203
|
+
|
|
204
|
+
if loop is None or loop.is_closed():
|
|
205
|
+
return asyncio.run(coro)
|
|
206
|
+
|
|
207
|
+
# 在 event loop 中,用线程池绕过
|
|
208
|
+
import concurrent.futures
|
|
209
|
+
|
|
210
|
+
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool:
|
|
211
|
+
future = pool.submit(asyncio.run, coro)
|
|
212
|
+
return future.result()
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
__all__ = [
|
|
216
|
+
"StepAgent",
|
|
217
|
+
"StepAgentSpec",
|
|
218
|
+
"ParseResult",
|
|
219
|
+
]
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""WorkflowTool — nanobot Tool 子类,暴露 run_workflow 给 LLM。
|
|
3
|
+
|
|
4
|
+
Usage::
|
|
5
|
+
|
|
6
|
+
from QuantNodes.agent.workflows.tool import WorkflowTool
|
|
7
|
+
|
|
8
|
+
wt = WorkflowTool(llm_client=provider, model="minimax-M3")
|
|
9
|
+
# 然后 registry.register(wt)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import asyncio
|
|
15
|
+
import json
|
|
16
|
+
import logging
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Optional
|
|
20
|
+
|
|
21
|
+
from QuantNodes.agent.tools.base import Tool
|
|
22
|
+
from .registry import REGISTRY
|
|
23
|
+
from .step_agent import StepAgent
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _update_state(state: Any, step_spec: Any, records: list[Any]) -> None:
|
|
29
|
+
"""根据 step_spec.state_output 更新 state。
|
|
30
|
+
|
|
31
|
+
- 如果 state 字段是 list → extend (追加)
|
|
32
|
+
- 否则 → setattr (覆盖)
|
|
33
|
+
"""
|
|
34
|
+
if not step_spec.state_output:
|
|
35
|
+
return
|
|
36
|
+
if not hasattr(state, step_spec.state_output):
|
|
37
|
+
return
|
|
38
|
+
target = getattr(state, step_spec.state_output)
|
|
39
|
+
if isinstance(target, list):
|
|
40
|
+
target.extend(records)
|
|
41
|
+
else:
|
|
42
|
+
setattr(state, step_spec.state_output, records)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class WorkflowTool(Tool):
|
|
46
|
+
"""nanobot Tool 子类,暴露 run_workflow 给 LLM。
|
|
47
|
+
|
|
48
|
+
执行逻辑:
|
|
49
|
+
1. 从 REGISTRY 查找 WorkflowSpec
|
|
50
|
+
2. 构造 state
|
|
51
|
+
3. 多轮循环执行 steps (支持 skip_on_last + prev_output 链式传递)
|
|
52
|
+
4. 执行 final_steps
|
|
53
|
+
5. result_builder 构建结果
|
|
54
|
+
6. 存 JSON 文件 + 返回摘要
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
_scopes = {"core", "subagent"}
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
llm_client: Any = None,
|
|
62
|
+
model: Optional[str] = None,
|
|
63
|
+
results_dir: Optional[Path] = None,
|
|
64
|
+
) -> None:
|
|
65
|
+
self._llm_client = llm_client
|
|
66
|
+
self._model = model
|
|
67
|
+
self._results_dir = results_dir or Path(".agent/results")
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def name(self) -> str:
|
|
71
|
+
return "run_workflow"
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def description(self) -> str:
|
|
75
|
+
return REGISTRY.build_llm_description()
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def parameters(self) -> dict[str, Any]:
|
|
79
|
+
return {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"workflow": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"description": "The workflow name to execute.",
|
|
85
|
+
},
|
|
86
|
+
"config": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"description": (
|
|
89
|
+
"Workflow-specific configuration. "
|
|
90
|
+
"See workflow description for available parameters."
|
|
91
|
+
),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
"required": ["workflow"],
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async def execute(
|
|
98
|
+
self,
|
|
99
|
+
workflow: str,
|
|
100
|
+
config: Optional[dict[str, Any]] = None,
|
|
101
|
+
**kwargs: Any,
|
|
102
|
+
) -> str:
|
|
103
|
+
"""执行 workflow。
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
workflow: workflow 名称 (从 REGISTRY 查找)。
|
|
107
|
+
config: workflow 配置参数。
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
摘要 JSON 字符串。
|
|
111
|
+
"""
|
|
112
|
+
spec = REGISTRY.get(workflow)
|
|
113
|
+
if spec is None:
|
|
114
|
+
available = [s["name"] for s in REGISTRY.list_all()]
|
|
115
|
+
return json.dumps(
|
|
116
|
+
{"status": "error", "message": f"Unknown workflow: {workflow!r}. Available: {available}"},
|
|
117
|
+
ensure_ascii=False,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
config = config or {}
|
|
121
|
+
client = self._llm_client
|
|
122
|
+
iterations = config.get("iterations", spec.iterations)
|
|
123
|
+
|
|
124
|
+
logger.info("WorkflowTool: starting %r (%d iterations)", workflow, iterations)
|
|
125
|
+
|
|
126
|
+
# 构造 state
|
|
127
|
+
state = spec.state_factory()
|
|
128
|
+
|
|
129
|
+
# 多轮循环
|
|
130
|
+
for round_idx in range(1, iterations + 1):
|
|
131
|
+
is_last = (round_idx == iterations)
|
|
132
|
+
prev_output: Optional[list[Any]] = None
|
|
133
|
+
|
|
134
|
+
for step_spec in spec.steps:
|
|
135
|
+
if step_spec.skip_on_last and is_last:
|
|
136
|
+
logger.info("WorkflowTool: skipping %s on last round", step_spec.agent_id)
|
|
137
|
+
continue
|
|
138
|
+
|
|
139
|
+
logger.info(
|
|
140
|
+
"WorkflowTool: round %d/%d step %s",
|
|
141
|
+
round_idx, iterations, step_spec.agent_id,
|
|
142
|
+
)
|
|
143
|
+
step = StepAgent(step_spec, llm_client=client)
|
|
144
|
+
records = await asyncio.to_thread(
|
|
145
|
+
step.run,
|
|
146
|
+
state=state,
|
|
147
|
+
round_idx=round_idx,
|
|
148
|
+
prev_output=prev_output,
|
|
149
|
+
**config,
|
|
150
|
+
)
|
|
151
|
+
_update_state(state, step_spec, records)
|
|
152
|
+
prev_output = records
|
|
153
|
+
|
|
154
|
+
# 最终步骤
|
|
155
|
+
for step_spec in spec.final_steps:
|
|
156
|
+
logger.info("WorkflowTool: final step %s", step_spec.agent_id)
|
|
157
|
+
step = StepAgent(step_spec, llm_client=client)
|
|
158
|
+
records = await asyncio.to_thread(
|
|
159
|
+
step.run,
|
|
160
|
+
state=state,
|
|
161
|
+
**config,
|
|
162
|
+
)
|
|
163
|
+
_update_state(state, step_spec, records)
|
|
164
|
+
|
|
165
|
+
# 构建结果
|
|
166
|
+
result = spec.result_builder(state, config)
|
|
167
|
+
|
|
168
|
+
# 存完整 JSON
|
|
169
|
+
try:
|
|
170
|
+
self._results_dir.mkdir(parents=True, exist_ok=True)
|
|
171
|
+
ts = datetime.now().strftime("%Y%m%d-%H%M%S")
|
|
172
|
+
result_file = self._results_dir / f"{workflow}-{ts}.json"
|
|
173
|
+
result_file.write_text(json.dumps(result, ensure_ascii=False, indent=2, default=str))
|
|
174
|
+
result_file_str = str(result_file)
|
|
175
|
+
logger.info("WorkflowTool: result saved to %s", result_file_str)
|
|
176
|
+
except Exception as exc:
|
|
177
|
+
logger.warning("WorkflowTool: failed to save result file: %s", exc)
|
|
178
|
+
result_file_str = ""
|
|
179
|
+
|
|
180
|
+
# 返回摘要
|
|
181
|
+
summary = result.get("summary", {})
|
|
182
|
+
top_formulas = result.get("final_pool", [])[:5]
|
|
183
|
+
return json.dumps(
|
|
184
|
+
{
|
|
185
|
+
"status": "completed",
|
|
186
|
+
"summary": summary,
|
|
187
|
+
"result_file": result_file_str,
|
|
188
|
+
"top_formulas": top_formulas,
|
|
189
|
+
},
|
|
190
|
+
ensure_ascii=False,
|
|
191
|
+
default=str,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
__all__ = [
|
|
196
|
+
"WorkflowTool",
|
|
197
|
+
"_update_state",
|
|
198
|
+
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
AI 模块
|
|
4
|
+
|
|
5
|
+
提供 AI 生成和优化 Pipeline 的功能。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from QuantNodes.ai.llm import (
|
|
9
|
+
LLMClientBase,
|
|
10
|
+
LLMError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
APIError,
|
|
14
|
+
Message,
|
|
15
|
+
MessageRole,
|
|
16
|
+
ChatCompletion,
|
|
17
|
+
ChatCompletionChunk,
|
|
18
|
+
OpenAIClient,
|
|
19
|
+
AzureOpenAIClient,
|
|
20
|
+
LLMGateway,
|
|
21
|
+
ToolCallResponse,
|
|
22
|
+
get_llm_gateway,
|
|
23
|
+
create_llm_gateway,
|
|
24
|
+
reset_llm_gateway,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from QuantNodes.ai.prompts import (
|
|
28
|
+
PromptLibrary,
|
|
29
|
+
PromptTemplate,
|
|
30
|
+
PromptBuilder,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
from QuantNodes.ai.sandbox import (
|
|
34
|
+
CodeSandbox,
|
|
35
|
+
CodeValidationResult,
|
|
36
|
+
DangerousCodeError,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
from QuantNodes.ai.strategy_gen import (
|
|
40
|
+
StrategyGenerator,
|
|
41
|
+
GenerationResult,
|
|
42
|
+
NaturalLanguageToPipeline,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
from QuantNodes.ai.optimizer import (
|
|
46
|
+
PipelineOptimizer,
|
|
47
|
+
OptimizationResult,
|
|
48
|
+
PipelineAnalyzer,
|
|
49
|
+
NodeAnalysis,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
# LLM
|
|
54
|
+
'LLMClientBase',
|
|
55
|
+
'LLMError',
|
|
56
|
+
'RateLimitError',
|
|
57
|
+
'AuthenticationError',
|
|
58
|
+
'APIError',
|
|
59
|
+
'Message',
|
|
60
|
+
'MessageRole',
|
|
61
|
+
'ChatCompletion',
|
|
62
|
+
'ChatCompletionChunk',
|
|
63
|
+
'OpenAIClient',
|
|
64
|
+
'AzureOpenAIClient',
|
|
65
|
+
|
|
66
|
+
# Gateway
|
|
67
|
+
'LLMGateway',
|
|
68
|
+
'ToolCallResponse',
|
|
69
|
+
'get_llm_gateway',
|
|
70
|
+
'create_llm_gateway',
|
|
71
|
+
'reset_llm_gateway',
|
|
72
|
+
|
|
73
|
+
# Prompts
|
|
74
|
+
'PromptLibrary',
|
|
75
|
+
'PromptTemplate',
|
|
76
|
+
'PromptBuilder',
|
|
77
|
+
|
|
78
|
+
# Sandbox
|
|
79
|
+
'CodeSandbox',
|
|
80
|
+
'CodeValidationResult',
|
|
81
|
+
'DangerousCodeError',
|
|
82
|
+
|
|
83
|
+
# Strategy Generation
|
|
84
|
+
'StrategyGenerator',
|
|
85
|
+
'GenerationResult',
|
|
86
|
+
'NaturalLanguageToPipeline',
|
|
87
|
+
|
|
88
|
+
# Optimization
|
|
89
|
+
'PipelineOptimizer',
|
|
90
|
+
'OptimizationResult',
|
|
91
|
+
'PipelineAnalyzer',
|
|
92
|
+
'NodeAnalysis',
|
|
93
|
+
]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
LLM 模块
|
|
4
|
+
|
|
5
|
+
提供 LLM 客户端接口。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from QuantNodes.ai.llm.base import (
|
|
9
|
+
LLMClientBase,
|
|
10
|
+
LLMError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
AuthenticationError,
|
|
13
|
+
APIError,
|
|
14
|
+
Message,
|
|
15
|
+
MessageRole,
|
|
16
|
+
ChatCompletion,
|
|
17
|
+
ChatCompletionChunk,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from QuantNodes.ai.llm.null import NullLLMClient
|
|
21
|
+
|
|
22
|
+
from QuantNodes.ai.llm.decorators import (
|
|
23
|
+
RetryingLLMClient,
|
|
24
|
+
LoggingLLMClient,
|
|
25
|
+
TokenCountingLLMClient,
|
|
26
|
+
CachedLLMClient,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from QuantNodes.ai.llm.openai import (
|
|
30
|
+
OpenAIClient,
|
|
31
|
+
AzureOpenAIClient,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
from QuantNodes.ai.llm.gateway import (
|
|
35
|
+
LLMGateway,
|
|
36
|
+
LLMConfig,
|
|
37
|
+
ToolCallResponse,
|
|
38
|
+
get_llm_gateway,
|
|
39
|
+
create_llm_gateway,
|
|
40
|
+
reset_llm_gateway,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
__all__ = [
|
|
44
|
+
# Base classes
|
|
45
|
+
'LLMClientBase',
|
|
46
|
+
'LLMError',
|
|
47
|
+
'RateLimitError',
|
|
48
|
+
'AuthenticationError',
|
|
49
|
+
'APIError',
|
|
50
|
+
'Message',
|
|
51
|
+
'MessageRole',
|
|
52
|
+
'ChatCompletion',
|
|
53
|
+
'ChatCompletionChunk',
|
|
54
|
+
|
|
55
|
+
# Null Object
|
|
56
|
+
'NullLLMClient',
|
|
57
|
+
|
|
58
|
+
# Decorators (Phase 1.1, 1.2)
|
|
59
|
+
'RetryingLLMClient',
|
|
60
|
+
'LoggingLLMClient',
|
|
61
|
+
'TokenCountingLLMClient',
|
|
62
|
+
'CachedLLMClient',
|
|
63
|
+
|
|
64
|
+
# Implementations
|
|
65
|
+
'OpenAIClient',
|
|
66
|
+
'AzureOpenAIClient',
|
|
67
|
+
|
|
68
|
+
# Gateway (unified LLM entry point)
|
|
69
|
+
'LLMGateway',
|
|
70
|
+
'LLMConfig',
|
|
71
|
+
'ToolCallResponse',
|
|
72
|
+
'get_llm_gateway',
|
|
73
|
+
'create_llm_gateway',
|
|
74
|
+
'reset_llm_gateway',
|
|
75
|
+
]
|