type Openai = {
api_key: string;
organization_id: string;
};
/**
* Create assistant file
* Create an assistant file by attaching a File to an assistant.
*/
export async function main(
auth: Openai,
assistant_id: string,
body: { file_id: string }
) {
const url = new URL(
`https://api.openai.com/v1/assistants/${assistant_id}/files`
);
const response = await fetch(url, {
method: "POST",
headers: {
"OpenAI-Organization": auth.organization_id,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 170 days ago