File tree Expand file tree Collapse file tree 1 file changed +19
-14
lines changed
Expand file tree Collapse file tree 1 file changed +19
-14
lines changed Original file line number Diff line number Diff line change 77import hashlib
88from pathlib import Path
99from tqdm import tqdm
10+ from pydantic_core import core_schema
11+ from pydantic_core .core_schema import GetJsonSchemaHandler , JsonSchemaValue
1012
1113
1214class File (BaseModel ):
@@ -239,21 +241,24 @@ def refresh_metadata(self) -> None:
239241 @classmethod
240242 def model_json_schema (cls , ** kwargs ):
241243 schema = super ().model_json_schema (** kwargs )
244+ schema ["$id" ] = "/schemas/File"
242245 # Create a schema that accepts either a string or the full object
243- base_schema = {
244- "anyOf " : [
246+ return {
247+ "oneOf " : [
245248 {"type" : "string" }, # Accept string input
246- {
247- "type" : "object" ,
248- "properties" : schema ["properties" ],
249- "title" : schema .get ("title" , "File" ),
250- "description" : "A class representing a file in the inference.sh ecosystem."
251- }
249+ schema # Accept full object input
250+ ]
251+ }
252+
253+ @classmethod
254+ def __get_pydantic_json_schema__ (
255+ cls , core_schema : core_schema .CoreSchema , handler : GetJsonSchemaHandler
256+ ) -> JsonSchemaValue :
257+ schema = handler (core_schema ) # this is the "normal" schema
258+ return {
259+ "oneOf" : [
260+ {"type" : "string" },
261+ schema
252262 ]
253263 }
254- # If this is the top-level schema, return as is
255- if not kwargs .get ("ref_template" ):
256- return base_schema
257- # If this is being used in $defs, include it in the schema
258- schema .update (base_schema )
259- return schema
264+
You can’t perform that action at this time.
0 commit comments