mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-18 16:28:41 +00:00
Update to the ImageContentItem datatype so url + data is not in a confusing union
This commit is contained in:
parent
4936794de1
commit
cf9fce6b6e
6 changed files with 36 additions and 29 deletions
|
|
@ -4,11 +4,11 @@
|
|||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from typing import Annotated, List, Literal, Union
|
||||
from typing import Annotated, List, Literal, Optional, Union
|
||||
|
||||
from llama_models.schema_utils import json_schema_type, register_schema
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
|
||||
@json_schema_type(
|
||||
|
|
@ -21,10 +21,21 @@ class URL(BaseModel):
|
|||
return self.uri
|
||||
|
||||
|
||||
class _URLOrData(BaseModel):
|
||||
url: Optional[URL] = None
|
||||
data: Optional[bytes] = None
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validator(cls, values):
|
||||
if isinstance(values, dict):
|
||||
return values
|
||||
return {"url": values}
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class ImageContentItem(BaseModel):
|
||||
class ImageContentItem(_URLOrData):
|
||||
type: Literal["image"] = "image"
|
||||
data: Union[bytes, URL]
|
||||
|
||||
|
||||
@json_schema_type
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ from llama_models.schema_utils import json_schema_type
|
|||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from llama_stack.apis.common.content_types import URL
|
||||
|
||||
|
||||
@json_schema_type
|
||||
class RestAPIMethod(Enum):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue