export type CreateApiPredArgs = {body: BodyInit}; export type CreateApiPredOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Enter the text and get its Hate Speech probability (0-1) across various categories * * POST /pred */ export const createApiPred = async (args: CreateApiPredArgs, options: CreateApiPredOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const url = `${baseUrl.replace(/\/+$/, '')}/pred${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };