@equinor/fusion-framework-cli-plugin-ai-search 1.0.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.
@@ -0,0 +1,7 @@
1
+ import type { Command } from 'commander';
2
+ /**
3
+ * Registers the AI search plugin command with the CLI program
4
+ * @param program - The Commander program instance to register commands with
5
+ */
6
+ export declare function registerAiPlugin(program: Command): void;
7
+ export default registerAiPlugin;
@@ -0,0 +1,105 @@
1
+ import { type Command } from 'commander';
2
+ /**
3
+ * Interface representing the AI-related options available in CLI commands.
4
+ * This interface defines the structure of options that can be passed to AI commands.
5
+ */
6
+ export interface AiOptions {
7
+ /** Azure OpenAI API key for authentication */
8
+ openaiApiKey: string;
9
+ /** Azure OpenAI API version */
10
+ openaiApiVersion: string;
11
+ /** Azure OpenAI instance name */
12
+ openaiInstance: string;
13
+ /** Azure OpenAI chat deployment name (optional) */
14
+ openaiChatDeployment?: string;
15
+ /** Azure OpenAI embedding deployment name (optional) */
16
+ openaiEmbeddingDeployment?: string;
17
+ /** Azure Search endpoint URL (optional) */
18
+ azureSearchEndpoint?: string;
19
+ /** Azure Search API key (optional) */
20
+ azureSearchApiKey?: string;
21
+ /** Azure Search index name (optional) */
22
+ azureSearchIndexName?: string;
23
+ }
24
+ /**
25
+ * Option for specifying the Azure OpenAI API key.
26
+ * Required for authentication with Azure OpenAI services.
27
+ */
28
+ export declare const apiKeyOption: import("commander").Option;
29
+ /**
30
+ * Option for specifying the Azure OpenAI API version.
31
+ * Defaults to the latest stable version if not provided.
32
+ */
33
+ export declare const apiVersionOption: import("commander").Option;
34
+ /**
35
+ * Option for specifying the Azure OpenAI instance name.
36
+ * Required for Azure OpenAI service endpoint construction.
37
+ */
38
+ export declare const apiInstanceOption: import("commander").Option;
39
+ /**
40
+ * Option for specifying the Azure OpenAI deployment name for chat models.
41
+ * Required for chat completions API calls.
42
+ */
43
+ export declare const chatDeploymentOption: import("commander").Option;
44
+ /**
45
+ * Option for specifying the Azure OpenAI deployment name for embedding models.
46
+ * Required for embeddings API calls.
47
+ */
48
+ export declare const embeddingDeploymentOption: import("commander").Option;
49
+ /**
50
+ * Option for specifying the Azure Search endpoint URL.
51
+ * Required for Azure Cognitive Search operations.
52
+ */
53
+ export declare const azureSearchEndpointOption: import("commander").Option;
54
+ /**
55
+ * Option for specifying the Azure Search API key.
56
+ * Required for authentication with Azure Cognitive Search.
57
+ */
58
+ export declare const azureSearchApiKeyOption: import("commander").Option;
59
+ /**
60
+ * Option for specifying the Azure Search index name.
61
+ * Required for search operations on a specific index.
62
+ */
63
+ export declare const azureSearchIndexNameOption: import("commander").Option;
64
+ /**
65
+ * Enhances a given command with AI-related options.
66
+ *
67
+ * This function adds the following options to the provided command:
68
+ * - `openaiApiKey`: Azure OpenAI API key
69
+ * - `openaiApiVersion`: Azure OpenAI API version
70
+ * - `openaiInstance`: Azure OpenAI instance name
71
+ * - `openaiChatDeployment`: Chat model deployment name
72
+ * - `openaiEmbeddingDeployment`: Embedding model deployment name (if includeEmbedding is true)
73
+ * - `azureSearchEndpoint`: Azure Search endpoint URL (if includeSearch is true)
74
+ * - `azureSearchApiKey`: Azure Search API key (if includeSearch is true)
75
+ * - `azureSearchIndexName`: Azure Search index name (if includeSearch is true)
76
+ *
77
+ * @param command - The command to which AI options will be added
78
+ * @param args - Optional configuration for which options to include
79
+ * @param args.includeEmbedding - Whether to include embedding deployment option
80
+ * @param args.includeChat - Whether to include chat deployment option (defaults to true)
81
+ * @param args.includeSearch - Whether to include Azure Search options (defaults to false)
82
+ * @returns The enhanced command with AI options
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * import { createCommand } from 'commander';
87
+ * import { withAiOptions } from './path/to/this/file';
88
+ *
89
+ * const command = withAiOptions(
90
+ * createCommand('ai-chat')
91
+ * .description('Chat with AI models')
92
+ * .action((options) => {
93
+ * console.log('API Key:', options.openaiApiKey);
94
+ * console.log('Instance:', options.openaiInstance);
95
+ * console.log('Chat Deployment:', options.openaiChatDeployment);
96
+ * })
97
+ * );
98
+ * ```
99
+ */
100
+ export declare const withAiOptions: (command: Command, args?: Partial<{
101
+ includeEmbedding: boolean;
102
+ includeChat: boolean;
103
+ includeSearch: boolean;
104
+ }>) => Command;
105
+ export default withAiOptions;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * CLI command: `ai search`
3
+ *
4
+ * Search the vector store to validate embeddings and retrieve relevant documents.
5
+ *
6
+ * Features:
7
+ * - Semantic search using vector embeddings
8
+ * - Configurable result limits
9
+ * - Filter support for metadata-based filtering
10
+ * - JSON output option for programmatic use
11
+ * - Detailed result display with scores and metadata
12
+ *
13
+ * Usage:
14
+ * $ ffc ai search <query> [options]
15
+ *
16
+ * Options:
17
+ * --limit <number> Maximum number of results to return (default: 10)
18
+ * --search-type <type> Search type: 'mmr' or 'similarity' (default: similarity)
19
+ * --filter <expression> OData filter expression for metadata filtering
20
+ * --json Output results as JSON
21
+ * --raw Output raw metadata without normalization
22
+ * --verbose Enable verbose output
23
+ * --openai-api-key <key> API key for Azure OpenAI
24
+ * --openai-api-version <version> API version (default: 2024-02-15-preview)
25
+ * --openai-instance <name> Azure OpenAI instance name
26
+ * --openai-embedding-deployment <name> Azure OpenAI embedding deployment name
27
+ * --azure-search-endpoint <url> Azure Search endpoint URL
28
+ * --azure-search-api-key <key> Azure Search API key
29
+ * --azure-search-index-name <name> Azure Search index name
30
+ *
31
+ * Environment Variables:
32
+ * AZURE_OPENAI_API_KEY API key for Azure OpenAI
33
+ * AZURE_OPENAI_API_VERSION API version
34
+ * AZURE_OPENAI_INSTANCE_NAME Instance name
35
+ * AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME Embedding deployment name
36
+ * AZURE_SEARCH_ENDPOINT Azure Search endpoint
37
+ * AZURE_SEARCH_API_KEY Azure Search API key
38
+ * AZURE_SEARCH_INDEX_NAME Azure Search index name
39
+ *
40
+ * Examples:
41
+ * $ ffc ai search "how to use the framework"
42
+ * $ ffc ai search "authentication" --limit 5
43
+ * $ ffc ai search "typescript" --filter "metadata/source eq 'src/index.ts'"
44
+ * $ ffc ai search "documentation" --search-type similarity
45
+ * $ ffc ai search "documentation" --json
46
+ * $ ffc ai search "documentation" --json --raw
47
+ * $ ffc ai search "API reference" --verbose
48
+ */
49
+ export declare const command: import("commander").Command;
50
+ export default command;
@@ -0,0 +1,10 @@
1
+ import { type AIModule } from '@equinor/fusion-framework-module-ai';
2
+ import type { AiOptions } from '../options/ai.js';
3
+ import { type ModulesInstance } from '@equinor/fusion-framework-module';
4
+ /**
5
+ * Initializes and configures the Fusion Framework with AI module capabilities
6
+ * @param options - AI configuration options including API keys, deployments, and vector store settings
7
+ * @returns Promise resolving to an initialized framework instance with AI module
8
+ * @throws {Error} If embedding deployment is required but not provided when configuring vector store
9
+ */
10
+ export declare const setupFramework: (options: AiOptions) => Promise<ModulesInstance<[AIModule]>>;
@@ -0,0 +1 @@
1
+ export declare const version = "1.0.0";
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@equinor/fusion-framework-cli-plugin-ai-search",
3
+ "version": "1.0.0",
4
+ "description": "AI search plugin for Fusion Framework CLI providing vector store search capabilities",
5
+ "main": "dist/esm/index.js",
6
+ "type": "module",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/esm/index.js",
11
+ "types": "./dist/types/index.d.ts"
12
+ }
13
+ },
14
+ "typesVersions": {
15
+ "*": {
16
+ ".": [
17
+ "dist/types/index.d.ts"
18
+ ]
19
+ }
20
+ },
21
+ "keywords": [
22
+ "fusion-framework",
23
+ "cli",
24
+ "plugin",
25
+ "llm",
26
+ "ai",
27
+ "search"
28
+ ],
29
+ "author": "",
30
+ "license": "ISC",
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/equinor/fusion-framework.git",
37
+ "directory": "packages/cli-plugins/ai/search"
38
+ },
39
+ "dependencies": {
40
+ "@langchain/core": "^1.0.1",
41
+ "commander": "^14.0.1",
42
+ "@equinor/fusion-framework-module-ai": "2.0.0",
43
+ "@equinor/fusion-framework-cli-plugin-ai-base": "1.0.0",
44
+ "@equinor/fusion-framework-module": "5.0.5"
45
+ },
46
+ "peerDependencies": {
47
+ "@equinor/fusion-framework-cli": "13.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "typescript": "^5.8.2"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -b",
54
+ "build:types": "tsc -b",
55
+ "watch": "tsc -b --watch",
56
+ "test": "vitest"
57
+ }
58
+ }
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { Command } from 'commander';
2
+ import { registerAiPlugin as registerAiPluginBase } from '@equinor/fusion-framework-cli-plugin-ai-base';
3
+ import { command as searchCommand } from './search.js';
4
+
5
+ /**
6
+ * Registers the AI search plugin command with the CLI program
7
+ * @param program - The Commander program instance to register commands with
8
+ */
9
+ export function registerAiPlugin(program: Command): void {
10
+ registerAiPluginBase(program, searchCommand);
11
+ }
12
+
13
+ export default registerAiPlugin;
@@ -0,0 +1,254 @@
1
+ import { type Command, createOption, InvalidOptionArgumentError } from 'commander';
2
+
3
+ /**
4
+ * Interface representing the AI-related options available in CLI commands.
5
+ * This interface defines the structure of options that can be passed to AI commands.
6
+ */
7
+ export interface AiOptions {
8
+ /** Azure OpenAI API key for authentication */
9
+ openaiApiKey: string;
10
+ /** Azure OpenAI API version */
11
+ openaiApiVersion: string;
12
+ /** Azure OpenAI instance name */
13
+ openaiInstance: string;
14
+ /** Azure OpenAI chat deployment name (optional) */
15
+ openaiChatDeployment?: string;
16
+ /** Azure OpenAI embedding deployment name (optional) */
17
+ openaiEmbeddingDeployment?: string;
18
+ /** Azure Search endpoint URL (optional) */
19
+ azureSearchEndpoint?: string;
20
+ /** Azure Search API key (optional) */
21
+ azureSearchApiKey?: string;
22
+ /** Azure Search index name (optional) */
23
+ azureSearchIndexName?: string;
24
+ }
25
+
26
+ /**
27
+ * Option for specifying the Azure OpenAI API key.
28
+ * Required for authentication with Azure OpenAI services.
29
+ */
30
+ export const apiKeyOption = createOption(
31
+ '--openai-api-key <key>',
32
+ 'API key for Azure OpenAI services',
33
+ ).env('AZURE_OPENAI_API_KEY');
34
+
35
+ /**
36
+ * Option for specifying the Azure OpenAI API version.
37
+ * Defaults to the latest stable version if not provided.
38
+ */
39
+ export const apiVersionOption = createOption(
40
+ '--openai-api-version <version>',
41
+ 'Azure OpenAI API version',
42
+ )
43
+ .env('AZURE_OPENAI_API_VERSION')
44
+ .default('2024-02-15-preview');
45
+
46
+ /**
47
+ * Option for specifying the Azure OpenAI instance name.
48
+ * Required for Azure OpenAI service endpoint construction.
49
+ */
50
+ export const apiInstanceOption = createOption(
51
+ '--openai-instance <name>',
52
+ 'Azure OpenAI instance name',
53
+ ).env('AZURE_OPENAI_INSTANCE_NAME');
54
+
55
+ /**
56
+ * Option for specifying the Azure OpenAI deployment name for chat models.
57
+ * Required for chat completions API calls.
58
+ */
59
+ export const chatDeploymentOption = createOption(
60
+ '--openai-chat-deployment <name>',
61
+ 'Azure OpenAI chat deployment name',
62
+ ).env('AZURE_OPENAI_CHAT_DEPLOYMENT_NAME');
63
+
64
+ /**
65
+ * Option for specifying the Azure OpenAI deployment name for embedding models.
66
+ * Required for embeddings API calls.
67
+ */
68
+ export const embeddingDeploymentOption = createOption(
69
+ '--openai-embedding-deployment <name>',
70
+ 'Azure OpenAI embedding deployment name',
71
+ ).env('AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME');
72
+
73
+ /**
74
+ * Option for specifying the Azure Search endpoint URL.
75
+ * Required for Azure Cognitive Search operations.
76
+ */
77
+ export const azureSearchEndpointOption = createOption(
78
+ '--azure-search-endpoint <url>',
79
+ 'Azure Search endpoint URL',
80
+ ).env('AZURE_SEARCH_ENDPOINT');
81
+
82
+ /**
83
+ * Option for specifying the Azure Search API key.
84
+ * Required for authentication with Azure Cognitive Search.
85
+ */
86
+ export const azureSearchApiKeyOption = createOption(
87
+ '--azure-search-api-key <key>',
88
+ 'Azure Search API key',
89
+ ).env('AZURE_SEARCH_API_KEY');
90
+
91
+ /**
92
+ * Option for specifying the Azure Search index name.
93
+ * Required for search operations on a specific index.
94
+ */
95
+ export const azureSearchIndexNameOption = createOption(
96
+ '--azure-search-index-name <name>',
97
+ 'Azure Search index name',
98
+ ).env('AZURE_SEARCH_INDEX_NAME');
99
+
100
+ /**
101
+ * Enhances a given command with AI-related options.
102
+ *
103
+ * This function adds the following options to the provided command:
104
+ * - `openaiApiKey`: Azure OpenAI API key
105
+ * - `openaiApiVersion`: Azure OpenAI API version
106
+ * - `openaiInstance`: Azure OpenAI instance name
107
+ * - `openaiChatDeployment`: Chat model deployment name
108
+ * - `openaiEmbeddingDeployment`: Embedding model deployment name (if includeEmbedding is true)
109
+ * - `azureSearchEndpoint`: Azure Search endpoint URL (if includeSearch is true)
110
+ * - `azureSearchApiKey`: Azure Search API key (if includeSearch is true)
111
+ * - `azureSearchIndexName`: Azure Search index name (if includeSearch is true)
112
+ *
113
+ * @param command - The command to which AI options will be added
114
+ * @param args - Optional configuration for which options to include
115
+ * @param args.includeEmbedding - Whether to include embedding deployment option
116
+ * @param args.includeChat - Whether to include chat deployment option (defaults to true)
117
+ * @param args.includeSearch - Whether to include Azure Search options (defaults to false)
118
+ * @returns The enhanced command with AI options
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * import { createCommand } from 'commander';
123
+ * import { withAiOptions } from './path/to/this/file';
124
+ *
125
+ * const command = withAiOptions(
126
+ * createCommand('ai-chat')
127
+ * .description('Chat with AI models')
128
+ * .action((options) => {
129
+ * console.log('API Key:', options.openaiApiKey);
130
+ * console.log('Instance:', options.openaiInstance);
131
+ * console.log('Chat Deployment:', options.openaiChatDeployment);
132
+ * })
133
+ * );
134
+ * ```
135
+ */
136
+ export const withAiOptions = (
137
+ command: Command,
138
+ args?: Partial<{
139
+ includeEmbedding: boolean;
140
+ includeChat: boolean;
141
+ includeSearch: boolean;
142
+ }>,
143
+ ): Command => {
144
+ // Core authentication options
145
+ command.addOption(apiKeyOption);
146
+ command.addOption(apiVersionOption);
147
+ command.addOption(apiInstanceOption);
148
+
149
+ // Deployment options
150
+ if (args?.includeChat === true) {
151
+ command.addOption(chatDeploymentOption);
152
+ }
153
+
154
+ if (args?.includeEmbedding === true) {
155
+ command.addOption(embeddingDeploymentOption);
156
+ }
157
+
158
+ // Azure Search options
159
+ if (args?.includeSearch === true) {
160
+ command.addOption(azureSearchEndpointOption);
161
+ command.addOption(azureSearchApiKeyOption);
162
+ command.addOption(azureSearchIndexNameOption);
163
+ }
164
+
165
+ // Validation hook
166
+ command.hook('preAction', (thisCommand) => {
167
+ const options = thisCommand.opts();
168
+
169
+ // Validate API key
170
+ if (
171
+ !options.openaiApiKey ||
172
+ typeof options.openaiApiKey !== 'string' ||
173
+ options.openaiApiKey.trim() === ''
174
+ ) {
175
+ throw new InvalidOptionArgumentError('API key is required and must be a non-empty string.');
176
+ }
177
+
178
+ // Validate API version
179
+ if (!options.openaiApiVersion || typeof options.openaiApiVersion !== 'string') {
180
+ throw new InvalidOptionArgumentError('API version must be a non-empty string.');
181
+ }
182
+
183
+ // Validate instance name
184
+ if (
185
+ !options.openaiInstance ||
186
+ typeof options.openaiInstance !== 'string' ||
187
+ options.openaiInstance.trim() === ''
188
+ ) {
189
+ throw new InvalidOptionArgumentError(
190
+ 'API instance name is required and must be a non-empty string.',
191
+ );
192
+ }
193
+
194
+ if (args?.includeChat === true) {
195
+ if (
196
+ !options.openaiChatDeployment ||
197
+ typeof options.openaiChatDeployment !== 'string' ||
198
+ options.openaiChatDeployment.trim() === ''
199
+ ) {
200
+ throw new InvalidOptionArgumentError(
201
+ 'Chat deployment name is required and must be a non-empty string.',
202
+ );
203
+ }
204
+ }
205
+
206
+ if (args?.includeEmbedding === true) {
207
+ if (
208
+ !options.openaiEmbeddingDeployment ||
209
+ typeof options.openaiEmbeddingDeployment !== 'string' ||
210
+ options.openaiEmbeddingDeployment.trim() === ''
211
+ ) {
212
+ throw new InvalidOptionArgumentError(
213
+ 'Embedding deployment name is required and must be a non-empty string.',
214
+ );
215
+ }
216
+ }
217
+
218
+ if (args?.includeSearch === true) {
219
+ if (
220
+ !options.azureSearchEndpoint ||
221
+ typeof options.azureSearchEndpoint !== 'string' ||
222
+ options.azureSearchEndpoint.trim() === ''
223
+ ) {
224
+ throw new InvalidOptionArgumentError(
225
+ 'Azure Search endpoint is required and must be a non-empty string.',
226
+ );
227
+ }
228
+
229
+ if (
230
+ !options.azureSearchApiKey ||
231
+ typeof options.azureSearchApiKey !== 'string' ||
232
+ options.azureSearchApiKey.trim() === ''
233
+ ) {
234
+ throw new InvalidOptionArgumentError(
235
+ 'Azure Search API key is required and must be a non-empty string.',
236
+ );
237
+ }
238
+
239
+ if (
240
+ !options.azureSearchIndexName ||
241
+ typeof options.azureSearchIndexName !== 'string' ||
242
+ options.azureSearchIndexName.trim() === ''
243
+ ) {
244
+ throw new InvalidOptionArgumentError(
245
+ 'Azure Search index name is required and must be a non-empty string.',
246
+ );
247
+ }
248
+ }
249
+ });
250
+
251
+ return command;
252
+ };
253
+
254
+ export default withAiOptions;