self-evolve-framework 1.5.0 → 1.6.0
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.
- package/package.json +1 -1
- package/template/skills/skillopt-sleep/SKILL.md +42 -0
- package/template/skills/skillopt-sleep/configs/_base_/default.yaml +103 -0
- package/template/skills/skillopt-sleep/configs/alfworld/default.yaml +29 -0
- package/template/skills/skillopt-sleep/configs/docvqa/default.yaml +28 -0
- package/template/skills/skillopt-sleep/configs/features/soft_gate.yaml +47 -0
- package/template/skills/skillopt-sleep/configs/livemathematicianbench/default.yaml +22 -0
- package/template/skills/skillopt-sleep/configs/officeqa/default.yaml +34 -0
- package/template/skills/skillopt-sleep/configs/searchqa/default.yaml +32 -0
- package/template/skills/skillopt-sleep/configs/spreadsheetbench/default.yaml +34 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/__init__.py +28 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/config.py +282 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/__init__.py +7 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/datasets/base.py +512 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/__init__.py +9 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/engine/trainer.py +2379 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/__init__.py +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/README.md +43 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/config_template.yaml +55 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/env_template.py +151 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/_template/loader_template.py +87 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/__init__.py +5 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/adapter.py +428 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/dataloader.py +123 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_error.md +55 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/analyst_success.md +33 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_no_history.md +8 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_history.md +9 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/prompts/rollout_with_memory.md +16 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/reflect.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/rollout.py +366 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/skills/initial.md +45 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/__init__.py +9 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_envs.py +221 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_projection.py +60 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/alfworld_prompts.py +8 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/config_tw.yaml +145 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_base.py +84 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/env_manager.py +139 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/alfworld/vendor/memory.py +87 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/base.py +329 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/__init__.py +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/adapter.py +90 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/dataloader.py +61 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/evaluator.py +113 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_error.md +35 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/analyst_success.md +24 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/prompts/rollout_system.md +12 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/rollout.py +391 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/docvqa/skills/initial.md +11 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/__init__.py +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/adapter.py +129 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/dataloader.py +308 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/evaluator.py +62 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_error.md +37 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/analyst_success.md +25 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/prompts/rollout_system.md +12 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/reflect.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/rollout.py +434 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/livemathematicianbench/skills/initial.md +16 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/__init__.py +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/adapter.py +112 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/dataloader.py +71 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/evaluator.py +46 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_error.md +37 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/analyst_success.md +25 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/prompts/rollout_system.md +15 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/rollout.py +799 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/skills/initial.md +15 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/officeqa/tool_runtime.py +552 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/__init__.py +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/adapter.py +96 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/dataloader.py +42 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/evaluator.py +100 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_error.md +46 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/analyst_success.md +32 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/prompts/rollout_system.md +13 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/reflect.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/rollout.py +494 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/searchqa/skills/initial.md +3 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/__init__.py +5 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/adapter.py +159 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/codegen_agent.py +731 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/dataloader.py +37 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/evaluator.py +158 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/executor.py +67 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_error.md +46 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/analyst_success.md +32 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/codegen_system.md +1 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/critical_rules.md +9 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/prompts/react_system.md +21 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/react_agent.py +395 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/reflect.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/rollout.py +979 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/envs/spreadsheetbench/skills/initial.md +56 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/__init__.py +13 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/evaluation/gate.py +148 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/__init__.py +15 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/aggregate.py +253 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/gradient/reflect.py +635 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/__init__.py +514 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/azure_openai.py +915 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/backend_config.py +185 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/claude_backend.py +371 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_backend.py +666 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/codex_harness.py +1057 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/common.py +229 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/minimax_backend.py +277 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/qwen_backend.py +456 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/model/router.py +236 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/__init__.py +15 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/appendix.py +156 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/clip.py +109 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/lr_autonomous.py +108 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/meta_skill.py +79 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/rewrite.py +59 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/scheduler.py +127 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/select.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill.py +201 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/skill_aware.py +206 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/slow_update.py +396 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/optimizer/update_modes.py +135 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/__init__.py +63 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error.md +41 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_full_rewrite.md +32 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_error_rewrite.md +44 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success.md +36 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_full_rewrite.md +30 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/analyst_success_rewrite.md +33 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/lr_autonomous.md +20 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure.md +30 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_full_rewrite.md +28 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_failure_rewrite.md +26 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final.md +33 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_full_rewrite.md +28 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_final_rewrite.md +25 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success.md +28 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_full_rewrite.md +28 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/merge_success_rewrite.md +25 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/meta_skill.md +40 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking.md +20 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/ranking_rewrite.md +15 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/rewrite_skill.md +25 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/prompts/slow_update.md +60 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/scheduler/__init__.py +8 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/types.py +306 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/__init__.py +4 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/json_utils.py +172 -0
- package/template/skills/skillopt-sleep/scripts/framework/skillopt/utils/scoring.py +28 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
"""ReflACT model API with runtime backend selection for the target path."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from skillopt.model import azure_openai as _openai
|
|
8
|
+
from skillopt.model import claude_backend as _claude
|
|
9
|
+
from skillopt.model import minimax_backend as _minimax
|
|
10
|
+
from skillopt.model import qwen_backend as _qwen
|
|
11
|
+
from skillopt.model.backend_config import ( # noqa: F401
|
|
12
|
+
configure_claude_code_exec,
|
|
13
|
+
configure_codex_exec,
|
|
14
|
+
get_claude_code_exec_config,
|
|
15
|
+
get_codex_exec_config,
|
|
16
|
+
get_target_backend,
|
|
17
|
+
get_optimizer_backend,
|
|
18
|
+
is_target_chat_backend,
|
|
19
|
+
is_target_exec_backend,
|
|
20
|
+
is_optimizer_chat_backend,
|
|
21
|
+
set_target_backend,
|
|
22
|
+
set_optimizer_backend,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def set_backend(name: str | None) -> str:
|
|
27
|
+
"""Backward-compatible global backend setter.
|
|
28
|
+
|
|
29
|
+
Historically the codebase used one shared backend for both optimizer and
|
|
30
|
+
target. Keep that entry point so older scripts continue to work, while
|
|
31
|
+
mapping it onto the split optimizer/target backend model.
|
|
32
|
+
"""
|
|
33
|
+
normalized = str(name or "azure_openai").strip().lower()
|
|
34
|
+
if normalized in {"azure_openai", "openai_chat", "azure", "azure-openai"}:
|
|
35
|
+
set_optimizer_backend("openai_chat")
|
|
36
|
+
set_target_backend("openai_chat")
|
|
37
|
+
return "azure_openai"
|
|
38
|
+
if normalized in {"claude", "claude_chat", "anthropic"}:
|
|
39
|
+
set_optimizer_backend("claude_chat")
|
|
40
|
+
set_target_backend("claude_chat")
|
|
41
|
+
return "claude_chat"
|
|
42
|
+
if normalized == "codex":
|
|
43
|
+
set_optimizer_backend("openai_chat")
|
|
44
|
+
set_target_backend("codex_exec")
|
|
45
|
+
return "codex"
|
|
46
|
+
if normalized in {"codex_exec", "claude_code_exec"}:
|
|
47
|
+
set_optimizer_backend("openai_chat")
|
|
48
|
+
set_target_backend(normalized)
|
|
49
|
+
return normalized
|
|
50
|
+
if normalized in {"qwen", "qwen_chat"}:
|
|
51
|
+
set_optimizer_backend("openai_chat")
|
|
52
|
+
set_target_backend("qwen_chat")
|
|
53
|
+
return "qwen_chat"
|
|
54
|
+
if normalized in {"minimax", "minimax_chat"}:
|
|
55
|
+
set_optimizer_backend("openai_chat")
|
|
56
|
+
set_target_backend("minimax_chat")
|
|
57
|
+
return "minimax_chat"
|
|
58
|
+
raise ValueError(f"Unsupported legacy backend: {name!r}")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_backend_name() -> str:
|
|
62
|
+
"""Best-effort backward-compatible backend summary."""
|
|
63
|
+
optimizer = get_optimizer_backend()
|
|
64
|
+
target = get_target_backend()
|
|
65
|
+
if optimizer == "claude_chat" and target == "claude_chat":
|
|
66
|
+
return "claude_chat"
|
|
67
|
+
if optimizer == "qwen_chat" and target == "qwen_chat":
|
|
68
|
+
return "qwen_chat"
|
|
69
|
+
if optimizer == "openai_chat" and target == "openai_chat":
|
|
70
|
+
return "azure_openai"
|
|
71
|
+
if optimizer == "openai_chat" and target == "codex_exec":
|
|
72
|
+
return "codex"
|
|
73
|
+
if optimizer == "openai_chat" and target == "qwen_chat":
|
|
74
|
+
return "qwen_chat"
|
|
75
|
+
if optimizer == "openai_chat" and target == "minimax_chat":
|
|
76
|
+
return "minimax_chat"
|
|
77
|
+
return f"{optimizer}+{target}"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def chat_optimizer(
|
|
81
|
+
system: str,
|
|
82
|
+
user: str,
|
|
83
|
+
max_completion_tokens: int = 16384,
|
|
84
|
+
retries: int = 5,
|
|
85
|
+
stage: str = "optimizer",
|
|
86
|
+
reasoning_effort: str | None = None,
|
|
87
|
+
timeout: int | None = None,
|
|
88
|
+
) -> tuple[str, dict]:
|
|
89
|
+
if get_optimizer_backend() == "claude_chat":
|
|
90
|
+
return _claude.chat_optimizer(
|
|
91
|
+
system=system,
|
|
92
|
+
user=user,
|
|
93
|
+
max_completion_tokens=max_completion_tokens,
|
|
94
|
+
retries=retries,
|
|
95
|
+
stage=stage,
|
|
96
|
+
timeout=timeout,
|
|
97
|
+
)
|
|
98
|
+
if get_optimizer_backend() == "qwen_chat":
|
|
99
|
+
return _qwen.chat_optimizer(
|
|
100
|
+
system=system,
|
|
101
|
+
user=user,
|
|
102
|
+
max_completion_tokens=max_completion_tokens,
|
|
103
|
+
retries=retries,
|
|
104
|
+
stage=stage,
|
|
105
|
+
reasoning_effort=reasoning_effort,
|
|
106
|
+
timeout=timeout,
|
|
107
|
+
)
|
|
108
|
+
return _openai.chat_optimizer(
|
|
109
|
+
system=system,
|
|
110
|
+
user=user,
|
|
111
|
+
max_completion_tokens=max_completion_tokens,
|
|
112
|
+
retries=retries,
|
|
113
|
+
stage=stage,
|
|
114
|
+
reasoning_effort=reasoning_effort,
|
|
115
|
+
timeout=timeout,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def chat_target(
|
|
120
|
+
system: str,
|
|
121
|
+
user: str,
|
|
122
|
+
max_completion_tokens: int = 16384,
|
|
123
|
+
retries: int = 5,
|
|
124
|
+
stage: str = "target",
|
|
125
|
+
reasoning_effort: str | None = None,
|
|
126
|
+
timeout: int | None = None,
|
|
127
|
+
) -> tuple[str, dict]:
|
|
128
|
+
if get_target_backend() == "claude_chat":
|
|
129
|
+
return _claude.chat_target(
|
|
130
|
+
system=system,
|
|
131
|
+
user=user,
|
|
132
|
+
max_completion_tokens=max_completion_tokens,
|
|
133
|
+
retries=retries,
|
|
134
|
+
stage=stage,
|
|
135
|
+
timeout=timeout,
|
|
136
|
+
)
|
|
137
|
+
if get_target_backend() == "qwen_chat":
|
|
138
|
+
return _qwen.chat_target(
|
|
139
|
+
system=system,
|
|
140
|
+
user=user,
|
|
141
|
+
max_completion_tokens=max_completion_tokens,
|
|
142
|
+
retries=retries,
|
|
143
|
+
stage=stage,
|
|
144
|
+
reasoning_effort=reasoning_effort,
|
|
145
|
+
timeout=timeout,
|
|
146
|
+
)
|
|
147
|
+
if get_target_backend() == "minimax_chat":
|
|
148
|
+
return _minimax.chat_target(
|
|
149
|
+
system=system,
|
|
150
|
+
user=user,
|
|
151
|
+
max_completion_tokens=max_completion_tokens,
|
|
152
|
+
retries=retries,
|
|
153
|
+
stage=stage,
|
|
154
|
+
reasoning_effort=reasoning_effort,
|
|
155
|
+
)
|
|
156
|
+
if not is_target_chat_backend():
|
|
157
|
+
raise NotImplementedError(
|
|
158
|
+
"chat_target is only supported with target_backend=openai_chat, claude_chat, qwen_chat, or minimax_chat. "
|
|
159
|
+
"Exec backends are handled in environment-specific rollout code."
|
|
160
|
+
)
|
|
161
|
+
return _openai.chat_target(
|
|
162
|
+
system=system,
|
|
163
|
+
user=user,
|
|
164
|
+
max_completion_tokens=max_completion_tokens,
|
|
165
|
+
retries=retries,
|
|
166
|
+
stage=stage,
|
|
167
|
+
reasoning_effort=reasoning_effort,
|
|
168
|
+
timeout=timeout,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def chat_optimizer_messages(
|
|
173
|
+
messages: list[dict[str, Any]],
|
|
174
|
+
max_completion_tokens: int = 16384,
|
|
175
|
+
retries: int = 5,
|
|
176
|
+
stage: str = "optimizer",
|
|
177
|
+
reasoning_effort: str | None = None,
|
|
178
|
+
*,
|
|
179
|
+
tools: list[dict[str, Any]] | None = None,
|
|
180
|
+
tool_choice: str | dict[str, Any] | None = None,
|
|
181
|
+
return_message: bool = False,
|
|
182
|
+
timeout: int | None = None,
|
|
183
|
+
) -> tuple[Any, dict]:
|
|
184
|
+
if get_optimizer_backend() == "claude_chat":
|
|
185
|
+
return _claude.chat_optimizer_messages(
|
|
186
|
+
messages=messages,
|
|
187
|
+
max_completion_tokens=max_completion_tokens,
|
|
188
|
+
retries=retries,
|
|
189
|
+
stage=stage,
|
|
190
|
+
tools=tools,
|
|
191
|
+
tool_choice=tool_choice,
|
|
192
|
+
return_message=return_message,
|
|
193
|
+
timeout=timeout,
|
|
194
|
+
)
|
|
195
|
+
if get_optimizer_backend() == "qwen_chat":
|
|
196
|
+
return _qwen.chat_optimizer_messages(
|
|
197
|
+
messages=messages,
|
|
198
|
+
max_completion_tokens=max_completion_tokens,
|
|
199
|
+
retries=retries,
|
|
200
|
+
stage=stage,
|
|
201
|
+
reasoning_effort=reasoning_effort,
|
|
202
|
+
tools=tools,
|
|
203
|
+
tool_choice=tool_choice,
|
|
204
|
+
return_message=return_message,
|
|
205
|
+
timeout=timeout,
|
|
206
|
+
)
|
|
207
|
+
return _openai.chat_optimizer_messages(
|
|
208
|
+
messages=messages,
|
|
209
|
+
max_completion_tokens=max_completion_tokens,
|
|
210
|
+
retries=retries,
|
|
211
|
+
stage=stage,
|
|
212
|
+
reasoning_effort=reasoning_effort,
|
|
213
|
+
tools=tools,
|
|
214
|
+
tool_choice=tool_choice,
|
|
215
|
+
return_message=return_message,
|
|
216
|
+
timeout=timeout,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def chat_target_messages(
|
|
221
|
+
messages: list[dict[str, Any]],
|
|
222
|
+
max_completion_tokens: int = 16384,
|
|
223
|
+
retries: int = 5,
|
|
224
|
+
stage: str = "target",
|
|
225
|
+
reasoning_effort: str | None = None,
|
|
226
|
+
*,
|
|
227
|
+
tools: list[dict[str, Any]] | None = None,
|
|
228
|
+
tool_choice: str | dict[str, Any] | None = None,
|
|
229
|
+
return_message: bool = False,
|
|
230
|
+
timeout: int | None = None,
|
|
231
|
+
) -> tuple[Any, dict]:
|
|
232
|
+
if get_target_backend() == "claude_chat":
|
|
233
|
+
return _claude.chat_target_messages(
|
|
234
|
+
messages=messages,
|
|
235
|
+
max_completion_tokens=max_completion_tokens,
|
|
236
|
+
retries=retries,
|
|
237
|
+
stage=stage,
|
|
238
|
+
tools=tools,
|
|
239
|
+
tool_choice=tool_choice,
|
|
240
|
+
return_message=return_message,
|
|
241
|
+
timeout=timeout,
|
|
242
|
+
)
|
|
243
|
+
if get_target_backend() == "qwen_chat":
|
|
244
|
+
return _qwen.chat_target_messages(
|
|
245
|
+
messages=messages,
|
|
246
|
+
max_completion_tokens=max_completion_tokens,
|
|
247
|
+
retries=retries,
|
|
248
|
+
stage=stage,
|
|
249
|
+
reasoning_effort=reasoning_effort,
|
|
250
|
+
tools=tools,
|
|
251
|
+
tool_choice=tool_choice,
|
|
252
|
+
return_message=return_message,
|
|
253
|
+
timeout=timeout,
|
|
254
|
+
)
|
|
255
|
+
if get_target_backend() == "minimax_chat":
|
|
256
|
+
return _minimax.chat_target_messages(
|
|
257
|
+
messages=messages,
|
|
258
|
+
max_completion_tokens=max_completion_tokens,
|
|
259
|
+
retries=retries,
|
|
260
|
+
stage=stage,
|
|
261
|
+
reasoning_effort=reasoning_effort,
|
|
262
|
+
tools=tools,
|
|
263
|
+
tool_choice=tool_choice,
|
|
264
|
+
return_message=return_message,
|
|
265
|
+
)
|
|
266
|
+
if not is_target_chat_backend():
|
|
267
|
+
raise NotImplementedError(
|
|
268
|
+
"chat_target_messages is only supported with target_backend=openai_chat, claude_chat, qwen_chat, or minimax_chat. "
|
|
269
|
+
"Exec backends are handled in environment-specific rollout code."
|
|
270
|
+
)
|
|
271
|
+
return _openai.chat_target_messages(
|
|
272
|
+
messages=messages,
|
|
273
|
+
max_completion_tokens=max_completion_tokens,
|
|
274
|
+
retries=retries,
|
|
275
|
+
stage=stage,
|
|
276
|
+
reasoning_effort=reasoning_effort,
|
|
277
|
+
tools=tools,
|
|
278
|
+
tool_choice=tool_choice,
|
|
279
|
+
return_message=return_message,
|
|
280
|
+
timeout=timeout,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def chat_messages_with_deployment(
|
|
285
|
+
deployment: str,
|
|
286
|
+
messages: list[dict[str, Any]],
|
|
287
|
+
max_completion_tokens: int = 16384,
|
|
288
|
+
retries: int = 5,
|
|
289
|
+
stage: str = "custom",
|
|
290
|
+
reasoning_effort: str | None = None,
|
|
291
|
+
*,
|
|
292
|
+
tools: list[dict[str, Any]] | None = None,
|
|
293
|
+
tool_choice: str | dict[str, Any] | None = None,
|
|
294
|
+
return_message: bool = False,
|
|
295
|
+
timeout: int | None = None,
|
|
296
|
+
) -> tuple[Any, dict]:
|
|
297
|
+
return _openai.chat_messages_with_deployment(
|
|
298
|
+
deployment=deployment,
|
|
299
|
+
messages=messages,
|
|
300
|
+
max_completion_tokens=max_completion_tokens,
|
|
301
|
+
retries=retries,
|
|
302
|
+
stage=stage,
|
|
303
|
+
reasoning_effort=reasoning_effort,
|
|
304
|
+
tools=tools,
|
|
305
|
+
tool_choice=tool_choice,
|
|
306
|
+
return_message=return_message,
|
|
307
|
+
timeout=timeout,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def chat_with_deployment(
|
|
312
|
+
deployment: str,
|
|
313
|
+
system: str,
|
|
314
|
+
user: str,
|
|
315
|
+
max_completion_tokens: int = 16384,
|
|
316
|
+
retries: int = 5,
|
|
317
|
+
stage: str = "custom",
|
|
318
|
+
reasoning_effort: str | None = None,
|
|
319
|
+
timeout: int | None = None,
|
|
320
|
+
) -> tuple[str, dict]:
|
|
321
|
+
return _openai.chat_with_deployment(
|
|
322
|
+
deployment=deployment,
|
|
323
|
+
system=system,
|
|
324
|
+
user=user,
|
|
325
|
+
max_completion_tokens=max_completion_tokens,
|
|
326
|
+
retries=retries,
|
|
327
|
+
stage=stage,
|
|
328
|
+
reasoning_effort=reasoning_effort,
|
|
329
|
+
timeout=timeout,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def get_token_summary() -> dict:
|
|
334
|
+
summary = _openai.get_token_summary()
|
|
335
|
+
claude_summary = _claude.get_token_summary()
|
|
336
|
+
for stage, values in claude_summary.items():
|
|
337
|
+
if stage == "_total":
|
|
338
|
+
continue
|
|
339
|
+
if stage not in summary:
|
|
340
|
+
summary[stage] = values
|
|
341
|
+
continue
|
|
342
|
+
summary[stage]["calls"] += values["calls"]
|
|
343
|
+
summary[stage]["prompt_tokens"] += values["prompt_tokens"]
|
|
344
|
+
summary[stage]["completion_tokens"] += values["completion_tokens"]
|
|
345
|
+
summary[stage]["total_tokens"] += values["total_tokens"]
|
|
346
|
+
qwen_summary = _qwen.get_token_summary()
|
|
347
|
+
for stage, values in qwen_summary.items():
|
|
348
|
+
if stage == "_total":
|
|
349
|
+
continue
|
|
350
|
+
if stage not in summary:
|
|
351
|
+
summary[stage] = values
|
|
352
|
+
continue
|
|
353
|
+
summary[stage]["calls"] += values["calls"]
|
|
354
|
+
summary[stage]["prompt_tokens"] += values["prompt_tokens"]
|
|
355
|
+
summary[stage]["completion_tokens"] += values["completion_tokens"]
|
|
356
|
+
summary[stage]["total_tokens"] += values["total_tokens"]
|
|
357
|
+
minimax_summary = _minimax.get_token_summary()
|
|
358
|
+
for stage, values in minimax_summary.items():
|
|
359
|
+
if stage == "_total":
|
|
360
|
+
continue
|
|
361
|
+
if stage not in summary:
|
|
362
|
+
summary[stage] = values
|
|
363
|
+
continue
|
|
364
|
+
summary[stage]["calls"] += values["calls"]
|
|
365
|
+
summary[stage]["prompt_tokens"] += values["prompt_tokens"]
|
|
366
|
+
summary[stage]["completion_tokens"] += values["completion_tokens"]
|
|
367
|
+
summary[stage]["total_tokens"] += values["total_tokens"]
|
|
368
|
+
total = {
|
|
369
|
+
"calls": 0,
|
|
370
|
+
"prompt_tokens": 0,
|
|
371
|
+
"completion_tokens": 0,
|
|
372
|
+
"total_tokens": 0,
|
|
373
|
+
}
|
|
374
|
+
for stage, values in summary.items():
|
|
375
|
+
if stage == "_total":
|
|
376
|
+
continue
|
|
377
|
+
total["calls"] += values["calls"]
|
|
378
|
+
total["prompt_tokens"] += values["prompt_tokens"]
|
|
379
|
+
total["completion_tokens"] += values["completion_tokens"]
|
|
380
|
+
total["total_tokens"] += values["total_tokens"]
|
|
381
|
+
summary["_total"] = total
|
|
382
|
+
return summary
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def reset_token_tracker() -> None:
|
|
386
|
+
_openai.reset_token_tracker()
|
|
387
|
+
_claude.reset_token_tracker()
|
|
388
|
+
_qwen.reset_token_tracker()
|
|
389
|
+
_minimax.reset_token_tracker()
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def configure_azure_openai(
|
|
393
|
+
*,
|
|
394
|
+
endpoint: str | None = None,
|
|
395
|
+
api_version: str | None = None,
|
|
396
|
+
api_key: str | None = None,
|
|
397
|
+
auth_mode: str | None = None,
|
|
398
|
+
ad_scope: str | None = None,
|
|
399
|
+
managed_identity_client_id: str | None = None,
|
|
400
|
+
optimizer_endpoint: str | None = None,
|
|
401
|
+
optimizer_api_version: str | None = None,
|
|
402
|
+
optimizer_api_key: str | None = None,
|
|
403
|
+
optimizer_auth_mode: str | None = None,
|
|
404
|
+
optimizer_ad_scope: str | None = None,
|
|
405
|
+
optimizer_managed_identity_client_id: str | None = None,
|
|
406
|
+
target_endpoint: str | None = None,
|
|
407
|
+
target_api_version: str | None = None,
|
|
408
|
+
target_api_key: str | None = None,
|
|
409
|
+
target_auth_mode: str | None = None,
|
|
410
|
+
target_ad_scope: str | None = None,
|
|
411
|
+
target_managed_identity_client_id: str | None = None,
|
|
412
|
+
) -> None:
|
|
413
|
+
_openai.configure_azure_openai(
|
|
414
|
+
endpoint=endpoint,
|
|
415
|
+
api_version=api_version,
|
|
416
|
+
api_key=api_key,
|
|
417
|
+
auth_mode=auth_mode,
|
|
418
|
+
ad_scope=ad_scope,
|
|
419
|
+
managed_identity_client_id=managed_identity_client_id,
|
|
420
|
+
optimizer_endpoint=optimizer_endpoint,
|
|
421
|
+
optimizer_api_version=optimizer_api_version,
|
|
422
|
+
optimizer_api_key=optimizer_api_key,
|
|
423
|
+
optimizer_auth_mode=optimizer_auth_mode,
|
|
424
|
+
optimizer_ad_scope=optimizer_ad_scope,
|
|
425
|
+
optimizer_managed_identity_client_id=optimizer_managed_identity_client_id,
|
|
426
|
+
target_endpoint=target_endpoint,
|
|
427
|
+
target_api_version=target_api_version,
|
|
428
|
+
target_api_key=target_api_key,
|
|
429
|
+
target_auth_mode=target_auth_mode,
|
|
430
|
+
target_ad_scope=target_ad_scope,
|
|
431
|
+
target_managed_identity_client_id=target_managed_identity_client_id,
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def configure_qwen_chat(
|
|
436
|
+
*,
|
|
437
|
+
base_url: str | None = None,
|
|
438
|
+
api_key: str | None = None,
|
|
439
|
+
temperature: float | str | None = None,
|
|
440
|
+
timeout_seconds: float | str | None = None,
|
|
441
|
+
max_tokens: int | str | None = None,
|
|
442
|
+
enable_thinking: bool | str | None = None,
|
|
443
|
+
optimizer_base_url: str | None = None,
|
|
444
|
+
optimizer_api_key: str | None = None,
|
|
445
|
+
optimizer_temperature: float | str | None = None,
|
|
446
|
+
optimizer_timeout_seconds: float | str | None = None,
|
|
447
|
+
optimizer_max_tokens: int | str | None = None,
|
|
448
|
+
optimizer_enable_thinking: bool | str | None = None,
|
|
449
|
+
target_base_url: str | None = None,
|
|
450
|
+
target_api_key: str | None = None,
|
|
451
|
+
target_temperature: float | str | None = None,
|
|
452
|
+
target_timeout_seconds: float | str | None = None,
|
|
453
|
+
target_max_tokens: int | str | None = None,
|
|
454
|
+
target_enable_thinking: bool | str | None = None,
|
|
455
|
+
) -> None:
|
|
456
|
+
_qwen.configure_qwen_chat(
|
|
457
|
+
base_url=base_url,
|
|
458
|
+
api_key=api_key,
|
|
459
|
+
temperature=temperature,
|
|
460
|
+
timeout_seconds=timeout_seconds,
|
|
461
|
+
max_tokens=max_tokens,
|
|
462
|
+
enable_thinking=enable_thinking,
|
|
463
|
+
optimizer_base_url=optimizer_base_url,
|
|
464
|
+
optimizer_api_key=optimizer_api_key,
|
|
465
|
+
optimizer_temperature=optimizer_temperature,
|
|
466
|
+
optimizer_timeout_seconds=optimizer_timeout_seconds,
|
|
467
|
+
optimizer_max_tokens=optimizer_max_tokens,
|
|
468
|
+
optimizer_enable_thinking=optimizer_enable_thinking,
|
|
469
|
+
target_base_url=target_base_url,
|
|
470
|
+
target_api_key=target_api_key,
|
|
471
|
+
target_temperature=target_temperature,
|
|
472
|
+
target_timeout_seconds=target_timeout_seconds,
|
|
473
|
+
target_max_tokens=target_max_tokens,
|
|
474
|
+
target_enable_thinking=target_enable_thinking,
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def configure_minimax_chat(
|
|
479
|
+
*,
|
|
480
|
+
base_url: str | None = None,
|
|
481
|
+
api_key: str | None = None,
|
|
482
|
+
temperature: float | str | None = None,
|
|
483
|
+
timeout_seconds: float | str | None = None,
|
|
484
|
+
max_tokens: int | str | None = None,
|
|
485
|
+
enable_thinking: bool | str | None = None,
|
|
486
|
+
) -> None:
|
|
487
|
+
_minimax.configure_minimax_chat(
|
|
488
|
+
base_url=base_url,
|
|
489
|
+
api_key=api_key,
|
|
490
|
+
temperature=temperature,
|
|
491
|
+
timeout_seconds=timeout_seconds,
|
|
492
|
+
max_tokens=max_tokens,
|
|
493
|
+
enable_thinking=enable_thinking,
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def set_reasoning_effort(effort: str | None) -> None:
|
|
498
|
+
_openai.set_reasoning_effort(effort)
|
|
499
|
+
_claude.set_reasoning_effort(effort)
|
|
500
|
+
_qwen.set_reasoning_effort(effort)
|
|
501
|
+
_minimax.set_reasoning_effort(effort)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def set_target_deployment(deployment: str) -> None:
|
|
505
|
+
_openai.set_target_deployment(deployment)
|
|
506
|
+
_claude.set_target_deployment(deployment)
|
|
507
|
+
_qwen.set_target_deployment(deployment)
|
|
508
|
+
_minimax.set_target_deployment(deployment)
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
def set_optimizer_deployment(deployment: str) -> None:
|
|
512
|
+
_openai.set_optimizer_deployment(deployment)
|
|
513
|
+
_claude.set_optimizer_deployment(deployment)
|
|
514
|
+
_qwen.set_optimizer_deployment(deployment)
|