//native
type Gitbook = {
token: string;
};
/**
* Ask a question in an organization
* Ask a question to an AI across spaces that is accessible by the currently authenticated target.
*/
export async function main(
auth: Gitbook,
organizationId: string,
format: "document" | "markdown" | undefined,
details: string | undefined,
body: { query: string; previousQueries?: string[] },
) {
const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/ask`);
for (const [k, v] of [
["format", format],
["details", details],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
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 235 days ago