type Openai = {
api_key: string;
organization_id: string;
};
/**
* List message files
* Returns a list of message files.
*/
export async function main(
auth: Openai,
thread_id: string,
message_id: string,
limit: string | undefined,
order: "asc" | "desc" | undefined,
after: string | undefined,
before: string | undefined
) {
const url = new URL(
`https://api.openai.com/v1/threads/${thread_id}/messages/${message_id}/files`
);
for (const [k, v] of [
["limit", limit],
["order", order],
["after", after],
["before", before],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"OpenAI-Organization": auth.organization_id,
Authorization: "Bearer " + auth.api_key,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 282 days ago