Skip to content

Commit 3ee307c

Browse files
committed
File update
1 parent 439c59a commit 3ee307c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "inferencesh"
7-
version = "0.1.12"
7+
version = "0.1.13"
88
description = "inference.sh Python SDK"
99
authors = [
1010
{name = "Inference Shell Inc.", email = "hello@inference.sh"},

src/inferencesh/sdk.py

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

102102
class File(BaseModel):
103103
"""A class representing a file in the inference.sh ecosystem."""
104-
path: str # Absolute path to the file or URL
104+
uri: str # Original location (URL or file path)
105+
path: Optional[str] = None # Resolved local file path
105106
mime_type: Optional[str] = None # MIME type of the file
106107
size: Optional[int] = None # File size in bytes
107108
filename: Optional[str] = None # Original filename if available
108-
_tmp_path: Optional[str] = None # Internal storage for temporary file path
109+
_tmp_path: Optional[str] = PrivateAttr(default=None) # Internal storage for temporary file path
109110

110111
def __init__(self, **data):
111112
super().__init__(**data)
112-
if self._is_url(self.path):
113+
if self._is_url(self.uri):
113114
self._download_url()
114-
elif not os.path.isabs(self.path):
115-
self.path = os.path.abspath(self.path)
115+
elif not os.path.isabs(self.uri):
116+
self.path = os.path.abspath(self.uri)
117+
else:
118+
self.path = self.uri
116119
self._populate_metadata()
117120

118121
def _is_url(self, path: str) -> bool:
119122
"""Check if the path is a URL."""
120123
parsed = urllib.parse.urlparse(path)
121124
return parsed.scheme in ('http', 'https')
125+
122126
def _download_url(self) -> None:
123127
"""Download the URL to a temporary file and update the path."""
124-
original_url = self.path
128+
original_url = self.uri
125129
tmp_file = None
126130
try:
127131
# Create a temporary file with a suffix based on the URL path
@@ -179,7 +183,7 @@ def _populate_metadata(self) -> None:
179183
@classmethod
180184
def from_path(cls, path: Union[str, os.PathLike]) -> 'File':
181185
"""Create a File instance from a file path."""
182-
return cls(path=str(path))
186+
return cls(uri=str(path))
183187

184188
def _guess_mime_type(self) -> Optional[str]:
185189
"""Guess the MIME type of the file."""

0 commit comments

Comments
 (0)