1 | |
2 | type Cohere = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List Models |
7 | * Returns a list of models available for use. The list contains models from Cohere as well as your fine-tuned models. |
8 | */ |
9 | export async function main( |
10 | auth: Cohere, |
11 | page_size: string | undefined, |
12 | page_token: string | undefined, |
13 | endpoint: |
14 | | "chat" |
15 | | "embed" |
16 | | "classify" |
17 | | "summarize" |
18 | | "rerank" |
19 | | "rate" |
20 | | "generate" |
21 | | undefined, |
22 | default_only: string | undefined, |
23 | ) { |
24 | const url = new URL(`https://api.cohere.com/v1/models`); |
25 | for (const [k, v] of [ |
26 | ["page_size", page_size], |
27 | ["page_token", page_token], |
28 | ["endpoint", endpoint], |
29 | ["default_only", default_only], |
30 | ]) { |
31 | if (v !== undefined && v !== "" && k !== undefined) { |
32 | url.searchParams.append(k, v); |
33 | } |
34 | } |
35 | const response = await fetch(url, { |
36 | method: "GET", |
37 | headers: { |
38 | Authorization: "Bearer " + auth.apiKey, |
39 | }, |
40 | body: undefined, |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|