inferencesh 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- inferencesh/sdk.py +48 -17
- {inferencesh-0.2.3.dist-info → inferencesh-0.2.5.dist-info}/METADATA +1 -1
- inferencesh-0.2.5.dist-info/RECORD +8 -0
- {inferencesh-0.2.3.dist-info → inferencesh-0.2.5.dist-info}/WHEEL +1 -1
- inferencesh-0.2.3.dist-info/RECORD +0 -8
- {inferencesh-0.2.3.dist-info → inferencesh-0.2.5.dist-info}/entry_points.txt +0 -0
- {inferencesh-0.2.3.dist-info → inferencesh-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {inferencesh-0.2.3.dist-info → inferencesh-0.2.5.dist-info}/top_level.txt +0 -0
inferencesh/sdk.py
CHANGED
|
@@ -140,17 +140,29 @@ class File(BaseModel):
|
|
|
140
140
|
return self
|
|
141
141
|
|
|
142
142
|
def model_post_init(self, _: Any) -> None:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
"""Initialize file path and metadata after model creation.
|
|
144
|
+
|
|
145
|
+
This method handles:
|
|
146
|
+
1. Downloading URLs to local files if uri is a URL
|
|
147
|
+
2. Converting relative paths to absolute paths
|
|
148
|
+
3. Populating file metadata
|
|
149
|
+
"""
|
|
150
|
+
# Handle uri if provided
|
|
151
|
+
if self.uri:
|
|
152
|
+
if self._is_url(self.uri):
|
|
153
|
+
self._download_url()
|
|
154
|
+
else:
|
|
155
|
+
# Convert relative paths to absolute, leave absolute paths unchanged
|
|
156
|
+
self.path = os.path.abspath(self.uri)
|
|
157
|
+
|
|
158
|
+
# Handle path if provided
|
|
149
159
|
if self.path:
|
|
160
|
+
# Convert relative paths to absolute, leave absolute paths unchanged
|
|
161
|
+
self.path = os.path.abspath(self.path)
|
|
150
162
|
self._populate_metadata()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
raise ValueError("Either 'uri' or 'path' must be provided and be valid")
|
|
154
166
|
def _is_url(self, path: str) -> bool:
|
|
155
167
|
"""Check if the path is a URL."""
|
|
156
168
|
parsed = urllib.parse.urlparse(path)
|
|
@@ -252,6 +264,18 @@ class File(BaseModel):
|
|
|
252
264
|
self.size = self._get_file_size() # Always update size
|
|
253
265
|
self.filename = self._get_filename()
|
|
254
266
|
|
|
267
|
+
@classmethod
|
|
268
|
+
def model_json_schema(cls, **kwargs):
|
|
269
|
+
schema = super().model_json_schema(**kwargs)
|
|
270
|
+
|
|
271
|
+
# Create a schema that accepts either a string or the full object
|
|
272
|
+
return {
|
|
273
|
+
"oneOf": [
|
|
274
|
+
{"type": "string"}, # Accept string input
|
|
275
|
+
schema # Accept full object input
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
|
|
255
279
|
|
|
256
280
|
class ContextMessageRole(str, Enum):
|
|
257
281
|
USER = "user"
|
|
@@ -326,19 +350,26 @@ class LLMInputWithImage(LLMInput):
|
|
|
326
350
|
default=None
|
|
327
351
|
)
|
|
328
352
|
|
|
329
|
-
class
|
|
330
|
-
"""Standard
|
|
331
|
-
DATA = "
|
|
332
|
-
TEMP = "
|
|
333
|
-
CACHE = "
|
|
353
|
+
class StorageDir(str, Enum):
|
|
354
|
+
"""Standard storage directories used by the SDK."""
|
|
355
|
+
DATA = "/app/data" # Persistent storage/cache directory
|
|
356
|
+
TEMP = "/app/tmp" # Temporary storage directory
|
|
357
|
+
CACHE = "/app/cache" # Cache directory
|
|
358
|
+
|
|
359
|
+
@property
|
|
360
|
+
def path(self) -> Path:
|
|
361
|
+
"""Get the Path object for this storage directory, ensuring it exists."""
|
|
362
|
+
path = Path(self.value)
|
|
363
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
364
|
+
return path
|
|
334
365
|
|
|
335
|
-
def download(url: str, directory: Union[str, Path,
|
|
366
|
+
def download(url: str, directory: Union[str, Path, StorageDir]) -> str:
|
|
336
367
|
"""Download a file to the specified directory and return its path.
|
|
337
368
|
|
|
338
369
|
Args:
|
|
339
370
|
url: The URL to download from
|
|
340
371
|
directory: The directory to save the file to. Can be a string path,
|
|
341
|
-
Path object, or
|
|
372
|
+
Path object, or StorageDir enum value.
|
|
342
373
|
|
|
343
374
|
Returns:
|
|
344
375
|
str: The path to the downloaded file
|
|
@@ -360,7 +391,7 @@ def download(url: str, directory: Union[str, Path, DownloadDir]) -> str:
|
|
|
360
391
|
output_path = hash_dir / filename
|
|
361
392
|
|
|
362
393
|
# If file exists in directory and it's not a temp directory, return it
|
|
363
|
-
if output_path.exists() and directory !=
|
|
394
|
+
if output_path.exists() and directory != StorageDir.TEMP:
|
|
364
395
|
return str(output_path)
|
|
365
396
|
|
|
366
397
|
# Download the file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
inferencesh/__init__.py,sha256=hbKkgHCh0lCdhWyHs3FHHRd8JfLeHkTd1bT4v79Fi8M,192
|
|
2
|
+
inferencesh/sdk.py,sha256=f_M4_-sKqYIg1kFiBjlI9-1nPNIw6DgLOdRo_9HaOzU,16202
|
|
3
|
+
inferencesh-0.2.5.dist-info/licenses/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
4
|
+
inferencesh-0.2.5.dist-info/METADATA,sha256=65IzfW7RGpTXrJevMcZo0w5xXnb9eYK4xEkd2uV3Yms,2756
|
|
5
|
+
inferencesh-0.2.5.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
6
|
+
inferencesh-0.2.5.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
7
|
+
inferencesh-0.2.5.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
8
|
+
inferencesh-0.2.5.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
inferencesh/__init__.py,sha256=hbKkgHCh0lCdhWyHs3FHHRd8JfLeHkTd1bT4v79Fi8M,192
|
|
2
|
-
inferencesh/sdk.py,sha256=KiD11omxGg0sbCiLSjyJnD1UvfWkUGyk9wB-3wIUcJU,15094
|
|
3
|
-
inferencesh-0.2.3.dist-info/licenses/LICENSE,sha256=OsgqEWIh2el_QMj0y8O1A5Q5Dl-dxqqYbFE6fszuR4s,1086
|
|
4
|
-
inferencesh-0.2.3.dist-info/METADATA,sha256=fLpjiyruNqbj9c9pIszbOpcwEAdK0tOATZCNfQvpIGE,2756
|
|
5
|
-
inferencesh-0.2.3.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
6
|
-
inferencesh-0.2.3.dist-info/entry_points.txt,sha256=6IC-fyozAqW3ljsMLGCXxJ0_ui2Jb-2fLHtoH1RTnEE,45
|
|
7
|
-
inferencesh-0.2.3.dist-info/top_level.txt,sha256=TSMHg3T1ThMl1HGAWmzBClwOYH1ump5neof9BfHIwaA,12
|
|
8
|
-
inferencesh-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|