E0-3/E0-4 groundwork: provider options, pinned docs, Track A/B in the protocol
- providers: per-model request extras (e.g. reasoning_effort), key_env, token_param (max_completion_tokens on api.openai.com); recorded - docs pinned to the toolchain being run: Rust offline docs from the sysroot, Zig langref and std source of the same installation; several mounts under a read-only /docs; hashes recorded (cached for big trees) - protocol: neutral model labels and calibration before classes (§2); smoke gates, fixed Aji commit, fixed per-model reasoning mode, slope of degradation (§39a); Track A controlled vs Track B native agents (§39b) - plan: E-C calibration, E-G gates, E-N native-agent run
This commit is contained in:
1 parent
b49003bdb9
commit
d7bb9273f3
14 files changed
+250
-60
No files matched your search
@@ -50,15 +50,16 @@ def _post(url, headers, body, timeout, retries=4):
|
||||
class Anthropic:
|
||||
name = "anthropic"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600, extra=None, **_):
|
||||
self.model, self.max_tokens, self.temperature, self.timeout = model, max_tokens, temperature, timeout
|
||||
self.extra = dict(extra or {})
|
||||
self.url = (base_url or "https://api.anthropic.com") + "/v1/messages"
|
||||
self.key = os.environ.get("ANTHROPIC_API_KEY")
|
||||
if not self.key:
|
||||
raise SystemExit("ANTHROPIC_API_KEY is not set")
|
||||
|
||||
def params(self):
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature}
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature, "extra": self.extra}
|
||||
|
||||
def complete(self, system, messages, tools):
|
||||
msgs = []
|
||||
@@ -81,6 +82,7 @@ class Anthropic:
|
||||
}
|
||||
if self.temperature is not None:
|
||||
body["temperature"] = self.temperature
|
||||
body.update(self.extra)
|
||||
r = _post(self.url, {"x-api-key": self.key, "anthropic-version": "2023-06-01"}, body, self.timeout)
|
||||
content = []
|
||||
for b in r.get("content", []):
|
||||
@@ -104,15 +106,25 @@ class Anthropic:
|
||||
|
||||
|
||||
class OpenAICompatible:
|
||||
"""`extra` is merged into every request body (for example
|
||||
{"reasoning_effort": "medium"}) and recorded. OpenAI's own endpoint takes
|
||||
`max_completion_tokens`; other servers take `max_tokens` unless
|
||||
`token_param` says otherwise. The API key is read from the environment
|
||||
variable named by `key_env` (default OPENAI_API_KEY)."""
|
||||
|
||||
name = "openai"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600, extra=None, key_env=None, token_param=None, **_):
|
||||
self.model, self.max_tokens, self.temperature, self.timeout = model, max_tokens, temperature, timeout
|
||||
self.url = (base_url or "https://api.openai.com/v1").rstrip("/") + "/chat/completions"
|
||||
self.key = os.environ.get("OPENAI_API_KEY", "")
|
||||
self.base = (base_url or "https://api.openai.com/v1").rstrip("/")
|
||||
self.url = self.base + "/chat/completions"
|
||||
self.key_env = key_env or "OPENAI_API_KEY"
|
||||
self.secret = os.environ.get(self.key_env, "")
|
||||
self.extra = dict(extra or {})
|
||||
self.token_param = token_param or ("max_completion_tokens" if "api.openai.com" in self.base else "max_tokens")
|
||||
|
||||
def params(self):
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature}
|
||||
return {"max_tokens": self.max_tokens, "token_param": self.token_param, "temperature": self.temperature, "extra": self.extra, "key_env": self.key_env}
|
||||
|
||||
def complete(self, system, messages, tools):
|
||||
msgs = [{"role": "system", "content": system}]
|
||||
@@ -132,13 +144,14 @@ class OpenAICompatible:
|
||||
msgs.append({"role": "user", "content": "\n".join(texts)})
|
||||
body = {
|
||||
"model": self.model,
|
||||
"max_tokens": self.max_tokens,
|
||||
self.token_param: self.max_tokens,
|
||||
"messages": msgs,
|
||||
"tools": [{"type": "function", "function": {"name": t["name"], "description": t["description"], "parameters": t["parameters"]}} for t in tools],
|
||||
}
|
||||
if self.temperature is not None:
|
||||
body["temperature"] = self.temperature
|
||||
headers = {"authorization": f"Bearer {self.key}"} if self.key else {}
|
||||
body.update(self.extra)
|
||||
headers = {"authorization": "Bearer " + self.secret} if self.secret else {}
|
||||
r = _post(self.url, headers, body, self.timeout)
|
||||
choice = r["choices"][0]
|
||||
msg = choice["message"]
|
||||
@@ -170,7 +183,7 @@ class Scripted:
|
||||
|
||||
name = "scripted"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=0):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=0, **_):
|
||||
self.model = model
|
||||
with open(model) as f:
|
||||
self.turns = json.load(f)
|
||||
|
||||
Reference in new issue
Block a user