import {z} from 'zod' export type LibsPythonSchemasLogRecordsFeedbackLikeDislikeRating = {feedback_type?: 'like_dislike' | undefined, value: boolean}; export type LibsPythonSchemasLogRecordsFeedbackStarRating = {feedback_type?: 'star' | undefined, value: number}; export type LibsPythonSchemasLogRecordsFeedbackScoreRating = {feedback_type?: 'score' | undefined, value: number}; export type LibsPythonSchemasLogRecordsFeedbackTagsRating = {feedback_type?: 'tags' | undefined, value: Array}; export type LibsPythonSchemasLogRecordsFeedbackTextRating = {feedback_type?: 'text' | undefined, value: string}; export type LibsPythonSchemasLogRecordsFeedbackChoiceRating = {feedback_type?: 'choice' | undefined, value: string}; export type LibsPythonSchemasLogRecordsFeedbackTreeChoiceRating = {feedback_type?: 'tree_choice' | undefined, value: string}; export type BulkFeedbackRatingCreate = {explanation?: (string | null) | undefined, rating: LibsPythonSchemasLogRecordsFeedbackLikeDislikeRating | LibsPythonSchemasLogRecordsFeedbackStarRating | LibsPythonSchemasLogRecordsFeedbackScoreRating | LibsPythonSchemasLogRecordsFeedbackTagsRating | LibsPythonSchemasLogRecordsFeedbackTextRating | LibsPythonSchemasLogRecordsFeedbackChoiceRating | LibsPythonSchemasLogRecordsFeedbackTreeChoiceRating, feedback_template_id: unknown, operation_type?: 'create' | undefined}; export type BulkFeedbackRatingDelete = {feedback_template_id: unknown, operation_type?: 'delete' | undefined}; export type IndexSelector = {selector_type?: 'indexes' | undefined, indexes: Array}; export type TraceSelector = {selector_type?: 'traces' | undefined, traces: Array}; export type BulkFeedbackRequest = {operations: Array, selector: IndexSelector | TraceSelector}; export type CreateApiPublicV2ProjectsProjectIdFeedbackRatingsArgs = {project_id: unknown, body: BulkFeedbackRequest}; export type CreateApiPublicV2ProjectsProjectIdFeedbackRatingsOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const selectorType = z.enum(["indexes", "traces"]); export const feedbackRatingOperationType = z.enum(["create", "delete"]); export const bulkFeedbackRatingStatus = z.object({selector: selectorType.optional(), index: z.number().int().nullable().optional(), trace: z.string().nullable().optional(), operation: feedbackRatingOperationType, success: z.boolean(), message: z.string().nullable()}); export const createApiPublicV2ProjectsProjectIdFeedbackRatingsResponse = z.array(bulkFeedbackRatingStatus); 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 }; /** * Apply Bulk Feedback V2 * * POST /public/v2/projects/{project_id}/feedback/ratings * * Also accepts auth: ClassicAPIKeyHeader, OAuth2PasswordBearer, HTTPBasic */ export const createApiPublicV2ProjectsProjectIdFeedbackRatings = async (args: CreateApiPublicV2ProjectsProjectIdFeedbackRatingsArgs, options?: CreateApiPublicV2ProjectsProjectIdFeedbackRatingsOptions) => { const {baseUrl = "https://api.galileo.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("Splunk-AO-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/public/v2/projects/${encodeURIComponent(String(args.project_id))}/feedback/ratings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiPublicV2ProjectsProjectIdFeedbackRatingsResponse, await res.json()) };