0
Modify Assistant
One script reply has been approved by the moderators Verified
Created by hugo697 32 days ago Viewed 2782 times
0
Submitted by hugo697 Bun
Verified 32 days ago
1
//native
2
type Ai21 = {
3
  apiKey: string;
4
};
5
/**
6
 * Modify Assistant
7
 *
8
 */
9
export async function main(
10
  auth: Ai21,
11
  assistant_id: string,
12
  body: {
13
    name?: string;
14
    description?: string;
15
    optimization?: "cost" | "latency";
16
    avatar?: string;
17
    is_archived?: false | true;
18
    models?: string[];
19
    tools?: "file_search" | "web_search" | "plan_approval"[];
20
    tool_resources?: { file_search?: {}; web_search?: {}; plan_approval?: {} };
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.ai21.com/studio/v1/assistants/${assistant_id}`,
25
  );
26

27
  const response = await fetch(url, {
28
    method: "PATCH",
29
    headers: {
30
      "Content-Type": "application/json",
31
      Authorization: "Bearer " + auth.apiKey,
32
    },
33
    body: JSON.stringify(body),
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41