forked from replicate/replicate-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.js
More file actions
97 lines (86 loc) · 3.45 KB
/
models.js
File metadata and controls
97 lines (86 loc) · 3.45 KB
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
/**
* Get information about a model
*
* @param {string} model_owner - Required. The name of the user or organization that owns the model
* @param {string} model_name - Required. The name of the model
* @returns {Promise<object>} Resolves with the model data
*/
async function getModel(model_owner, model_name) {
const response = await this.request(`/models/${model_owner}/${model_name}`, {
method: "GET",
});
return response.json();
}
/**
* List model versions
*
* @param {string} model_owner - Required. The name of the user or organization that owns the model
* @param {string} model_name - Required. The name of the model
* @returns {Promise<object>} Resolves with the list of model versions
*/
async function listModelVersions(model_owner, model_name) {
const response = await this.request(
`/models/${model_owner}/${model_name}/versions`,
{
method: "GET",
}
);
return response.json();
}
/**
* Get a specific model version
*
* @param {string} model_owner - Required. The name of the user or organization that owns the model
* @param {string} model_name - Required. The name of the model
* @param {string} version_id - Required. The model version
* @returns {Promise<object>} Resolves with the model version data
*/
async function getModelVersion(model_owner, model_name, version_id) {
const response = await this.request(
`/models/${model_owner}/${model_name}/versions/${version_id}`,
{
method: "GET",
}
);
return response.json();
}
/**
* List all public models
*
* @returns {Promise<object>} Resolves with the model version data
*/
async function listModels() {
const response = await this.request("/models", {
method: "GET",
});
return response.json();
}
/**
* Create a new model
*
* @param {string} model_owner - Required. The name of the user or organization that will own the model. This must be the same as the user or organization that is making the API request. In other words, the API token used in the request must belong to this user or organization.
* @param {string} model_name - Required. The name of the model. This must be unique among all models owned by the user or organization.
* @param {object} options
* @param {("public"|"private")} options.visibility - Required. Whether the model should be public or private. A public model can be viewed and run by anyone, whereas a private model can be viewed and run only by the user or organization members that own the model.
* @param {string} options.hardware - Required. The SKU for the hardware used to run the model. Possible values can be found by calling `Replicate.hardware.list()`.
* @param {string} options.description - A description of the model.
* @param {string} options.github_url - A URL for the model's source code on GitHub.
* @param {string} options.paper_url - A URL for the model's paper.
* @param {string} options.license_url - A URL for the model's license.
* @param {string} options.cover_image_url - A URL for the model's cover image. This should be an image file.
* @returns {Promise<object>} Resolves with the model version data
*/
async function createModel(model_owner, model_name, options) {
const data = { owner: model_owner, name: model_name, ...options };
const response = await this.request("/models", {
method: "POST",
data,
});
return response.json();
}
module.exports = {
get: getModel,
list: listModels,
create: createModel,
versions: { list: listModelVersions, get: getModelVersion },
};