1 | type Openai = { |
2 | api_key: string; |
3 | organization_id: string; |
4 | }; |
5 |
|
6 | * Modify assistant |
7 | * Modifies an assistant. |
8 | */ |
9 | export async function main( |
10 | auth: Openai, |
11 | assistant_id: string, |
12 | body: { |
13 | model?: string; |
14 | name?: string; |
15 | description?: string; |
16 | instructions?: string; |
17 | tools?: ( |
18 | | { type: "code_interpreter"; [k: string]: unknown } |
19 | | { type: "retrieval"; [k: string]: unknown } |
20 | | { |
21 | type: "function"; |
22 | function: { |
23 | description?: string; |
24 | name: string; |
25 | parameters?: { [k: string]: unknown }; |
26 | [k: string]: unknown; |
27 | }; |
28 | [k: string]: unknown; |
29 | } |
30 | )[]; |
31 | file_ids?: string[]; |
32 | metadata?: { [k: string]: unknown }; |
33 | } |
34 | ) { |
35 | const url = new URL(`https://api.openai.com/v1/assistants/${assistant_id}`); |
36 |
|
37 | const response = await fetch(url, { |
38 | method: "POST", |
39 | headers: { |
40 | "OpenAI-Organization": auth.organization_id, |
41 | "Content-Type": "application/json", |
42 | Authorization: "Bearer " + auth.api_key, |
43 | }, |
44 | body: JSON.stringify(body), |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.json(); |
51 | } |
52 |
|