Skip to content

Commit 04e69c0

Browse files
committed
fix file validation
1 parent 19389d9 commit 04e69c0

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/inferencesh/sdk.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async def unload(self):
101101

102102
class File(BaseModel):
103103
"""A class representing a file in the inference.sh ecosystem."""
104-
uri: str # Original location (URL or file path)
104+
uri: Optional[str] = None # Original location (URL or file path)
105105
path: Optional[str] = None # Resolved local file path
106106
content_type: Optional[str] = None # MIME type of the file
107107
size: Optional[int] = None # File size in bytes
@@ -113,12 +113,19 @@ class File(BaseModel):
113113
populate_by_name=True
114114
)
115115

116+
@model_validator(mode='after')
117+
def check_uri_or_path(self) -> 'File':
118+
"""Validate that either uri or path is provided."""
119+
if not self.uri and not self.path:
120+
raise ValueError("Either 'uri' or 'path' must be provided")
121+
return self
122+
116123
def model_post_init(self, _: Any) -> None:
117-
if self._is_url(self.uri):
124+
if self.uri and self._is_url(self.uri):
118125
self._download_url()
119-
elif not os.path.isabs(self.uri):
126+
elif self.uri and not os.path.isabs(self.uri):
120127
self.path = os.path.abspath(self.uri)
121-
else:
128+
elif self.uri:
122129
self.path = self.uri
123130
self._populate_metadata()
124131

0 commit comments

Comments
 (0)