forked from luopingyi/xc_agent_platform_demo
select-opt dry-run: foothold verified_reuse first, build-config default w/ fallback, GPU enum map (45/45)
This commit is contained in:
@@ -1,31 +1,66 @@
|
||||
"""Offline sample by default; explicit opt-in enables captured build-config API."""
|
||||
"""Dry-run configuration: token-resolvable build-config first; failures fall back to sample with GAP."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
from src.build_config_client import build_config, BuildConfigError
|
||||
from src.task_add_client import resolve_token
|
||||
|
||||
SOURCE = 'POST /api/adapt/task/build-config (discovered via capture); default templates/config_params.sample.yaml'
|
||||
GAP = 'GAP: build-config API discovered via capture (autoconfig-capture-2026-10-16.md); live/实锤 needs token + API call and auth proof. Sample is dry-run draft only, NOT production-ready.'
|
||||
SOURCE = 'POST /api/adapt/task/build-config (discovered via capture); fallback templates/config_params.sample.yaml'
|
||||
GAP = 'GAP: build-config API discovered via capture; sample is dry-run draft only, NOT production-ready. API foothold evidence: GAP (not wired).'
|
||||
GPU_ENUMS = {
|
||||
'壁砺': 'Biren_166m', '壁砺166M': 'Biren_166m', 'Biren_166m': 'Biren_166m',
|
||||
'曦望': 'Sunrise_pt-200-x1', '曦望 S2': 'Sunrise_pt-200-x1',
|
||||
'Sunrise_pt-200-x1': 'Sunrise_pt-200-x1',
|
||||
}
|
||||
|
||||
|
||||
def config_params_source():
|
||||
"""Requested source preference for dry-run.
|
||||
|
||||
- CONFIG_PARAMS_SOURCE=sample → force offline sample
|
||||
- CONFIG_PARAMS_SOURCE=build-config → force API path (with soft fallback in with_meta)
|
||||
- default (empty): prefer build-config when resolve_token() succeeds; else sample
|
||||
- ALLOW_BUILD_CONFIG=1 remains a legacy opt-in synonym when source empty and token ok
|
||||
"""
|
||||
source = os.environ.get('CONFIG_PARAMS_SOURCE', '').strip()
|
||||
if source not in ('', 'sample', 'build-config'):
|
||||
raise BuildConfigError('unsupported CONFIG_PARAMS_SOURCE')
|
||||
if source == 'build-config':
|
||||
return 'build-config'
|
||||
if os.environ.get('ALLOW_BUILD_CONFIG') == '1':
|
||||
if source:
|
||||
return source
|
||||
try:
|
||||
resolve_token()
|
||||
except (ValueError, OSError):
|
||||
return 'sample'
|
||||
# Token resolvable → prefer build-config (kickoff select-opt default).
|
||||
return 'build-config'
|
||||
|
||||
|
||||
def build_config_params_with_meta(gpu_type=None, framework='vllm', task_type='text-generation'):
|
||||
"""Return (YAML, metadata); API failures explicitly fall back for dry-run.
|
||||
|
||||
scripts/build_config_dry.py calls build_config directly and remains strict.
|
||||
"""
|
||||
source = config_params_source()
|
||||
meta = {'configParams_source': 'sample'}
|
||||
try:
|
||||
resolve_token()
|
||||
except (ValueError, OSError):
|
||||
meta['auth'] = 'missing'
|
||||
else:
|
||||
meta['auth'] = 'ok'
|
||||
gpu_enum = GPU_ENUMS.get(gpu_type)
|
||||
if source == 'build-config' and gpu_enum is None:
|
||||
meta['configParams_fallback_reason'] = 'GAP: gpu enum unmapped'
|
||||
elif source == 'build-config':
|
||||
try:
|
||||
resolve_token()
|
||||
except (ValueError, OSError):
|
||||
pass
|
||||
yaml = build_config(gpu_enum, framework, task_type)
|
||||
except BuildConfigError as error:
|
||||
meta['configParams_fallback_reason'] = 'GAP: ' + error.error_attribution
|
||||
else:
|
||||
return 'build-config'
|
||||
return 'sample'
|
||||
meta['configParams_source'] = 'build-config'
|
||||
return yaml, meta
|
||||
return (Path(__file__).resolve().parents[1] / 'templates/config_params.sample.yaml').read_text(), meta
|
||||
|
||||
|
||||
def build_config_params(gpu_type=None, framework='vllm', task_type='text-generation'):
|
||||
"""Return YAML; opted-in API failures propagate, never fall back to sample."""
|
||||
if config_params_source() == 'build-config':
|
||||
return build_config(gpu_type, framework, task_type)
|
||||
return (Path(__file__).resolve().parents[1] / 'templates/config_params.sample.yaml').read_text()
|
||||
"""Compatible YAML-only dry-run wrapper, including explicit fallback."""
|
||||
return build_config_params_with_meta(gpu_type, framework, task_type)[0]
|
||||
|
||||
Reference in New Issue
Block a user