@ohos-ports/genkit 1.42.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +203 -0
- package/README.md +434 -0
- package/lib/beta.d.mts +18 -0
- package/lib/beta.d.ts +18 -0
- package/lib/beta.js +88 -0
- package/lib/beta.js.map +1 -0
- package/lib/beta.mjs +64 -0
- package/lib/beta.mjs.map +1 -0
- package/lib/client/agent.d.mts +52 -0
- package/lib/client/agent.d.ts +52 -0
- package/lib/client/agent.js +90 -0
- package/lib/client/agent.js.map +1 -0
- package/lib/client/agent.mjs +68 -0
- package/lib/client/agent.mjs.map +1 -0
- package/lib/client/client.d.mts +80 -0
- package/lib/client/client.d.ts +80 -0
- package/lib/client/client.js +164 -0
- package/lib/client/client.js.map +1 -0
- package/lib/client/client.mjs +139 -0
- package/lib/client/client.mjs.map +1 -0
- package/lib/client/index.d.mts +6 -0
- package/lib/client/index.d.ts +6 -0
- package/lib/client/index.js +55 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/index.mjs +31 -0
- package/lib/client/index.mjs.map +1 -0
- package/lib/client/types.d.mts +17 -0
- package/lib/client/types.d.ts +17 -0
- package/lib/client/types.js +17 -0
- package/lib/client/types.js.map +1 -0
- package/lib/client/types.mjs +1 -0
- package/lib/client/types.mjs.map +1 -0
- package/lib/common.d.mts +3 -0
- package/lib/common.d.ts +3 -0
- package/lib/common.js +151 -0
- package/lib/common.js.map +1 -0
- package/lib/common.mjs +128 -0
- package/lib/common.mjs.map +1 -0
- package/lib/context.d.mts +1 -0
- package/lib/context.d.ts +1 -0
- package/lib/context.js +50 -0
- package/lib/context.js.map +1 -0
- package/lib/context.mjs +28 -0
- package/lib/context.mjs.map +1 -0
- package/lib/embedder.d.mts +1 -0
- package/lib/embedder.d.ts +1 -0
- package/lib/embedder.js +48 -0
- package/lib/embedder.js.map +1 -0
- package/lib/embedder.mjs +26 -0
- package/lib/embedder.mjs.map +1 -0
- package/lib/evaluator.d.mts +1 -0
- package/lib/evaluator.d.ts +1 -0
- package/lib/evaluator.js +60 -0
- package/lib/evaluator.js.map +1 -0
- package/lib/evaluator.mjs +38 -0
- package/lib/evaluator.mjs.map +1 -0
- package/lib/extract.d.mts +1 -0
- package/lib/extract.d.ts +1 -0
- package/lib/extract.js +48 -0
- package/lib/extract.js.map +1 -0
- package/lib/extract.mjs +23 -0
- package/lib/extract.mjs.map +1 -0
- package/lib/formats.d.mts +1 -0
- package/lib/formats.d.ts +1 -0
- package/lib/formats.js +34 -0
- package/lib/formats.js.map +1 -0
- package/lib/formats.mjs +18 -0
- package/lib/formats.mjs.map +1 -0
- package/lib/genkit-beta.d.mts +183 -0
- package/lib/genkit-beta.d.ts +183 -0
- package/lib/genkit-beta.js +178 -0
- package/lib/genkit-beta.js.map +1 -0
- package/lib/genkit-beta.mjs +159 -0
- package/lib/genkit-beta.mjs.map +1 -0
- package/lib/genkit.d.mts +10 -0
- package/lib/genkit.d.ts +10 -0
- package/lib/genkit.js +471 -0
- package/lib/genkit.js.map +1 -0
- package/lib/genkit.mjs +489 -0
- package/lib/genkit.mjs.map +1 -0
- package/lib/index-BSkuxdwl.d.mts +311 -0
- package/lib/index-BSkuxdwl.d.ts +311 -0
- package/lib/index.d.mts +10 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +51 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +24 -0
- package/lib/index.mjs.map +1 -0
- package/lib/logging.d.mts +1 -0
- package/lib/logging.d.ts +1 -0
- package/lib/logging.js +46 -0
- package/lib/logging.js.map +1 -0
- package/lib/logging.mjs +22 -0
- package/lib/logging.mjs.map +1 -0
- package/lib/middleware.d.mts +1 -0
- package/lib/middleware.d.ts +1 -0
- package/lib/middleware.js +56 -0
- package/lib/middleware.js.map +1 -0
- package/lib/middleware.mjs +34 -0
- package/lib/middleware.mjs.map +1 -0
- package/lib/model.d.mts +1 -0
- package/lib/model.d.ts +1 -0
- package/lib/model.js +92 -0
- package/lib/model.js.map +1 -0
- package/lib/model.mjs +70 -0
- package/lib/model.mjs.map +1 -0
- package/lib/plugin.d.mts +10 -0
- package/lib/plugin.d.ts +10 -0
- package/lib/plugin.js +143 -0
- package/lib/plugin.js.map +1 -0
- package/lib/plugin.mjs +113 -0
- package/lib/plugin.mjs.map +1 -0
- package/lib/registry.d.mts +1 -0
- package/lib/registry.d.ts +1 -0
- package/lib/registry.js +46 -0
- package/lib/registry.js.map +1 -0
- package/lib/registry.mjs +24 -0
- package/lib/registry.mjs.map +1 -0
- package/lib/reranker.d.mts +1 -0
- package/lib/reranker.d.ts +1 -0
- package/lib/reranker.js +54 -0
- package/lib/reranker.js.map +1 -0
- package/lib/reranker.mjs +32 -0
- package/lib/reranker.mjs.map +1 -0
- package/lib/retriever.d.mts +1 -0
- package/lib/retriever.d.ts +1 -0
- package/lib/retriever.js +58 -0
- package/lib/retriever.js.map +1 -0
- package/lib/retriever.mjs +36 -0
- package/lib/retriever.mjs.map +1 -0
- package/lib/schema.d.mts +1 -0
- package/lib/schema.d.ts +1 -0
- package/lib/schema.js +54 -0
- package/lib/schema.js.map +1 -0
- package/lib/schema.mjs +32 -0
- package/lib/schema.mjs.map +1 -0
- package/lib/testing.d.mts +1 -0
- package/lib/testing.d.ts +1 -0
- package/lib/testing.js +50 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.mjs +28 -0
- package/lib/testing.mjs.map +1 -0
- package/lib/tool.d.mts +1 -0
- package/lib/tool.d.ts +1 -0
- package/lib/tool.js +54 -0
- package/lib/tool.js.map +1 -0
- package/lib/tool.mjs +32 -0
- package/lib/tool.mjs.map +1 -0
- package/lib/tracing.d.mts +1 -0
- package/lib/tracing.d.ts +1 -0
- package/lib/tracing.js +82 -0
- package/lib/tracing.js.map +1 -0
- package/lib/tracing.mjs +60 -0
- package/lib/tracing.mjs.map +1 -0
- package/package.json +233 -0
- package/src/beta.ts +85 -0
- package/src/client/agent.ts +160 -0
- package/src/client/client.ts +237 -0
- package/src/client/index.ts +72 -0
- package/src/client/types.ts +41 -0
- package/src/common.ts +175 -0
- package/src/context.ts +37 -0
- package/src/embedder.ts +41 -0
- package/src/evaluator.ts +50 -0
- package/src/extract.ts +30 -0
- package/src/formats.ts +30 -0
- package/src/genkit-beta.ts +275 -0
- package/src/genkit.ts +818 -0
- package/src/index.ts +29 -0
- package/src/logging.ts +30 -0
- package/src/middleware.ts +38 -0
- package/src/model.ts +87 -0
- package/src/plugin.ts +172 -0
- package/src/registry.ts +36 -0
- package/src/reranker.ts +42 -0
- package/src/retriever.ts +55 -0
- package/src/schema.ts +40 -0
- package/src/testing.ts +47 -0
- package/src/tool.ts +40 -0
- package/src/tracing.ts +55 -0
- package/tests/agent_client_test.ts +497 -0
- package/tests/embed_test.ts +142 -0
- package/tests/evaluate_test.ts +52 -0
- package/tests/flow_test.ts +94 -0
- package/tests/formats_test.ts +168 -0
- package/tests/generate_test.ts +1631 -0
- package/tests/genkit_test.ts +33 -0
- package/tests/helpers.ts +176 -0
- package/tests/mock-model_test.ts +490 -0
- package/tests/plugins_test.ts +259 -0
- package/tests/prompts/badSchemaRef.prompt +9 -0
- package/tests/prompts/chat_preamble.prompt +5 -0
- package/tests/prompts/kitchensink.prompt +25 -0
- package/tests/prompts/output.prompt +11 -0
- package/tests/prompts/schemaRef.prompt +9 -0
- package/tests/prompts/sub/test.prompt +5 -0
- package/tests/prompts/test.prompt +5 -0
- package/tests/prompts/test.variant.prompt +8 -0
- package/tests/prompts/toolPrompt.prompt +6 -0
- package/tests/prompts_test.ts +1442 -0
- package/tests/session_test.ts +17 -0
- package/typedoc.json +22 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2025 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Main genkit import.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { genkit } from 'genkit';
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module /
|
|
27
|
+
*/
|
|
28
|
+
export * from './common.js';
|
|
29
|
+
export { Genkit, genkit, type GenkitOptions } from './genkit.js';
|
package/src/logging.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Logging utilities — the Genkit {@link logger} singleton for structured log
|
|
21
|
+
* output.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { logger } from 'genkit/logging';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module logging
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export { logger } from '@genkit-ai/core/logging';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Built-in model middleware — `retry`, `fallback`, `augmentWithContext`,
|
|
21
|
+
* `validateSupport`, and other middleware for enhancing model requests.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { retry, fallback } from 'genkit/model/middleware';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module model/middleware
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
augmentWithContext,
|
|
32
|
+
downloadRequestMedia,
|
|
33
|
+
fallback,
|
|
34
|
+
retry,
|
|
35
|
+
simulateSystemPrompt,
|
|
36
|
+
validateSupport,
|
|
37
|
+
type AugmentWithContextOptions,
|
|
38
|
+
} from '@genkit-ai/ai/model/middleware';
|
package/src/model.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Model types and helpers — request/response schemas, message and part types,
|
|
21
|
+
* model references, and middleware interfaces for building model plugins.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { modelRef, type ModelAction, type MessageData } from 'genkit/model';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module model
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
CandidateErrorSchema,
|
|
32
|
+
CandidateSchema,
|
|
33
|
+
CustomPartSchema,
|
|
34
|
+
DataPartSchema,
|
|
35
|
+
GenerateRequestSchema,
|
|
36
|
+
GenerateResponseChunkSchema,
|
|
37
|
+
GenerateResponseSchema,
|
|
38
|
+
GenerationCommonConfigDescriptions,
|
|
39
|
+
GenerationCommonConfigSchema,
|
|
40
|
+
GenerationUsageSchema,
|
|
41
|
+
MediaPartSchema,
|
|
42
|
+
MessageSchema,
|
|
43
|
+
ModelInfoSchema,
|
|
44
|
+
ModelRequestSchema,
|
|
45
|
+
ModelResponseSchema,
|
|
46
|
+
PartSchema,
|
|
47
|
+
RoleSchema,
|
|
48
|
+
TextPartSchema,
|
|
49
|
+
ToolDefinitionSchema,
|
|
50
|
+
ToolRequestPartSchema,
|
|
51
|
+
ToolResponsePartSchema,
|
|
52
|
+
getBasicUsageStats,
|
|
53
|
+
modelRef,
|
|
54
|
+
simulateConstrainedGeneration,
|
|
55
|
+
type BackgroundModelAction,
|
|
56
|
+
type CandidateData,
|
|
57
|
+
type CandidateError,
|
|
58
|
+
type CustomPart,
|
|
59
|
+
type DataPart,
|
|
60
|
+
type DefineBackgroundModelOptions,
|
|
61
|
+
type DefineModelOptions,
|
|
62
|
+
type GenerateRequest,
|
|
63
|
+
type GenerateRequestData,
|
|
64
|
+
type GenerateResponseChunkData,
|
|
65
|
+
type GenerateResponseData,
|
|
66
|
+
type GenerationCommonConfig,
|
|
67
|
+
type GenerationUsage,
|
|
68
|
+
type MediaPart,
|
|
69
|
+
type MessageData,
|
|
70
|
+
type ModelAction,
|
|
71
|
+
type ModelArgument,
|
|
72
|
+
type ModelInfo,
|
|
73
|
+
type ModelMiddleware,
|
|
74
|
+
type ModelMiddlewareArgument,
|
|
75
|
+
type ModelMiddlewareWithOptions,
|
|
76
|
+
type ModelReference,
|
|
77
|
+
type ModelRequest,
|
|
78
|
+
type ModelResponseChunkData,
|
|
79
|
+
type ModelResponseData,
|
|
80
|
+
type OutputConfig,
|
|
81
|
+
type Part,
|
|
82
|
+
type Role,
|
|
83
|
+
type TextPart,
|
|
84
|
+
type ToolDefinition,
|
|
85
|
+
type ToolRequestPart,
|
|
86
|
+
type ToolResponsePart,
|
|
87
|
+
} from '@genkit-ai/ai/model';
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Plugin authoring utilities — factory functions (`model`, `embedder`,
|
|
21
|
+
* `retriever`, etc.), plugin lifecycle types, and the v1/v2 plugin
|
|
22
|
+
* interfaces for building Genkit plugins.
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { model, embedder, genkitPlugin } from 'genkit/plugin';
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @module plugin
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import type { GenerateMiddleware } from '@genkit-ai/ai';
|
|
32
|
+
import { type GenkitPluginV2 } from '@genkit-ai/ai';
|
|
33
|
+
import { type ModelAction } from '@genkit-ai/ai/model';
|
|
34
|
+
import {
|
|
35
|
+
GenkitError,
|
|
36
|
+
type ActionMetadata,
|
|
37
|
+
type ResolvableAction,
|
|
38
|
+
} from '@genkit-ai/core';
|
|
39
|
+
import type { Genkit } from './genkit.js';
|
|
40
|
+
import type { ActionType } from './registry.js';
|
|
41
|
+
|
|
42
|
+
export { embedder, embedderActionMetadata } from '@genkit-ai/ai/embedder';
|
|
43
|
+
export { evaluator } from '@genkit-ai/ai/evaluator';
|
|
44
|
+
export {
|
|
45
|
+
backgroundModel,
|
|
46
|
+
model,
|
|
47
|
+
modelActionMetadata,
|
|
48
|
+
} from '@genkit-ai/ai/model';
|
|
49
|
+
export { reranker } from '@genkit-ai/ai/reranker';
|
|
50
|
+
export { indexer, retriever } from '@genkit-ai/ai/retriever';
|
|
51
|
+
export { type GenerateMiddleware, type GenkitPluginV2, type ResolvableAction };
|
|
52
|
+
|
|
53
|
+
/** A v1 plugin provider returned by a {@link GenkitPlugin} factory function. */
|
|
54
|
+
export interface PluginProvider {
|
|
55
|
+
name: string;
|
|
56
|
+
initializer: () => void | Promise<void>;
|
|
57
|
+
resolver?: (action: ActionType, target: string) => Promise<void>;
|
|
58
|
+
listActions?: () => Promise<ActionMetadata[]>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A v1 Genkit plugin factory function. Returns a {@link PluginProvider} when called with a Genkit instance. */
|
|
62
|
+
export type GenkitPlugin = (genkit: Genkit) => PluginProvider;
|
|
63
|
+
|
|
64
|
+
/** Initialization function called during plugin setup. */
|
|
65
|
+
export type PluginInit = (genkit: Genkit) => void | Promise<void>;
|
|
66
|
+
|
|
67
|
+
/** Optional resolver function for lazily-resolved plugin actions. */
|
|
68
|
+
export type PluginActionResolver = (
|
|
69
|
+
genkit: Genkit,
|
|
70
|
+
action: ActionType,
|
|
71
|
+
target: string
|
|
72
|
+
) => Promise<void>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Defines a Genkit plugin.
|
|
76
|
+
*/
|
|
77
|
+
export function genkitPlugin<T extends PluginInit>(
|
|
78
|
+
pluginName: string,
|
|
79
|
+
initFn: T,
|
|
80
|
+
resolveFn?: PluginActionResolver,
|
|
81
|
+
listActionsFn?: () => Promise<ActionMetadata[]>
|
|
82
|
+
): GenkitPlugin {
|
|
83
|
+
return (genkit: Genkit) => ({
|
|
84
|
+
name: pluginName,
|
|
85
|
+
initializer: async () => {
|
|
86
|
+
await initFn(genkit);
|
|
87
|
+
},
|
|
88
|
+
resolver: async (action: ActionType, target: string): Promise<void> => {
|
|
89
|
+
if (resolveFn) {
|
|
90
|
+
return await resolveFn(genkit, action, target);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
listActions: async (): Promise<ActionMetadata[]> => {
|
|
94
|
+
if (listActionsFn) {
|
|
95
|
+
return await listActionsFn();
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Concrete implementation of a v2 plugin that wraps a {@link GenkitPluginV2} definition
|
|
104
|
+
* and provides default implementations for all optional hooks.
|
|
105
|
+
*/
|
|
106
|
+
export class GenkitPluginV2Instance implements Required<GenkitPluginV2> {
|
|
107
|
+
readonly version = 'v2';
|
|
108
|
+
readonly name: string;
|
|
109
|
+
|
|
110
|
+
private plugin: Omit<GenkitPluginV2, 'version' | 'model'>;
|
|
111
|
+
|
|
112
|
+
constructor(plugin: Omit<GenkitPluginV2, 'version' | 'model'>) {
|
|
113
|
+
this.name = plugin.name;
|
|
114
|
+
this.plugin = plugin;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
init(): ResolvableAction[] | Promise<ResolvableAction[]> {
|
|
118
|
+
if (!this.plugin.init) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
return this.plugin.init();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
list(): ActionMetadata[] | Promise<ActionMetadata[]> {
|
|
125
|
+
if (!this.plugin.list) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
return this.plugin.list();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
middleware(): GenerateMiddleware<any, any>[] {
|
|
132
|
+
if (!this.plugin.middleware) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return this.plugin.middleware();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
resolve(
|
|
139
|
+
actionType: ActionType,
|
|
140
|
+
name: string
|
|
141
|
+
): ResolvableAction | undefined | Promise<ResolvableAction | undefined> {
|
|
142
|
+
if (!this.plugin.resolve) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
return this.plugin.resolve(actionType, name);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async model(name: string): Promise<ModelAction> {
|
|
149
|
+
const model = await this.resolve('model', name);
|
|
150
|
+
if (!model) {
|
|
151
|
+
throw new GenkitError({
|
|
152
|
+
message: `Failed to resolve model ${name} for plugin ${this.name}`,
|
|
153
|
+
status: 'NOT_FOUND',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return model as ModelAction;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new v2 plugin instance from the provided options.
|
|
162
|
+
*/
|
|
163
|
+
export function genkitPluginV2(
|
|
164
|
+
options: Omit<GenkitPluginV2, 'version' | 'model'>
|
|
165
|
+
): GenkitPluginV2Instance {
|
|
166
|
+
return new GenkitPluginV2Instance(options);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Checks whether the given plugin conforms to the v2 plugin interface. */
|
|
170
|
+
export function isPluginV2(plugin: unknown): plugin is GenkitPluginV2 {
|
|
171
|
+
return (plugin as GenkitPluginV2).version === 'v2';
|
|
172
|
+
}
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Action registry internals — `Registry`, `Schema`, and related types used by
|
|
21
|
+
* plugin authors and advanced integrations.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Registry } from 'genkit/registry';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module registry
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
Registry,
|
|
32
|
+
type ActionType,
|
|
33
|
+
type AsyncProvider,
|
|
34
|
+
type HasRegistry,
|
|
35
|
+
type Schema,
|
|
36
|
+
} from '@genkit-ai/core/registry';
|
package/src/reranker.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reranker types — `RankedDocument`, reference helpers, and schemas for
|
|
21
|
+
* building reranker plugins.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { RankedDocument, rerankerRef } from 'genkit/reranker';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module reranker
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
CommonRerankerOptionsSchema,
|
|
32
|
+
RankedDocument,
|
|
33
|
+
RankedDocumentDataSchema,
|
|
34
|
+
RerankerInfoSchema,
|
|
35
|
+
rerankerRef,
|
|
36
|
+
type RankedDocumentData,
|
|
37
|
+
type RerankerAction,
|
|
38
|
+
type RerankerArgument,
|
|
39
|
+
type RerankerInfo,
|
|
40
|
+
type RerankerParams,
|
|
41
|
+
type RerankerReference,
|
|
42
|
+
} from '@genkit-ai/ai/reranker';
|
package/src/retriever.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Retriever and indexer types — `Document`, reference helpers, and schemas for
|
|
21
|
+
* building RAG (retrieval-augmented generation) plugins.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { Document, retrieverRef, indexerRef } from 'genkit/retriever';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module retriever
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
CommonRetrieverOptionsSchema,
|
|
32
|
+
Document,
|
|
33
|
+
DocumentDataSchema,
|
|
34
|
+
IndexerInfoSchema,
|
|
35
|
+
RetrieverInfoSchema,
|
|
36
|
+
indexerRef,
|
|
37
|
+
retrieverRef,
|
|
38
|
+
type DocumentData,
|
|
39
|
+
type IndexerAction,
|
|
40
|
+
type IndexerArgument,
|
|
41
|
+
type IndexerFn,
|
|
42
|
+
type IndexerInfo,
|
|
43
|
+
type IndexerParams,
|
|
44
|
+
type IndexerReference,
|
|
45
|
+
type MediaPart,
|
|
46
|
+
type Part,
|
|
47
|
+
type RetrieverAction,
|
|
48
|
+
type RetrieverArgument,
|
|
49
|
+
type RetrieverFn,
|
|
50
|
+
type RetrieverInfo,
|
|
51
|
+
type RetrieverParams,
|
|
52
|
+
type RetrieverReference,
|
|
53
|
+
type SimpleRetrieverOptions,
|
|
54
|
+
type TextPart,
|
|
55
|
+
} from '@genkit-ai/ai/retriever';
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Schema utilities — JSON Schema conversion, validation helpers, and related
|
|
21
|
+
* types for working with Zod schemas in Genkit.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { toJsonSchema, parseSchema, ValidationError } from 'genkit/schema';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module schema
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
ValidationError,
|
|
32
|
+
annotateSchema,
|
|
33
|
+
parseSchema,
|
|
34
|
+
toJsonSchema,
|
|
35
|
+
validateSchema,
|
|
36
|
+
type JSONSchema,
|
|
37
|
+
type ProvidedSchema,
|
|
38
|
+
type ValidationErrorDetail,
|
|
39
|
+
type ValidationResponse,
|
|
40
|
+
} from '@genkit-ai/core/schema';
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Testing utilities for Genkit apps and model plugins.
|
|
21
|
+
*
|
|
22
|
+
* - {@link mockModel} — a programmable mock model with typed call inspection,
|
|
23
|
+
* for testing flows, prompts, and tools deterministically.
|
|
24
|
+
* - {@link echoModel} — a zero-config model that echoes the rendered request,
|
|
25
|
+
* for asserting prompt/message assembly.
|
|
26
|
+
* - `testModels` — a conformance harness for model *plugin* authors.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { mockModel, echoModel, testModels } from 'genkit/testing';
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module testing
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
echoModel,
|
|
37
|
+
mockModel,
|
|
38
|
+
testModels,
|
|
39
|
+
type EchoModelOptions,
|
|
40
|
+
type MockChunk,
|
|
41
|
+
type MockContext,
|
|
42
|
+
type MockModel,
|
|
43
|
+
type MockModelOptions,
|
|
44
|
+
type MockRespond,
|
|
45
|
+
type MockRespondFn,
|
|
46
|
+
type MockResponse,
|
|
47
|
+
} from '@genkit-ai/ai/testing';
|
package/src/tool.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Tool types — action types, configuration, and helpers for defining tools
|
|
21
|
+
* that models can call (function calling).
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { type ToolAction, type ToolConfig } from 'genkit/tool';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module tool
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
asTool,
|
|
32
|
+
dynamicTool,
|
|
33
|
+
interrupt,
|
|
34
|
+
toToolDefinition,
|
|
35
|
+
tool,
|
|
36
|
+
type MultipartToolAction,
|
|
37
|
+
type ToolAction,
|
|
38
|
+
type ToolArgument,
|
|
39
|
+
type ToolConfig,
|
|
40
|
+
} from '@genkit-ai/ai/tool';
|
package/src/tracing.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2024 Google LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Tracing and telemetry — span/trace schemas, custom metadata helpers, and
|
|
21
|
+
* OpenTelemetry integration utilities.
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { runInNewSpan, setCustomMetadataAttributes } from 'genkit/tracing';
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module tracing
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
SPAN_TYPE_ATTR,
|
|
32
|
+
SpanContextSchema,
|
|
33
|
+
SpanDataSchema,
|
|
34
|
+
SpanMetadataSchema,
|
|
35
|
+
SpanStatusSchema,
|
|
36
|
+
TimeEventSchema,
|
|
37
|
+
TraceDataSchema,
|
|
38
|
+
TraceMetadataSchema,
|
|
39
|
+
TraceServerExporter,
|
|
40
|
+
appendSpan,
|
|
41
|
+
disableGenkitOTelInitialization,
|
|
42
|
+
disableOTelRootSpanDetection,
|
|
43
|
+
enableTelemetry,
|
|
44
|
+
flushTracing,
|
|
45
|
+
runInNewSpan,
|
|
46
|
+
setCustomMetadataAttribute,
|
|
47
|
+
setCustomMetadataAttributes,
|
|
48
|
+
setTelemetryServerUrl,
|
|
49
|
+
toDisplayPath,
|
|
50
|
+
type PathMetadata,
|
|
51
|
+
type SpanData,
|
|
52
|
+
type SpanMetadata,
|
|
53
|
+
type TraceData,
|
|
54
|
+
type TraceMetadata,
|
|
55
|
+
} from '@genkit-ai/core/tracing';
|