mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-06 02:09:04 +00:00
* feat(decisions): add unified /v1/decisions endpoint for Jev-compatible providers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(decisions): register typesafe as a provider so Jev deployments load Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * refactor(decisions): move provider endpoints under llms and validate proxy bodies Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(decisions): add Cloudflare Clef and Strands Decider backends Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(decisions): register decisions routes for managed agents and gateway Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(decisions): use raw regex for cloudflare missing account match Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(decisions): avoid cast in Cloudflare response unwrapping Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(decisions): default model, evaluation health probe, short Cloudflare names The proxy validates only state and questions, so a request without a model falls through to the configured default model like every other route. Health checks probe evaluation-mode deployments through the Decisions API instead of failing with an unsupported mode, and cloudflare/clef and cloudflare/clef-flash get cost-map rows so the short names resolve a mode and a price. The registry no longer claims typed decisions for a provider with no backend. * fix(decisions): let health_check_params override the evaluation probe Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(integration): audit the decisions endpoint across providers, limits, health and chaos Adds the /v1/decisions audit cells: one wire contract per provider (path, key, body and cost-map billing), the gateway-only fields and tags, the sad paths (invalid bodies, unknown model, key checks, api_base in the body, upstream 401/429/500, a 200 without answers, an unreachable upstream), the two evaluation-mode health probes, and three chaos cells (a mixed-failure burst over both routes, a worker SIGKILL mid-burst, an upstream outage and restart on the same port). The PR's cost case read the upstream observations through the gateway, which answers 404 for that path; it now reads them from the upstream URL. The owned proxy harness takes extra CLI arguments, and its graceful stop waits as long as a worker boot may take, since a worker still starting honors SIGTERM only once it is up and the 30 second wait forced a cleanup under load. * fix(decisions): send env API keys to a configured api_base Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * feat(decisions): add zero-cost evaluation cost-map entry for Strands Decider Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(decisions): register the routes through the lazy feature registry The Decisions router was included at import, ahead of the config and DB pass-through endpoints, so a pass-through configured at /v1/decisions was skipped and answered 400 as an unknown Decisions provider. The routes now register through LAZY_FEATURES, which splices them in after every eager route, so a pass-through at /v1/decisions keeps its route while /decisions still serves natively. The lazy OpenAPI snapshot carries the two paths so the schema shows them before the first call. The audit cells add the env-key egress to a configured api_base, the client api_base opt-in shared with chat, the pass-through precedence on an owned proxy, and the Strands evaluation health check resolved from the cost map. The integration config exports the Perplexity env key the first cell needs. * fix(decisions): keep the Cloudflare api_base message in its transformation and read the audit upstream once per cell * fix(proxy): let a config pass-through beat a lazily registered route in eager mode With LITELLM_DISABLE_LAZY_ROUTES set the decisions routes are registered at startup, so SafeRouteAdder treated a config pass-through at exactly /v1/decisions as already registered and dropped it. In lazy mode a pass-through created through the API after the first native call was skipped the same way. Routes a lazy feature owns no longer count as registered, and a route added at one of their paths is placed ahead of them, the precedence lazy mode gives a config pass-through when the feature has not loaded yet. --------- Co-authored-by: mateo <mateo@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
149 lines
6.6 KiB
Python
149 lines
6.6 KiB
Python
import os
|
|
import uuid
|
|
from typing import Final
|
|
|
|
import httpx
|
|
from integration._support.client import Gateway, object_value, string_value
|
|
from integration._support.upstream import ScenarioHandle, delete_scenario, register_scenario
|
|
from integration.cost_calculation.cost_tracking_case import JsonResponse
|
|
from pydantic import JsonValue
|
|
|
|
_DECISIONS_PROBE_REPLY: Final = JsonResponse(
|
|
content_type="application/json",
|
|
body={
|
|
"model": "pplx-decider-v1-27b",
|
|
"answers": {"reachable": {"type": "noul", "noul": 1.0}},
|
|
"usage": {"input_tokens": 10, "output_tokens": 1},
|
|
},
|
|
)
|
|
_CONFIGURED_PROBE_REPLY: Final = JsonResponse(
|
|
content_type="application/json",
|
|
body={
|
|
"model": "jev-custom",
|
|
"answers": {"alive": {"type": "choice", "choice": "yes", "confidence": 0.9, "probabilities": {"yes": 0.9}}},
|
|
"usage": {"input_tokens": 10, "output_tokens": 1},
|
|
},
|
|
)
|
|
_STRANDS_PROBE_REPLY: Final = JsonResponse(
|
|
content_type="application/json",
|
|
body={
|
|
"model": "strands-decider-2B-hobson-v19",
|
|
"answers": {"reachable": {"type": "noul", "noul": 1.0}},
|
|
"usage": {"input_tokens": 10, "output_tokens": 1},
|
|
},
|
|
)
|
|
_CONFIGURED_STATE: Final[dict[str, JsonValue]] = {"ticket": "health probe"}
|
|
_CONFIGURED_QUESTIONS: Final[dict[str, JsonValue]] = {
|
|
"alive": {"type": "choice", "criteria": {"yes": "the service answers", "no": "the service is down"}}
|
|
}
|
|
|
|
|
|
def test_health_check_of_a_model_added_through_the_api_calls_its_upstream_and_reports_it_healthy(
|
|
gateway: Gateway,
|
|
) -> None:
|
|
with (
|
|
gateway.scenario() as scenario,
|
|
httpx.Client(base_url=gateway.upstream_url, timeout=5, trust_env=False) as upstream,
|
|
):
|
|
provider_model: Final = f"health-{uuid.uuid4().hex}"
|
|
model: Final = scenario.model(model=f"openai/{provider_model}")
|
|
key: Final = scenario.key(models=[model])
|
|
listed: Final = gateway.request("GET", "/v2/model/info", key=key, params={"model": model})
|
|
assert listed.status_code == 200, listed.text
|
|
assert [entry["model_name"] for entry in listed.json()["data"]] == [model]
|
|
assert (
|
|
object_value(gateway.chat(model, key=key, text=f"health {uuid.uuid4().hex}")["usage"])["total_tokens"] == 40
|
|
)
|
|
upstream.get("/__observations").raise_for_status()
|
|
health: Final = gateway.request("GET", "/health", params={"model": model})
|
|
assert health.status_code == 200, health.text
|
|
report: Final = health.json()
|
|
assert (report["healthy_count"], report["unhealthy_count"]) == (1, 0), report
|
|
assert [(endpoint["model"], endpoint["api_base"]) for endpoint in report["healthy_endpoints"]] == [
|
|
(f"openai/{provider_model}", f"{gateway.upstream_url}/v1")
|
|
]
|
|
assert [request["body"]["model"] for request in upstream.get("/__observations").json()["requests"]] == [
|
|
provider_model
|
|
]
|
|
|
|
|
|
def _health_report(gateway: Gateway, model: str) -> dict[str, JsonValue]:
|
|
health: Final = gateway.request("GET", "/health", params={"model": model})
|
|
assert health.status_code == 200, health.text
|
|
return health.json()
|
|
|
|
|
|
def _probes_sent_to(gateway: Gateway, handle: ScenarioHandle) -> list[tuple[str, JsonValue]]:
|
|
with httpx.Client(base_url=gateway.upstream_url, timeout=5, trust_env=False) as upstream:
|
|
requests: Final = upstream.get("/__observations").json()["requests"]
|
|
return [
|
|
(string_value(request["path"]), request["body"])
|
|
for request in map(object_value, requests)
|
|
if string_value(request["path"]).startswith(f"/{handle.scenario_id}/")
|
|
]
|
|
|
|
|
|
def test_evaluation_mode_health_check_resolves_the_mode_from_the_cost_map_and_sends_the_default_probe(
|
|
gateway: Gateway,
|
|
) -> None:
|
|
with gateway.scenario() as scenario:
|
|
handle: Final = register_scenario(f"health-decisions-{uuid.uuid4().hex[:12]}", _DECISIONS_PROBE_REPLY)
|
|
scenario.cleanups.callback(delete_scenario, handle)
|
|
model: Final = scenario.model(model="perplexity/pplx-decider-v1-27b", api_base=handle.api_base())
|
|
report: Final = _health_report(gateway, model)
|
|
assert (report["healthy_count"], report["unhealthy_count"]) == (1, 0), report
|
|
assert _probes_sent_to(gateway, handle) == [
|
|
(
|
|
f"/{handle.scenario_id}/v1/decisions",
|
|
{
|
|
"model": "pplx-decider-v1-27b",
|
|
"state": os.environ.get("DEFAULT_HEALTH_CHECK_PROMPT", "test from litellm"),
|
|
"questions": {"reachable": {"type": "noul", "instructions": "Is the service reachable?"}},
|
|
},
|
|
)
|
|
]
|
|
|
|
|
|
def test_evaluation_mode_health_check_sends_the_configured_state_and_questions(gateway: Gateway) -> None:
|
|
with gateway.scenario() as scenario:
|
|
handle: Final = register_scenario(f"health-decisions-{uuid.uuid4().hex[:12]}", _CONFIGURED_PROBE_REPLY)
|
|
scenario.cleanups.callback(delete_scenario, handle)
|
|
model: Final = scenario.model(
|
|
model="typesafe/jev-custom",
|
|
api_base=handle.api_base(),
|
|
model_info={
|
|
"mode": "evaluation",
|
|
"health_check_params": {"state": _CONFIGURED_STATE, "questions": _CONFIGURED_QUESTIONS},
|
|
},
|
|
)
|
|
report: Final = _health_report(gateway, model)
|
|
assert (report["healthy_count"], report["unhealthy_count"]) == (1, 0), report
|
|
assert _probes_sent_to(gateway, handle) == [
|
|
(
|
|
f"/{handle.scenario_id}/v1/systemone",
|
|
{"model": "jev-custom", "state": _CONFIGURED_STATE, "questions": _CONFIGURED_QUESTIONS},
|
|
)
|
|
]
|
|
|
|
|
|
def test_evaluation_mode_health_check_of_the_self_hosted_strands_model_resolves_the_mode_from_the_cost_map(
|
|
gateway: Gateway,
|
|
) -> None:
|
|
with gateway.scenario() as scenario:
|
|
handle: Final = register_scenario(f"health-decisions-{uuid.uuid4().hex[:12]}", _STRANDS_PROBE_REPLY)
|
|
scenario.cleanups.callback(delete_scenario, handle)
|
|
model: Final = scenario.model(
|
|
model="strands_decider/strands-decider-2B-hobson-v19", api_base=handle.api_base(), api_key=None
|
|
)
|
|
report: Final = _health_report(gateway, model)
|
|
assert (report["healthy_count"], report["unhealthy_count"]) == (1, 0), report
|
|
assert _probes_sent_to(gateway, handle) == [
|
|
(
|
|
f"/{handle.scenario_id}/v1/systemone",
|
|
{
|
|
"model": "strands-decider-2B-hobson-v19",
|
|
"state": os.environ.get("DEFAULT_HEALTH_CHECK_PROMPT", "test from litellm"),
|
|
"questions": {"reachable": {"type": "noul", "instructions": "Is the service reachable?"}},
|
|
},
|
|
)
|
|
]
|