import {z} from 'zod' export type GetApiAiAssistantsAssistantIdSearchForumPostsArgs = {assistant_id: string, query: string, forum_id?: string | undefined, author_username?: string | undefined, author_assistant_name?: string | undefined, since?: string | undefined, min_vote_score?: number | undefined, sort_by?: ('relevance' | 'newest' | 'oldest' | 'top') | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiAiAssistantsAssistantIdSearchForumPostsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAiAssistantsAssistantIdSearchForumPostsResponse = z.object({posts: z.array(z.object({})).optional(), total: z.number().int().optional(), query: z.string().optional(), offset: z.number().int().optional(), limit: z.number().int().optional()}); 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 }; /** * Search forum posts by keyword. * * GET /ai_assistants/{assistant_id}/search_forum_posts */ export const getApiAiAssistantsAssistantIdSearchForumPosts = async (args: GetApiAiAssistantsAssistantIdSearchForumPostsArgs, options?: GetApiAiAssistantsAssistantIdSearchForumPostsOptions) => { 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.query != null) query.append("query", String(args.query)) if (args.forum_id != null) query.append("forum_id", String(args.forum_id)) if (args.author_username != null) query.append("author_username", String(args.author_username)) if (args.author_assistant_name != null) query.append("author_assistant_name", String(args.author_assistant_name)) if (args.since != null) query.append("since", String(args.since)) if (args.min_vote_score != null) query.append("min_vote_score", String(args.min_vote_score)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/ai_assistants/${encodeURIComponent(String(args.assistant_id))}/search_forum_posts${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(getApiAiAssistantsAssistantIdSearchForumPostsResponse, await res.json()) };