@genkit-ai/ai
Version:
Genkit AI framework generative AI APIs.
706 lines (702 loc) • 26.7 kB
TypeScript
import { z, Action } from '@genkit-ai/core';
import { Registry } from '@genkit-ai/core/registry';
import { D as Document, f as EmbedderInfo, b as DocumentData } from './document-DpghhKCM.js';
export { a as DocumentDataSchema, M as MediaPart, P as Part, k as TextPart } from './document-DpghhKCM.js';
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Retriever implementation function signature.
*/
type RetrieverFn<RetrieverOptions extends z.ZodTypeAny> = (query: Document, queryOpts: z.infer<RetrieverOptions>) => Promise<RetrieverResponse>;
/**
* Indexer implementation function signature.
*/
type IndexerFn<IndexerOptions extends z.ZodTypeAny> = (docs: Array<Document>, indexerOpts: z.infer<IndexerOptions>) => Promise<void>;
declare const RetrieverRequestSchema: z.ZodObject<{
query: z.ZodObject<{
content: z.ZodArray<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
media: z.ZodObject<{
contentType: z.ZodOptional<z.ZodString>;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
contentType?: string | undefined;
}, {
url: string;
contentType?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>, "many">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}>;
options: z.ZodOptional<z.ZodAny>;
}, "strip", z.ZodTypeAny, {
query: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
};
options?: any;
}, {
query: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
};
options?: any;
}>;
declare const RetrieverResponseSchema: z.ZodObject<{
documents: z.ZodArray<z.ZodObject<{
content: z.ZodArray<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
media: z.ZodObject<{
contentType: z.ZodOptional<z.ZodString>;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
contentType?: string | undefined;
}, {
url: string;
contentType?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>, "many">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}>, "many">;
}, "strip", z.ZodTypeAny, {
documents: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}[];
}, {
documents: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}[];
}>;
type RetrieverResponse = z.infer<typeof RetrieverResponseSchema>;
declare const IndexerRequestSchema: z.ZodObject<{
documents: z.ZodArray<z.ZodObject<{
content: z.ZodArray<z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
text: z.ZodString;
}>, "strip", z.ZodTypeAny, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>, z.ZodObject<z.objectUtil.extendShape<{
text: z.ZodOptional<z.ZodNever>;
media: z.ZodOptional<z.ZodNever>;
toolRequest: z.ZodOptional<z.ZodNever>;
toolResponse: z.ZodOptional<z.ZodNever>;
data: z.ZodOptional<z.ZodUnknown>;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
custom: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, {
media: z.ZodObject<{
contentType: z.ZodOptional<z.ZodString>;
url: z.ZodString;
}, "strip", z.ZodTypeAny, {
url: string;
contentType?: string | undefined;
}, {
url: string;
contentType?: string | undefined;
}>;
}>, "strip", z.ZodTypeAny, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}, {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
}>]>, "many">;
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
}, "strip", z.ZodTypeAny, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}, {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}>, "many">;
options: z.ZodOptional<z.ZodAny>;
}, "strip", z.ZodTypeAny, {
documents: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}[];
options?: any;
}, {
documents: {
content: ({
text: string;
custom?: Record<string, unknown> | undefined;
media?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
} | {
media: {
url: string;
contentType?: string | undefined;
};
custom?: Record<string, unknown> | undefined;
text?: undefined;
toolRequest?: undefined;
toolResponse?: undefined;
data?: unknown;
metadata?: Record<string, unknown> | undefined;
})[];
metadata?: Record<string, any> | undefined;
}[];
options?: any;
}>;
/**
* Zod schema of retriever info metadata.
*/
declare const RetrieverInfoSchema: z.ZodObject<{
label: z.ZodOptional<z.ZodString>;
/** Supported model capabilities. */
supports: z.ZodOptional<z.ZodObject<{
/** Model can process media as part of the prompt (multimodal input). */
media: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
media?: boolean | undefined;
}, {
media?: boolean | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
label?: string | undefined;
supports?: {
media?: boolean | undefined;
} | undefined;
}, {
label?: string | undefined;
supports?: {
media?: boolean | undefined;
} | undefined;
}>;
type RetrieverInfo = z.infer<typeof RetrieverInfoSchema>;
/**
* A retriever action type.
*/
type RetrieverAction<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny> = Action<typeof RetrieverRequestSchema, typeof RetrieverResponseSchema> & {
__configSchema?: CustomOptions;
};
/**
* An indexer action type.
*/
type IndexerAction<IndexerOptions extends z.ZodTypeAny = z.ZodTypeAny> = Action<typeof IndexerRequestSchema, z.ZodVoid> & {
__configSchema?: IndexerOptions;
};
/**
* Creates a retriever action for the provided {@link RetrieverFn} implementation.
*/
declare function defineRetriever<OptionsType extends z.ZodTypeAny = z.ZodTypeAny>(registry: Registry, options: {
name: string;
configSchema?: OptionsType;
info?: RetrieverInfo;
}, runner: RetrieverFn<OptionsType>): RetrieverAction<OptionsType>;
/**
* Creates an indexer action for the provided {@link IndexerFn} implementation.
*/
declare function defineIndexer<IndexerOptions extends z.ZodTypeAny>(registry: Registry, options: {
name: string;
embedderInfo?: EmbedderInfo;
configSchema?: IndexerOptions;
}, runner: IndexerFn<IndexerOptions>): IndexerAction<IndexerOptions>;
interface RetrieverParams<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny> {
retriever: RetrieverArgument<CustomOptions>;
query: string | DocumentData;
options?: z.infer<CustomOptions>;
}
/**
* A type that can be used to pass a retriever as an argument, either using a reference or an action.
*/
type RetrieverArgument<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny> = RetrieverAction<CustomOptions> | RetrieverReference<CustomOptions> | string;
/**
* Retrieves documents from a {@link RetrieverArgument} based on the provided query.
*/
declare function retrieve<CustomOptions extends z.ZodTypeAny>(registry: Registry, params: RetrieverParams<CustomOptions>): Promise<Array<Document>>;
/**
* A type that can be used to pass an indexer as an argument, either using a reference or an action.
*/
type IndexerArgument<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny> = IndexerReference<CustomOptions> | IndexerAction<CustomOptions> | string;
/**
* Options passed to the index function.
*/
interface IndexerParams<CustomOptions extends z.ZodTypeAny = z.ZodTypeAny> {
indexer: IndexerArgument<CustomOptions>;
documents: Array<DocumentData>;
options?: z.infer<CustomOptions>;
}
/**
* Indexes documents using a {@link IndexerArgument}.
*/
declare function index<CustomOptions extends z.ZodTypeAny>(registry: Registry, params: IndexerParams<CustomOptions>): Promise<void>;
/**
* Zod schema of common retriever options.
*/
declare const CommonRetrieverOptionsSchema: z.ZodObject<{
k: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
k?: number | undefined;
}, {
k?: number | undefined;
}>;
/**
* A retriver reference object.
*/
interface RetrieverReference<CustomOptions extends z.ZodTypeAny> {
name: string;
configSchema?: CustomOptions;
info?: RetrieverInfo;
}
/**
* Helper method to configure a {@link RetrieverReference} to a plugin.
*/
declare function retrieverRef<CustomOptionsSchema extends z.ZodTypeAny = z.ZodTypeAny>(options: RetrieverReference<CustomOptionsSchema>): RetrieverReference<CustomOptionsSchema>;
declare const IndexerInfoSchema: z.ZodObject<{
label: z.ZodOptional<z.ZodString>;
/** Supported model capabilities. */
supports: z.ZodOptional<z.ZodObject<{
/** Model can process media as part of the prompt (multimodal input). */
media: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
media?: boolean | undefined;
}, {
media?: boolean | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
label?: string | undefined;
supports?: {
media?: boolean | undefined;
} | undefined;
}, {
label?: string | undefined;
supports?: {
media?: boolean | undefined;
} | undefined;
}>;
/**
* Indexer metadata.
*/
type IndexerInfo = z.infer<typeof IndexerInfoSchema>;
interface IndexerReference<CustomOptions extends z.ZodTypeAny> {
name: string;
configSchema?: CustomOptions;
info?: IndexerInfo;
}
/**
* Helper method to configure a {@link IndexerReference} to a plugin.
*/
declare function indexerRef<CustomOptionsSchema extends z.ZodTypeAny = z.ZodTypeAny>(options: IndexerReference<CustomOptionsSchema>): IndexerReference<CustomOptionsSchema>;
/**
* Simple retriever options.
*/
interface SimpleRetrieverOptions<C extends z.ZodTypeAny = z.ZodTypeAny, R = any> {
/** The name of the retriever you're creating. */
name: string;
/** A Zod schema containing any configuration info available beyond the query. */
configSchema?: C;
/**
* Specifies how to extract content from the returned items.
*
* - If a string, specifies the key of the returned item to extract as content.
* - If a function, allows you to extract content as text or a document part.
**/
content?: string | ((item: R) => Document['content'] | string);
/**
* Specifies how to extract metadata from the returned items.
*
* - If an array of strings, specifies list of keys to extract from returned objects.
* - If a function, allows you to use custom behavior to extract metadata from returned items.
*/
metadata?: string[] | ((item: R) => Document['metadata']);
}
/**
* defineSimpleRetriever makes it easy to map existing data into documents that
* can be used for prompt augmentation.
*
* @param options Configuration options for the retriever.
* @param handler A function that queries a datastore and returns items from which to extract documents.
* @returns A Genkit retriever.
*/
declare function defineSimpleRetriever<C extends z.ZodTypeAny = z.ZodTypeAny, R = any>(registry: Registry, options: SimpleRetrieverOptions<C, R>, handler: (query: Document, config: z.infer<C>) => Promise<R[]>): RetrieverAction<C>;
export { CommonRetrieverOptionsSchema, Document, DocumentData, type IndexerAction, type IndexerArgument, type IndexerFn, type IndexerInfo, IndexerInfoSchema, type IndexerParams, type IndexerReference, type RetrieverAction, type RetrieverArgument, type RetrieverFn, type RetrieverInfo, RetrieverInfoSchema, type RetrieverParams, type RetrieverReference, type SimpleRetrieverOptions, defineIndexer, defineRetriever, defineSimpleRetriever, index, indexerRef, retrieve, retrieverRef };