Modify thread

Modifies a thread.

Script openai Verified

by hugo697 ยท 12/1/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 372 days ago
1
type Openai = {
2
  api_key: string;
3
  organization_id: string;
4
};
5
/**
6
 * Modify thread
7
 * Modifies a thread.
8
 */
9
export async function main(
10
  auth: Openai,
11
  thread_id: string,
12
  body: { metadata?: { [k: string]: unknown } }
13
) {
14
  const url = new URL(`https://api.openai.com/v1/threads/${thread_id}`);
15

16
  const response = await fetch(url, {
17
    method: "POST",
18
    headers: {
19
      "OpenAI-Organization": auth.organization_id,
20
      "Content-Type": "application/json",
21
      Authorization: "Bearer " + auth.api_key,
22
    },
23
    body: JSON.stringify(body),
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31