mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-26 01:12:21 +00:00
* fix(proxy): document responses API request and response schemas in openapi Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(proxy): namespace colliding openapi defs instead of overwriting existing components Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore(proxy): regenerate lazy openapi snapshot and dashboard schema types Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(proxy): require model and input in responses schema, document event stream, fix def collision refs Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(proxy): mark responses request fields readonly required Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(proxy): reuse existing OpenAPI components when a $defs entry has the same shape Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: kerry <kerry@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
43 lines
2.4 KiB
Python
43 lines
2.4 KiB
Python
from typing import Final
|
|
|
|
from integration._support.client import Gateway, object_value, string_value
|
|
from pydantic import JsonValue
|
|
|
|
|
|
def _operation(openapi: dict[str, JsonValue], path: str, method: str) -> dict[str, JsonValue]:
|
|
return object_value(object_value(object_value(openapi["paths"])[path])[method])
|
|
|
|
|
|
def _ok_schema_properties(openapi: dict[str, JsonValue], operation: dict[str, JsonValue]) -> dict[str, JsonValue]:
|
|
ok: Final = object_value(object_value(operation["responses"])["200"])
|
|
schema: Final = object_value(object_value(object_value(ok["content"])["application/json"])["schema"])
|
|
if "$ref" in schema:
|
|
name: Final = string_value(schema["$ref"]).rsplit("/", 1)[-1]
|
|
return object_value(object_value(object_value(object_value(openapi["components"])["schemas"])[name])["properties"])
|
|
assert "properties" in schema, ok
|
|
return object_value(schema["properties"])
|
|
|
|
|
|
def test_v1_responses_post_declares_a_request_body_and_response_schema(gateway: Gateway) -> None:
|
|
openapi: dict[str, JsonValue] = gateway.get("/openapi.json")
|
|
post: Final = _operation(openapi, "/v1/responses", "post")
|
|
body: Final = object_value(post["requestBody"])
|
|
schema: Final = object_value(object_value(object_value(body["content"])["application/json"])["schema"])
|
|
properties: Final = object_value(schema.get("properties"))
|
|
assert {"model", "input", "instructions", "tools", "previous_response_id", "background", "stream"} <= set(
|
|
properties
|
|
), sorted(properties)
|
|
assert {"id", "object", "output", "usage"} <= set(_ok_schema_properties(openapi, post)), post["responses"]
|
|
assert "tool_calls" in object_value(
|
|
object_value(object_value(object_value(openapi["components"])["schemas"])["Message"])["properties"]
|
|
)
|
|
|
|
|
|
def test_v1_responses_by_id_routes_declare_response_schemas(gateway: Gateway) -> None:
|
|
openapi: dict[str, JsonValue] = gateway.get("/openapi.json")
|
|
get: Final = _operation(openapi, "/v1/responses/{response_id}", "get")
|
|
assert {"id", "object", "output"} <= set(_ok_schema_properties(openapi, get)), get["responses"]
|
|
delete: Final = _operation(openapi, "/v1/responses/{response_id}", "delete")
|
|
assert {"id", "object", "deleted"} <= set(_ok_schema_properties(openapi, delete)), delete["responses"]
|
|
items: Final = _operation(openapi, "/v1/responses/{response_id}/input_items", "get")
|
|
assert {"data", "object", "has_more"} <= set(_ok_schema_properties(openapi, items)), items["responses"]
|