@future-explorer/lib 1.0.9 → 1.0.10
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/README.md +6 -6
- package/dist/clients/ai/unified/unified-ai-client.d.ts +9 -13
- package/dist/clients/ai/unified/unified-ai-client.d.ts.map +1 -1
- package/dist/clients/ai/unified/unified-ai-client.js +10 -11
- package/dist/clients/ai/unified/unified-ai-client.model.d.ts +19 -0
- package/dist/clients/ai/unified/unified-ai-client.model.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,11 +87,11 @@ const SentimentSchema = z.object({
|
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
// Generate structured response
|
|
90
|
-
const result = await client.generateStructuredResponse(
|
|
91
|
-
SentimentSchema,
|
|
92
|
-
'I absolutely love this product!',
|
|
93
|
-
'You are a sentiment analysis expert.'
|
|
94
|
-
);
|
|
90
|
+
const result = await client.generateStructuredResponse({
|
|
91
|
+
schema: SentimentSchema,
|
|
92
|
+
userPrompt: 'I absolutely love this product!',
|
|
93
|
+
systemMessage: 'You are a sentiment analysis expert.',
|
|
94
|
+
});
|
|
95
95
|
|
|
96
96
|
console.log(result.sentiment); // 'positive'
|
|
97
97
|
console.log(result.confidence); // 0.95
|
|
@@ -108,7 +108,7 @@ console.log(result.summary); // '...'
|
|
|
108
108
|
|
|
109
109
|
### Methods
|
|
110
110
|
|
|
111
|
-
- `generateStructuredResponse<T>(
|
|
111
|
+
- `generateStructuredResponse<T>(params: GenerateObjectParams<T>)`: Generates a structured response matching the Zod schema. Accepts `schema`, `userPrompt`, `systemMessage`, plus any additional `generateObject()` options
|
|
112
112
|
- `getModel()`: Returns the underlying LanguageModel instance
|
|
113
113
|
|
|
114
114
|
## Development
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LanguageModel } from 'ai';
|
|
2
|
-
import {
|
|
3
|
-
import { Provider } from './unified-ai-client.model';
|
|
2
|
+
import { GenerateObjectParams, Provider } from './unified-ai-client.model';
|
|
4
3
|
/**
|
|
5
4
|
* Unified AI Client that supports multiple AI providers (OpenAI, XAI, Gemini)
|
|
6
5
|
* and allows generating structured responses based on Zod schemas.
|
|
@@ -13,11 +12,8 @@ export declare class UnifiedAiClient {
|
|
|
13
12
|
*
|
|
14
13
|
* @template T - The type inferred from the Zod schema
|
|
15
14
|
*
|
|
16
|
-
* @param
|
|
17
|
-
*
|
|
18
|
-
* @param prompt - User input/message to send to the AI model (role: user)
|
|
19
|
-
* @param system - Optional system instructions that define the AI's behavior,
|
|
20
|
-
* persona, and task context (role: system)
|
|
15
|
+
* @param params - Configuration object for the structured response generation.
|
|
16
|
+
* See {@link GenerateObjectParams} for all available options.
|
|
21
17
|
*
|
|
22
18
|
* @returns Promise resolving to the validated object matching the schema type T
|
|
23
19
|
*
|
|
@@ -33,16 +29,16 @@ export declare class UnifiedAiClient {
|
|
|
33
29
|
* });
|
|
34
30
|
*
|
|
35
31
|
* // Generate structured response
|
|
36
|
-
* const result = await service.generateStructuredResponse(
|
|
37
|
-
* SentimentSchema,
|
|
38
|
-
* 'I absolutely love this product!',
|
|
39
|
-
* 'You are a sentiment analysis expert. Be precise with confidence scores.'
|
|
40
|
-
* );
|
|
32
|
+
* const result = await service.generateStructuredResponse({
|
|
33
|
+
* schema: SentimentSchema,
|
|
34
|
+
* userPrompt: 'I absolutely love this product!',
|
|
35
|
+
* systemMessage: 'You are a sentiment analysis expert. Be precise with confidence scores.',
|
|
36
|
+
* });
|
|
41
37
|
*
|
|
42
38
|
* console.log(result.sentiment); // 'positive'
|
|
43
39
|
* console.log(result.confidence); // 0.95
|
|
44
40
|
*/
|
|
45
|
-
generateStructuredResponse<T>(
|
|
41
|
+
generateStructuredResponse<T>(params: GenerateObjectParams<T>): Promise<T>;
|
|
46
42
|
/**
|
|
47
43
|
* Retrieves the underlying LanguageModel instance.
|
|
48
44
|
* @returns The LanguageModel instance used by the UnifiedAiClient.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-ai-client.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"unified-ai-client.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE3E;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAgB;gBAEjB,QAAQ,EAAE,QAAQ;IAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAchF;;;OAGG;IACH,QAAQ,IAAI,aAAa;IAIzB,OAAO,CAAC,WAAW;CAYpB"}
|
|
@@ -20,11 +20,8 @@ class UnifiedAiClient {
|
|
|
20
20
|
*
|
|
21
21
|
* @template T - The type inferred from the Zod schema
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
24
|
-
*
|
|
25
|
-
* @param prompt - User input/message to send to the AI model (role: user)
|
|
26
|
-
* @param system - Optional system instructions that define the AI's behavior,
|
|
27
|
-
* persona, and task context (role: system)
|
|
23
|
+
* @param params - Configuration object for the structured response generation.
|
|
24
|
+
* See {@link GenerateObjectParams} for all available options.
|
|
28
25
|
*
|
|
29
26
|
* @returns Promise resolving to the validated object matching the schema type T
|
|
30
27
|
*
|
|
@@ -40,17 +37,19 @@ class UnifiedAiClient {
|
|
|
40
37
|
* });
|
|
41
38
|
*
|
|
42
39
|
* // Generate structured response
|
|
43
|
-
* const result = await service.generateStructuredResponse(
|
|
44
|
-
* SentimentSchema,
|
|
45
|
-
* 'I absolutely love this product!',
|
|
46
|
-
* 'You are a sentiment analysis expert. Be precise with confidence scores.'
|
|
47
|
-
* );
|
|
40
|
+
* const result = await service.generateStructuredResponse({
|
|
41
|
+
* schema: SentimentSchema,
|
|
42
|
+
* userPrompt: 'I absolutely love this product!',
|
|
43
|
+
* systemMessage: 'You are a sentiment analysis expert. Be precise with confidence scores.',
|
|
44
|
+
* });
|
|
48
45
|
*
|
|
49
46
|
* console.log(result.sentiment); // 'positive'
|
|
50
47
|
* console.log(result.confidence); // 0.95
|
|
51
48
|
*/
|
|
52
|
-
async generateStructuredResponse(
|
|
49
|
+
async generateStructuredResponse(params) {
|
|
50
|
+
const { schema, userPrompt, systemMessage, ...rest } = params;
|
|
53
51
|
const result = await (0, ai_1.generateObject)({
|
|
52
|
+
...rest,
|
|
54
53
|
model: this.model,
|
|
55
54
|
schema: schema, // Option 2: Use jsonSchema instead of Zod directly: schema: jsonSchema<T>(zodToJsonSchema(schema) as any),
|
|
56
55
|
prompt: userPrompt,
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
import { generateObject } from 'ai';
|
|
2
|
+
import { ZodSchema } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Options for generating a structured response from the AI model.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type inferred from the Zod schema
|
|
7
|
+
*
|
|
8
|
+
* Includes the core params (schema, userPrompt, systemMessage) plus
|
|
9
|
+
* any additional options supported by the underlying `generateObject()` call
|
|
10
|
+
* (e.g. mode, schemaName, schemaDescription, maxTokens, temperature, etc.).
|
|
11
|
+
*/
|
|
12
|
+
export interface GenerateObjectParams<T> extends Omit<Parameters<typeof generateObject>[0], 'model' | 'schema' | 'prompt' | 'system' | 'messages'> {
|
|
13
|
+
/** Zod schema defining the expected response structure. */
|
|
14
|
+
schema: ZodSchema<T>;
|
|
15
|
+
/** User input/message to send to the AI model (role: user). */
|
|
16
|
+
userPrompt: string;
|
|
17
|
+
/** Optional system instructions that define the AI's behavior, persona, and task context (role: system). */
|
|
18
|
+
systemMessage?: string;
|
|
19
|
+
}
|
|
1
20
|
/**
|
|
2
21
|
* Enum representing supported AI providers.
|
|
3
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-ai-client.model.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;IACH,GAAG,QAAQ;IACX;;OAEG;IACH,MAAM,WAAW;CAClB"}
|
|
1
|
+
{"version":3,"file":"unified-ai-client.model.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,CACrC,SAAQ,IAAI,CACV,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CACtD;IACD,2DAA2D;IAC3D,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,4GAA4G;IAC5G,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,oBAAY,QAAQ;IAClB;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;IACH,GAAG,QAAQ;IACX;;OAEG;IACH,MAAM,WAAW;CAClB"}
|