|
9 | 9 | from pathlib import Path |
10 | 10 | from tqdm import tqdm |
11 | 11 |
|
12 | | -from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler |
13 | | -from pydantic_core import CoreSchema, core_schema |
14 | | - |
15 | 12 | class File(BaseModel): |
16 | 13 | """A class representing a file in the inference.sh ecosystem.""" |
17 | 14 |
|
@@ -239,22 +236,29 @@ def refresh_metadata(self) -> None: |
239 | 236 | self.size = self._get_file_size() # Always update size |
240 | 237 | self.filename = self._get_filename() |
241 | 238 |
|
242 | | - @classmethod |
243 | | - def __get_pydantic_core_schema__( |
244 | | - cls, source: Type[Any], handler: GetCoreSchemaHandler |
245 | | - ) -> CoreSchema: |
246 | | - """Generates a Pydantic Core schema for validation of this File class""" |
247 | | - # Get the default schema for our class |
248 | | - schema = handler(source) |
| 239 | + # @classmethod |
| 240 | + # def __get_pydantic_core_schema__( |
| 241 | + # cls, source: Type[Any], handler: GetCoreSchemaHandler |
| 242 | + # ) -> CoreSchema: |
| 243 | + # """Generates a Pydantic Core schema for validation of this File class""" |
| 244 | + # # Get the default schema for our class |
| 245 | + # schema = handler(source) |
| 246 | + |
| 247 | + # # Create a proper serialization schema that includes the type |
| 248 | + # serialization = core_schema.plain_serializer_function_ser_schema( |
| 249 | + # lambda x: x.uri if x.uri else x.path, |
| 250 | + # return_schema=core_schema.str_schema(), |
| 251 | + # when_used="json", |
| 252 | + # ) |
249 | 253 |
|
250 | | - return core_schema.json_or_python_schema( |
251 | | - json_schema=core_schema.union_schema([ |
252 | | - core_schema.str_schema(), # Accept string input |
253 | | - schema, # Accept full object input |
254 | | - ]), |
255 | | - python_schema=schema, |
256 | | - serialization=schema.get("serialization", {}), |
257 | | - ) |
| 254 | + # return core_schema.json_or_python_schema( |
| 255 | + # json_schema=core_schema.union_schema([ |
| 256 | + # core_schema.str_schema(), # Accept string input |
| 257 | + # schema, # Accept full object input |
| 258 | + # ]), |
| 259 | + # python_schema=schema, |
| 260 | + # serialization=serialization, |
| 261 | + # ) |
258 | 262 |
|
259 | 263 | @classmethod |
260 | 264 | def __get_pydantic_json_schema__( |
|
0 commit comments