mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-06-28 02:53:30 +00:00
chore: more mypy checks (ollama, vllm, ...) (#1777)
# What does this PR do? - **chore: mypy for strong_typing** - **chore: mypy for remote::vllm** - **chore: mypy for remote::ollama** - **chore: mypy for providers.datatype** --------- Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
parent
d5e0f32485
commit
66d6c2580e
15 changed files with 103 additions and 72 deletions
|
@ -460,13 +460,17 @@ class JsonSchemaGenerator:
|
|||
discriminator = None
|
||||
if typing.get_origin(data_type) is Annotated:
|
||||
discriminator = typing.get_args(data_type)[1].discriminator
|
||||
ret = {"oneOf": [self.type_to_schema(union_type) for union_type in typing.get_args(typ)]}
|
||||
ret: Schema = {"oneOf": [self.type_to_schema(union_type) for union_type in typing.get_args(typ)]}
|
||||
if discriminator:
|
||||
# for each union type, we need to read the value of the discriminator
|
||||
mapping = {}
|
||||
mapping: dict[str, JsonType] = {}
|
||||
for union_type in typing.get_args(typ):
|
||||
props = self.type_to_schema(union_type, force_expand=True)["properties"]
|
||||
mapping[props[discriminator]["default"]] = self.type_to_schema(union_type)["$ref"]
|
||||
# mypy is confused here because JsonType allows multiple types, some of them
|
||||
# not indexable (bool?) or not indexable by string (list?). The correctness of
|
||||
# types depends on correct model definitions. Hence multiple ignore statements below.
|
||||
discriminator_value = props[discriminator]["default"] # type: ignore[index,call-overload]
|
||||
mapping[discriminator_value] = self.type_to_schema(union_type)["$ref"] # type: ignore[index]
|
||||
|
||||
ret["discriminator"] = {
|
||||
"propertyName": discriminator,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue