//native
type Ai21 = {
apiKey: string;
};
/**
* Get Organization Files
* Get metadata about a specific file by file ID. The file ID is generated by
AI21 when you upload the file.
*/
export async function main(
auth: Ai21,
name: string | undefined,
path: string | undefined,
status:
| "DB_RECORD_CREATED"
| "UPLOADED"
| "UPLOAD_FAILED"
| "PROCESSED"
| "PROCESSING_FAILED"
| undefined,
label: string | undefined,
limit: string | undefined,
offset: string | undefined,
) {
const url = new URL(`https://api.ai21.com/studio/v1/library/files`);
for (const [k, v] of [
["name", name],
["path", path],
["status", status],
["label", label],
["limit", limit],
["offset", offset],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 32 days ago