Skip to content

Commit 587ed82

Browse files
committed
Add unit tests for existing use() functionality
1 parent e4398b9 commit 587ed82

File tree

2 files changed

+509
-157
lines changed

2 files changed

+509
-157
lines changed

replicate/use.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# - [ ] Support lazy downloading of files into Path
1010
# - [ ] Support helpers for working with ContatenateIterator
1111
import inspect
12+
import os
1213
from dataclasses import dataclass
1314
from functools import cached_property
1415
from typing import Any, Dict, Optional, Tuple
@@ -26,10 +27,9 @@ def _in_module_scope() -> bool:
2627
"""
2728
Returns True when called from top level module scope.
2829
"""
29-
import os
3030
if os.getenv("REPLICATE_ALWAYS_ALLOW_USE"):
3131
return True
32-
32+
3333
if frame := inspect.currentframe():
3434
if caller := frame.f_back:
3535
return caller.f_code.co_name == "<module>"
@@ -172,8 +172,13 @@ def openapi_schema(self) -> dict[Any, Any]:
172172
"""
173173
Get the OpenAPI schema for this model version.
174174
"""
175-
schema = self._model.latest_version.openapi_schema
176-
if cog_version := self._model.latest_version.cog_version:
175+
latest_version = self._model.latest_version
176+
if latest_version is None:
177+
msg = f"Model {self._model.owner}/{self._model.name} has no latest version"
178+
raise ValueError(msg)
179+
180+
schema = latest_version.openapi_schema
181+
if cog_version := latest_version.cog_version:
177182
schema = make_schema_backwards_compatible(schema, cog_version)
178183
return schema
179184

0 commit comments

Comments
 (0)