mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
Merge 55b02a28f4 into b03e913ccf
This commit is contained in:
commit
74d5ce3a2f
2 changed files with 38 additions and 2 deletions
|
|
@ -92,8 +92,12 @@ class OCRResponse(LiteLLMPydanticObjectBase):
|
|||
document_annotation: Any | None = None
|
||||
usage_info: OCRUsageInfo | None = None
|
||||
content: str | None = None
|
||||
tables: list[dict[str, object]] | None = None
|
||||
keyValuePairs: list[dict[str, object]] | None = None
|
||||
# `Any`, not `object`: the `object` field below shadows the builtin in this
|
||||
# class namespace, and pydantic resolves the deferred annotations against
|
||||
# that namespace — so `dict[str, object]` resolves to the string "ocr" and
|
||||
# the model can never be built.
|
||||
tables: list[dict[str, Any]] | None = None
|
||||
keyValuePairs: list[dict[str, Any]] | None = None
|
||||
object: str = "ocr"
|
||||
|
||||
model_config = {"extra": "allow"}
|
||||
|
|
|
|||
32
tests/test_litellm/ocr/test_ocr_response_model_build.py
Normal file
32
tests/test_litellm/ocr/test_ocr_response_model_build.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""`OCRResponse` must be constructible.
|
||||
|
||||
The model declares a field literally named `object`, which shadows the builtin
|
||||
inside the class namespace. Pydantic resolves the deferred annotations against
|
||||
that namespace, so any *other* field annotated with the builtin `object`
|
||||
resolves to the string "ocr" and pydantic treats it as an unresolved forward
|
||||
reference — the model then cannot be built at all.
|
||||
"""
|
||||
|
||||
from litellm.llms.base_llm.ocr.transformation import OCRPage, OCRResponse
|
||||
|
||||
|
||||
def test_ocr_response_can_be_constructed():
|
||||
response = OCRResponse(
|
||||
pages=[OCRPage(index=0, markdown="# hello")],
|
||||
model="mistral-ocr-latest",
|
||||
)
|
||||
|
||||
assert response.object == "ocr"
|
||||
assert response.pages[0].markdown == "# hello"
|
||||
|
||||
|
||||
def test_ocr_response_accepts_tables_and_key_value_pairs():
|
||||
response = OCRResponse(
|
||||
pages=[OCRPage(index=0, markdown="# hello")],
|
||||
model="mistral-ocr-latest",
|
||||
tables=[{"rows": [["a", "b"]]}],
|
||||
keyValuePairs=[{"key": "invoice_no", "value": "42"}],
|
||||
)
|
||||
|
||||
assert response.tables == [{"rows": [["a", "b"]]}]
|
||||
assert response.keyValuePairs == [{"key": "invoice_no", "value": "42"}]
|
||||
Loading…
Add table
Reference in a new issue