FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
replicate-python/replicate/version.py at main · Gregoryquarles/replicate-python · GitHub
Gregoryquarles
/
replicate-python
Public
forked from
replicate/replicate-python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
replicate-python
/
replicate
/
version.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
158 lines (116 loc) · 4.26 KB
Breadcrumbs
replicate-python
/
replicate
/
version.py
Copy path
File metadata and controls
158 lines (116 loc) · 4.26 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import
datetime
from
typing
import
TYPE_CHECKING
,
Any
,
Dict
,
Tuple
,
Union
if
TYPE_CHECKING
:
from
replicate
.
client
import
Client
from
replicate
.
model
import
Model
from
replicate
.
pagination
import
Page
from
replicate
.
resource
import
Namespace
,
Resource
class
Version
(
Resource
):
"""
A version of a model.
"""
id
:
str
"""The unique ID of the version."""
created_at
:
datetime
.
datetime
"""When the version was created."""
cog_version
:
str
"""The version of the Cog used to create the version."""
openapi_schema
:
dict
"""An OpenAPI description of the model inputs and outputs."""
class
Versions
(
Namespace
):
"""
Namespace for operations related to model versions.
"""
model
:
Tuple
[
str
,
str
]
def
__init__
(
self
,
client
:
"Client"
,
model
:
Union
[
str
,
Tuple
[
str
,
str
],
"Model"
]
)
->
None
:
super
().
__init__
(
client
=
client
)
from
replicate
.
model
import
Model
# pylint: disable=import-outside-toplevel
if
isinstance
(
model
,
Model
):
self
.
model
=
(
model
.
owner
,
model
.
name
)
elif
isinstance
(
model
,
str
):
owner
,
name
=
model
.
split
(
"/"
,
1
)
self
.
model
=
(
owner
,
name
)
else
:
self
.
model
=
model
def
get
(
self
,
id
:
str
)
->
Version
:
"""
Get a specific model version.
Args:
id: The version ID.
Returns:
The model version.
"""
resp
=
self
.
_client
.
_request
(
"GET"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions/
{
id
}
"
)
return
_json_to_version
(
resp
.
json
())
async
def
async_get
(
self
,
id
:
str
)
->
Version
:
"""
Get a specific model version.
Args:
id: The version ID.
Returns:
The model version.
"""
resp
=
await
self
.
_client
.
_async_request
(
"GET"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions/
{
id
}
"
)
return
_json_to_version
(
resp
.
json
())
def
list
(
self
)
->
Page
[
Version
]:
"""
Return a list of all versions for a model.
Returns:
List[Version]: A list of version objects.
"""
resp
=
self
.
_client
.
_request
(
"GET"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions"
)
obj
=
resp
.
json
()
obj
[
"results"
]
=
[
_json_to_version
(
result
)
for
result
in
obj
[
"results"
]]
return
Page
[
Version
](
**
obj
)
async
def
async_list
(
self
)
->
Page
[
Version
]:
"""
Return a list of all versions for a model.
Returns:
List[Version]: A list of version objects.
"""
resp
=
await
self
.
_client
.
_async_request
(
"GET"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions"
)
obj
=
resp
.
json
()
obj
[
"results"
]
=
[
_json_to_version
(
result
)
for
result
in
obj
[
"results"
]]
return
Page
[
Version
](
**
obj
)
def
delete
(
self
,
id
:
str
)
->
bool
:
"""
Delete a model version and all associated predictions, including all output files.
Model version deletion has some restrictions:
* You can only delete versions from models you own.
* You can only delete versions from private models.
* You cannot delete a version if someone other than you
has run predictions with it.
Args:
id: The version ID.
"""
resp
=
self
.
_client
.
_request
(
"DELETE"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions/
{
id
}
"
)
return
resp
.
status_code
==
204
async
def
async_delete
(
self
,
id
:
str
)
->
bool
:
"""
Delete a model version and all associated predictions, including all output files.
Model version deletion has some restrictions:
* You can only delete versions from models you own.
* You can only delete versions from private models.
* You cannot delete a version if someone other than you
has run predictions with it.
Args:
id: The version ID.
"""
resp
=
await
self
.
_client
.
_async_request
(
"DELETE"
,
f"/v1/models/
{
self
.
model
[
0
]
}
/
{
self
.
model
[
1
]
}
/versions/
{
id
}
"
)
return
resp
.
status_code
==
204
def
_json_to_version
(
json
:
Dict
[
str
,
Any
])
->
Version
:
return
Version
(
**
json
)
Back
|
FazBrowse Home
|
New Git URL