import {z} from 'zod' export type GetApiQuestionAnswerFeedbacksArgs = {offset?: number | undefined, limit?: number | undefined, collection_id?: string | undefined, interval?: string | undefined, no_collection?: boolean | undefined}; export type GetApiQuestionAnswerFeedbacksOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const qAFeedback = z.object({question_content: z.string(), reply_content: z.string(), question_id: z.string(), reply_id: z.string(), llm: z.string().optional(), system_prompt: z.string().optional(), pre_prompt_query: z.string().optional(), prompt_query: z.string().optional(), pre_prompt_summary: z.string().optional(), prompt_summary: z.string().optional(), rag_config: z.string().optional(), collection_documents: z.array(z.string()).optional(), votes: z.number().int(), expected_answer: z.string().optional(), user_comment: z.string().optional(), collection_id: z.string().optional(), collection_name: z.string().optional(), response_created_at_time: z.string(), prompt_template_id: z.string().optional(), include_chat_history: z.string().optional(), chat_session_id: z.string().optional(), voted_user_id: z.string().optional(), voted_username: z.string().optional()}); export const getApiQuestionAnswerFeedbacksResponse = z.array(qAFeedback); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Lists user's questions and answers that have a feedback. * * GET /question_answer_feedbacks */ export const getApiQuestionAnswerFeedbacks = async (args: GetApiQuestionAnswerFeedbacksArgs, options?: GetApiQuestionAnswerFeedbacksOptions) => { const {baseUrl = "https://h2ogpte.genai.h2o.ai/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.collection_id != null) query.append("collection_id", String(args.collection_id)) if (args.interval != null) query.append("interval", String(args.interval)) if (args.no_collection != null) query.append("no_collection", String(args.no_collection)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/question_answer_feedbacks${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiQuestionAnswerFeedbacksResponse, await res.json()) };