openprotein-python 0.4.3__py3-none-any.whl → 0.5.0.dev0__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.
- openprotein/__init__.py +40 -17
- openprotein/api/__init__.py +2 -7
- openprotein/api/align.py +68 -496
- openprotein/api/assaydata.py +216 -0
- openprotein/api/deprecated/__init__.py +0 -0
- openprotein/api/deprecated/poet.py +304 -0
- openprotein/api/design.py +7 -433
- openprotein/api/embedding.py +155 -999
- openprotein/api/fold.py +26 -319
- openprotein/api/job.py +91 -0
- openprotein/api/predict.py +25 -381
- openprotein/api/predictor.py +205 -0
- openprotein/api/svd.py +150 -0
- openprotein/api/train.py +42 -481
- openprotein/app/__init__.py +11 -0
- openprotein/app/models/__init__.py +20 -0
- openprotein/app/models/align/__init__.py +5 -0
- openprotein/app/models/align/base.py +20 -0
- openprotein/app/models/align/msa.py +140 -0
- openprotein/app/models/align/prompt.py +83 -0
- openprotein/app/models/assaydata.py +176 -0
- openprotein/app/models/deprecated/__init__.py +0 -0
- openprotein/app/models/deprecated/poet.py +183 -0
- openprotein/app/models/design.py +102 -0
- openprotein/app/models/embeddings/__init__.py +7 -0
- openprotein/app/models/embeddings/base.py +269 -0
- openprotein/app/models/embeddings/esm.py +32 -0
- openprotein/app/models/embeddings/future.py +98 -0
- openprotein/app/models/embeddings/openprotein.py +21 -0
- openprotein/app/models/embeddings/poet.py +393 -0
- openprotein/app/models/embeddings/test.py +38 -0
- openprotein/app/models/fold/__init__.py +6 -0
- openprotein/app/models/fold/alphafold2.py +50 -0
- openprotein/app/models/fold/base.py +81 -0
- openprotein/app/models/fold/esmfold.py +31 -0
- openprotein/app/models/fold/future.py +53 -0
- openprotein/app/models/futures.py +445 -0
- openprotein/app/models/predict.py +158 -0
- openprotein/app/models/predictor/__init__.py +4 -0
- openprotein/app/models/predictor/predict.py +78 -0
- openprotein/app/models/predictor/predictor.py +141 -0
- openprotein/app/models/svd.py +171 -0
- openprotein/app/models/train.py +300 -0
- openprotein/app/services/__init__.py +11 -0
- openprotein/app/services/align.py +147 -0
- openprotein/app/services/assaydata.py +127 -0
- openprotein/app/services/design.py +77 -0
- openprotein/app/services/embeddings.py +126 -0
- openprotein/app/services/fold.py +89 -0
- openprotein/app/services/job.py +48 -0
- openprotein/app/services/predict.py +139 -0
- openprotein/app/services/predictor.py +168 -0
- openprotein/app/services/svd.py +102 -0
- openprotein/app/services/train.py +135 -0
- openprotein/config.py +0 -3
- openprotein/errors.py +22 -5
- openprotein/schemas/__init__.py +59 -0
- openprotein/schemas/align.py +55 -0
- openprotein/schemas/assaydata.py +27 -0
- openprotein/schemas/deprecated/__init__.py +0 -0
- openprotein/schemas/deprecated/poet.py +70 -0
- openprotein/schemas/design.py +251 -0
- openprotein/schemas/embeddings.py +103 -0
- openprotein/schemas/fold.py +10 -0
- openprotein/schemas/job.py +110 -0
- openprotein/schemas/predict.py +83 -0
- openprotein/schemas/predictor.py +83 -0
- openprotein/schemas/svd.py +32 -0
- openprotein/schemas/train.py +34 -0
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info}/METADATA +19 -14
- openprotein_python-0.5.0.dev0.dist-info/RECORD +76 -0
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info}/WHEEL +1 -1
- openprotein/api/data.py +0 -532
- openprotein/api/jobs.py +0 -351
- openprotein/api/poet.py +0 -612
- openprotein/futures.py +0 -60
- openprotein/jobs.py +0 -186
- openprotein/pydantic.py +0 -20
- openprotein/schemas.py +0 -55
- openprotein_python-0.4.3.dist-info/RECORD +0 -24
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info/licenses}/LICENSE.txt +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
from openprotein.base import APISession
|
|
2
|
+
from openprotein.errors import APIError
|
|
3
|
+
from openprotein.schemas import AssayDataPage, AssayMetadata
|
|
4
|
+
from pydantic import TypeAdapter
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def list_models(session: APISession, assay_id: str) -> list:
|
|
8
|
+
"""
|
|
9
|
+
List models assoicated with assay.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
session : APISession
|
|
14
|
+
Session object for API communication.
|
|
15
|
+
assay_id : str
|
|
16
|
+
assay ID
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
List
|
|
21
|
+
List of models
|
|
22
|
+
"""
|
|
23
|
+
endpoint = "v1/models"
|
|
24
|
+
response = session.get(endpoint, params={"assay_id": assay_id})
|
|
25
|
+
return response.json()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def assaydata_post(
|
|
29
|
+
session: APISession,
|
|
30
|
+
assay_file,
|
|
31
|
+
assay_name: str,
|
|
32
|
+
assay_description: str | None = "",
|
|
33
|
+
) -> AssayMetadata:
|
|
34
|
+
"""
|
|
35
|
+
Post assay data.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
session : APISession
|
|
40
|
+
Session object for API communication.
|
|
41
|
+
assay_file : str
|
|
42
|
+
Path to the assay data file.
|
|
43
|
+
assay_name : str
|
|
44
|
+
Name of the assay.
|
|
45
|
+
assay_description : str, optional
|
|
46
|
+
Description of the assay, by default ''.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
AssayMetadata
|
|
51
|
+
Metadata of the posted assay data.
|
|
52
|
+
"""
|
|
53
|
+
endpoint = "v1/assaydata"
|
|
54
|
+
|
|
55
|
+
files = {"assay_data": assay_file}
|
|
56
|
+
data = {"assay_name": assay_name, "assay_description": assay_description}
|
|
57
|
+
|
|
58
|
+
response = session.post(endpoint, files=files, data=data)
|
|
59
|
+
if response.status_code == 200:
|
|
60
|
+
return TypeAdapter(AssayMetadata).validate_python(response.json())
|
|
61
|
+
else:
|
|
62
|
+
raise APIError(f"Unable to post assay data: {response.text}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def assaydata_list(session: APISession) -> list[AssayMetadata]:
|
|
66
|
+
"""
|
|
67
|
+
Get a list of all assay metadata.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
session : APISession
|
|
72
|
+
Session object for API communication.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
List[AssayMetadata]
|
|
77
|
+
List of all assay metadata.
|
|
78
|
+
|
|
79
|
+
Raises
|
|
80
|
+
------
|
|
81
|
+
APIError
|
|
82
|
+
If an error occurs during the API request.
|
|
83
|
+
"""
|
|
84
|
+
endpoint = "v1/assaydata"
|
|
85
|
+
response = session.get(endpoint)
|
|
86
|
+
if response.status_code == 200:
|
|
87
|
+
return TypeAdapter(list[AssayMetadata]).validate_python(response.json())
|
|
88
|
+
else:
|
|
89
|
+
raise APIError(f"Unable to list assay data: {response.text}")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def get_assay_metadata(session: APISession, assay_id: str) -> AssayMetadata:
|
|
93
|
+
"""
|
|
94
|
+
Retrieve metadata for a specified assay.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
session : APISession
|
|
100
|
+
The current API session for communication with the server.
|
|
101
|
+
assay_id : str
|
|
102
|
+
The identifier of the assay for which metadata is to be retrieved.
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
AssayMetadata
|
|
107
|
+
An AssayMetadata that contains the metadata for the specified assay.
|
|
108
|
+
|
|
109
|
+
Raises
|
|
110
|
+
------
|
|
111
|
+
InvalidJob
|
|
112
|
+
If no assay metadata with the specified assay_id is found.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
endpoint = "v1/assaydata/metadata"
|
|
116
|
+
response = session.get(endpoint, params={"assay_id": assay_id})
|
|
117
|
+
if response.status_code == 200:
|
|
118
|
+
data = TypeAdapter(AssayMetadata).validate_python(response.json())
|
|
119
|
+
else:
|
|
120
|
+
raise APIError(f"Unable to list assay data: {response.text}")
|
|
121
|
+
if data == []:
|
|
122
|
+
raise APIError(f"No assay with id={assay_id} found")
|
|
123
|
+
return data
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def assaydata_put(
|
|
127
|
+
session: APISession,
|
|
128
|
+
assay_id: str,
|
|
129
|
+
assay_name: str | None = None,
|
|
130
|
+
assay_description: str | None = None,
|
|
131
|
+
) -> AssayMetadata:
|
|
132
|
+
"""
|
|
133
|
+
Update assay metadata.
|
|
134
|
+
|
|
135
|
+
Parameters
|
|
136
|
+
----------
|
|
137
|
+
session : APISession
|
|
138
|
+
Session object for API communication.
|
|
139
|
+
assay_id : str
|
|
140
|
+
Id of the assay.
|
|
141
|
+
assay_name : str, optional
|
|
142
|
+
New name of the assay, by default None.
|
|
143
|
+
assay_description : str, optional
|
|
144
|
+
New description of the assay, by default None.
|
|
145
|
+
|
|
146
|
+
Returns
|
|
147
|
+
-------
|
|
148
|
+
AssayMetadata
|
|
149
|
+
Updated metadata of the assay.
|
|
150
|
+
|
|
151
|
+
Raises
|
|
152
|
+
------
|
|
153
|
+
APIError
|
|
154
|
+
If an error occurs during the API request.
|
|
155
|
+
"""
|
|
156
|
+
endpoint = f"v1/assaydata/{assay_id}"
|
|
157
|
+
data = {}
|
|
158
|
+
if assay_name is not None:
|
|
159
|
+
data["assay_name"] = assay_name
|
|
160
|
+
if assay_description is not None:
|
|
161
|
+
data["assay_description"] = assay_description
|
|
162
|
+
|
|
163
|
+
response = session.put(endpoint, data=data)
|
|
164
|
+
if response.status_code == 200:
|
|
165
|
+
return TypeAdapter(AssayMetadata).validate_python(response.json())
|
|
166
|
+
else:
|
|
167
|
+
raise APIError(f"Unable to update assay data: {response.text}")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def assaydata_page_get(
|
|
171
|
+
session: APISession,
|
|
172
|
+
assay_id: str,
|
|
173
|
+
measurement_name: str | None = None,
|
|
174
|
+
page_offset: int = 0,
|
|
175
|
+
page_size: int = 1000,
|
|
176
|
+
data_format: str = "wide",
|
|
177
|
+
) -> AssayDataPage:
|
|
178
|
+
"""
|
|
179
|
+
Get a page of assay data.
|
|
180
|
+
|
|
181
|
+
Parameters
|
|
182
|
+
----------
|
|
183
|
+
session : APISession
|
|
184
|
+
Session object for API communication.
|
|
185
|
+
assay_id : str
|
|
186
|
+
Id of the assay.
|
|
187
|
+
measurement_name : str, optional
|
|
188
|
+
Name of the measurement, by default None.
|
|
189
|
+
page_offset : int, optional
|
|
190
|
+
Offset of the page, by default 0.
|
|
191
|
+
page_size : int, optional
|
|
192
|
+
Size of the page, by default 1000.
|
|
193
|
+
data_format : str, optional
|
|
194
|
+
data_format of the data, by default 'wide'.
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
AssayDataPage
|
|
199
|
+
Page of assay data.
|
|
200
|
+
|
|
201
|
+
Raises
|
|
202
|
+
------
|
|
203
|
+
APIError
|
|
204
|
+
If an error occurs during the API request.
|
|
205
|
+
"""
|
|
206
|
+
endpoint = f"v1/assaydata/{assay_id}"
|
|
207
|
+
|
|
208
|
+
params = {"page_offset": page_offset, "page_size": page_size, "format": data_format}
|
|
209
|
+
if measurement_name is not None:
|
|
210
|
+
params["measurement_name"] = measurement_name
|
|
211
|
+
|
|
212
|
+
response = session.get(endpoint, params=params)
|
|
213
|
+
if response.status_code == 200:
|
|
214
|
+
return TypeAdapter(AssayDataPage).validate_python(response.json())
|
|
215
|
+
else:
|
|
216
|
+
raise APIError(f"Unable to get assay data page: {response.text}")
|
|
File without changes
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import random
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
from openprotein import config
|
|
6
|
+
from openprotein.base import APISession
|
|
7
|
+
from openprotein.errors import APIError, InvalidParameterError, MissingParameterError
|
|
8
|
+
from openprotein.schemas import PoetGenerateJob, PoetScoreJob, PoetSSPJob
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def poet_score_post(
|
|
12
|
+
session: APISession, prompt_id: str, queries: list[bytes] | list[str]
|
|
13
|
+
) -> PoetScoreJob:
|
|
14
|
+
"""
|
|
15
|
+
Submits a job to score sequences based on the given prompt.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
----------
|
|
19
|
+
session : APISession
|
|
20
|
+
An instance of APISession to manage interactions with the API.
|
|
21
|
+
prompt_id : str
|
|
22
|
+
The ID of the prompt.
|
|
23
|
+
queries : List[str]
|
|
24
|
+
A list of query sequences to be scored.
|
|
25
|
+
|
|
26
|
+
Raises
|
|
27
|
+
------
|
|
28
|
+
APIError
|
|
29
|
+
If there is an issue with the API request.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
PoetScoreJob
|
|
34
|
+
An object representing the status and results of the scoring job.
|
|
35
|
+
"""
|
|
36
|
+
endpoint = "v1/poet/score"
|
|
37
|
+
|
|
38
|
+
if len(queries) == 0:
|
|
39
|
+
raise MissingParameterError("Must include queries for scoring!")
|
|
40
|
+
if not prompt_id:
|
|
41
|
+
raise MissingParameterError("Must include prompt_id in request!")
|
|
42
|
+
|
|
43
|
+
queries = [i.encode() if isinstance(i, str) else i for i in queries]
|
|
44
|
+
try:
|
|
45
|
+
variant_file = io.BytesIO(b"\n".join(queries))
|
|
46
|
+
params = {"prompt_id": prompt_id}
|
|
47
|
+
response = session.post(
|
|
48
|
+
endpoint, files={"variant_file": variant_file}, params=params
|
|
49
|
+
)
|
|
50
|
+
return PoetScoreJob.model_validate(response.json())
|
|
51
|
+
except Exception as exc:
|
|
52
|
+
raise APIError(f"Failed to post poet score: {exc}") from exc
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def poet_score_get(
|
|
56
|
+
session: APISession, job_id, page_size=config.POET_PAGE_SIZE, page_offset=0
|
|
57
|
+
):
|
|
58
|
+
"""
|
|
59
|
+
Fetch a page of results from a PoET score job.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
session : APISession
|
|
64
|
+
An instance of APISession to manage interactions with the API.
|
|
65
|
+
job_id : str
|
|
66
|
+
The ID of the PoET scoring job to fetch results from.
|
|
67
|
+
page_size : int, optional
|
|
68
|
+
The number of results to fetch in a single page. Defaults to config.POET_PAGE_SIZE.
|
|
69
|
+
page_offset : int, optional
|
|
70
|
+
The offset (number of results) to start fetching results from. Defaults to 0.
|
|
71
|
+
|
|
72
|
+
Raises
|
|
73
|
+
------
|
|
74
|
+
APIError
|
|
75
|
+
If the provided page size is larger than the maximum allowed page size.
|
|
76
|
+
|
|
77
|
+
Returns
|
|
78
|
+
-------
|
|
79
|
+
PoetScoreJob
|
|
80
|
+
An object representing the PoET scoring job, including its current status and results (if any).
|
|
81
|
+
"""
|
|
82
|
+
endpoint = "v1/poet/score"
|
|
83
|
+
|
|
84
|
+
if page_size > config.POET_MAX_PAGE_SIZE:
|
|
85
|
+
raise APIError(
|
|
86
|
+
f"Page size must be less than the max for PoET: {config.POET_MAX_PAGE_SIZE}"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
response = session.get(
|
|
90
|
+
endpoint,
|
|
91
|
+
params={"job_id": job_id, "page_size": page_size, "page_offset": page_offset},
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# return results to be assembled together
|
|
95
|
+
return PoetScoreJob.model_validate(response.json())
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def poet_single_site_post(
|
|
99
|
+
session: APISession,
|
|
100
|
+
variant,
|
|
101
|
+
parent_id: str | None = None,
|
|
102
|
+
prompt_id: str | None = None,
|
|
103
|
+
) -> PoetSSPJob:
|
|
104
|
+
"""
|
|
105
|
+
Request PoET single-site analysis for a variant.
|
|
106
|
+
|
|
107
|
+
This function will mutate every position in the variant to every amino acid and return the scores.
|
|
108
|
+
Note that if parent_id is set then it will inherit all prompt properties of that parent.
|
|
109
|
+
|
|
110
|
+
Parameters
|
|
111
|
+
----------
|
|
112
|
+
session : APISession
|
|
113
|
+
An instance of APISession for API interactions.
|
|
114
|
+
variant : str
|
|
115
|
+
The variant to analyze.
|
|
116
|
+
parent_id : str, optional
|
|
117
|
+
The ID of the parent job. Either parent_id or prompt_id must be set. Defaults to None.
|
|
118
|
+
prompt_id : str, optional
|
|
119
|
+
The ID of the prompt. Either parent_id or prompt_id must be set. Defaults to None.
|
|
120
|
+
|
|
121
|
+
Raises
|
|
122
|
+
------
|
|
123
|
+
APIError
|
|
124
|
+
If the input parameters are invalid or there is an issue with the API request.
|
|
125
|
+
|
|
126
|
+
Returns
|
|
127
|
+
-------
|
|
128
|
+
PoetSSPJob
|
|
129
|
+
An object representing the status and results of the PoET single-site analysis job.
|
|
130
|
+
Note that the input variant score is given as `X0X`.
|
|
131
|
+
"""
|
|
132
|
+
endpoint = "v1/poet/single_site"
|
|
133
|
+
|
|
134
|
+
if (parent_id is None and prompt_id is None) or (
|
|
135
|
+
parent_id is not None and prompt_id is not None
|
|
136
|
+
):
|
|
137
|
+
raise InvalidParameterError("Either parent_id or prompt_id must be set.")
|
|
138
|
+
|
|
139
|
+
if isinstance(variant, str):
|
|
140
|
+
variant = variant.encode()
|
|
141
|
+
|
|
142
|
+
params = {"variant": variant}
|
|
143
|
+
if prompt_id is not None:
|
|
144
|
+
params["prompt_id"] = prompt_id
|
|
145
|
+
if parent_id is not None:
|
|
146
|
+
params["parent_id"] = parent_id
|
|
147
|
+
|
|
148
|
+
try:
|
|
149
|
+
response = session.post(endpoint, params=params)
|
|
150
|
+
return PoetSSPJob.model_validate(response.json())
|
|
151
|
+
except Exception as exc:
|
|
152
|
+
raise APIError(f"Failed to post poet single-site analysis: {exc}") from exc
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def poet_single_site_get(
|
|
156
|
+
session: APISession, job_id: str, page_size: int = 100, page_offset: int = 0
|
|
157
|
+
) -> PoetSSPJob:
|
|
158
|
+
"""
|
|
159
|
+
Fetch paged results of a PoET single-site analysis job.
|
|
160
|
+
|
|
161
|
+
Parameters
|
|
162
|
+
----------
|
|
163
|
+
session : APISession
|
|
164
|
+
An instance of APISession for API interactions.
|
|
165
|
+
job_id : str
|
|
166
|
+
The ID of the PoET single-site analysis job to fetch results from.
|
|
167
|
+
page_size : int, optional
|
|
168
|
+
The number of results to fetch in a single page. Defaults to 100.
|
|
169
|
+
page_offset : int, optional
|
|
170
|
+
The offset (number of results) to start fetching results from. Defaults to 0.
|
|
171
|
+
|
|
172
|
+
Raises
|
|
173
|
+
------
|
|
174
|
+
APIError
|
|
175
|
+
If there is an issue with the API request.
|
|
176
|
+
|
|
177
|
+
Returns
|
|
178
|
+
-------
|
|
179
|
+
PoetSSPJob
|
|
180
|
+
An object representing the status and results of the PoET single-site analysis job.
|
|
181
|
+
"""
|
|
182
|
+
endpoint = "v1/poet/single_site"
|
|
183
|
+
|
|
184
|
+
params = {"job_id": job_id, "page_size": page_size, "page_offset": page_offset}
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
response = session.get(endpoint, params=params)
|
|
188
|
+
|
|
189
|
+
except Exception as exc:
|
|
190
|
+
raise APIError(
|
|
191
|
+
f"Failed to get poet single-site analysis results: {exc}"
|
|
192
|
+
) from exc
|
|
193
|
+
# return results to be assembled together
|
|
194
|
+
return PoetSSPJob.model_validate(response.json())
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def poet_generate_post(
|
|
198
|
+
session: APISession,
|
|
199
|
+
prompt_id: str,
|
|
200
|
+
num_samples: int = 100,
|
|
201
|
+
temperature: float = 1.0,
|
|
202
|
+
topk: float | None = None,
|
|
203
|
+
topp: float | None = None,
|
|
204
|
+
max_length: int | None = 1000,
|
|
205
|
+
random_seed: int | None = None,
|
|
206
|
+
) -> PoetGenerateJob:
|
|
207
|
+
"""
|
|
208
|
+
Generate protein sequences with a prompt.
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
session : APISession
|
|
213
|
+
An instance of APISession for API interactions.
|
|
214
|
+
prompt_id : str
|
|
215
|
+
The ID of the prompt to generate samples from.
|
|
216
|
+
num_samples : int, optional
|
|
217
|
+
The number of samples to generate. Defaults to 100.
|
|
218
|
+
temperature : float, optional
|
|
219
|
+
The temperature for sampling. Higher values produce more random outputs. Defaults to 1.0.
|
|
220
|
+
topk : int, optional
|
|
221
|
+
The number of top-k residues to consider during sampling. Defaults to None.
|
|
222
|
+
topp : float, optional
|
|
223
|
+
The cumulative probability threshold for top-p sampling. Defaults to None.
|
|
224
|
+
max_length : int, optional
|
|
225
|
+
The maximum length of generated proteins. Defaults to 1000.
|
|
226
|
+
random_seed : int, optional
|
|
227
|
+
Seed for random number generation. Defaults to a random number.
|
|
228
|
+
|
|
229
|
+
Raises
|
|
230
|
+
------
|
|
231
|
+
APIError
|
|
232
|
+
If there is an issue with the API request.
|
|
233
|
+
|
|
234
|
+
Returns
|
|
235
|
+
-------
|
|
236
|
+
Job
|
|
237
|
+
An object representing the status and information about the generation job.
|
|
238
|
+
"""
|
|
239
|
+
endpoint = "v1/poet/generate"
|
|
240
|
+
|
|
241
|
+
if not (0.1 <= temperature <= 2):
|
|
242
|
+
raise InvalidParameterError("The 'temperature' must be between 0.1 and 2.")
|
|
243
|
+
if topk:
|
|
244
|
+
if not (2 <= topk <= 20):
|
|
245
|
+
raise InvalidParameterError("The 'topk' must be between 2 and 22.")
|
|
246
|
+
if topp:
|
|
247
|
+
if not (0 <= topp <= 1):
|
|
248
|
+
raise InvalidParameterError("The 'topp' must be between 0 and 1.")
|
|
249
|
+
if random_seed:
|
|
250
|
+
if not (0 <= random_seed <= 2**32):
|
|
251
|
+
raise InvalidParameterError("The 'random_seed' must be between 0 and 1.")
|
|
252
|
+
|
|
253
|
+
if random_seed is None:
|
|
254
|
+
random_seed = random.randrange(2**32)
|
|
255
|
+
|
|
256
|
+
params = {
|
|
257
|
+
"prompt_id": prompt_id,
|
|
258
|
+
"generate_n": num_samples,
|
|
259
|
+
"temperature": temperature,
|
|
260
|
+
"maxlen": max_length,
|
|
261
|
+
"seed": random_seed,
|
|
262
|
+
}
|
|
263
|
+
if topk is not None:
|
|
264
|
+
params["topk"] = topk
|
|
265
|
+
if topp is not None:
|
|
266
|
+
params["topp"] = topp
|
|
267
|
+
|
|
268
|
+
try:
|
|
269
|
+
response = session.post(endpoint, params=params)
|
|
270
|
+
return PoetGenerateJob.model_validate(response.json())
|
|
271
|
+
except Exception as exc:
|
|
272
|
+
raise APIError(f"Failed to post PoET generation request: {exc}") from exc
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def poet_generate_get(session: APISession, job_id) -> requests.Response:
|
|
276
|
+
"""
|
|
277
|
+
Get the results of a PoET generation job.
|
|
278
|
+
|
|
279
|
+
Parameters
|
|
280
|
+
----------
|
|
281
|
+
session : APISession
|
|
282
|
+
An instance of APISession for API interactions.
|
|
283
|
+
job_id : str
|
|
284
|
+
Job ID from a poet/generate job.
|
|
285
|
+
|
|
286
|
+
Raises
|
|
287
|
+
------
|
|
288
|
+
APIError
|
|
289
|
+
If there is an issue with the API request.
|
|
290
|
+
|
|
291
|
+
Returns
|
|
292
|
+
-------
|
|
293
|
+
requests.Response
|
|
294
|
+
The response object containing the results of the PoET generation job.
|
|
295
|
+
"""
|
|
296
|
+
endpoint = "v1/poet/generate"
|
|
297
|
+
|
|
298
|
+
params = {"job_id": job_id}
|
|
299
|
+
|
|
300
|
+
try:
|
|
301
|
+
response = session.get(endpoint, params=params, stream=True)
|
|
302
|
+
return response
|
|
303
|
+
except Exception as exc:
|
|
304
|
+
raise APIError(f"Failed to get poet generation results: {exc}") from exc
|