@aws-amplify/data-schema 1.9.0 → 1.9.2
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/dist/cjs/SchemaProcessor.js +14 -2
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/ai/ConversationSchemaTypes.js +16 -8
- package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +14 -2
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/ai/ConversationSchemaTypes.d.ts +5 -1
- package/dist/esm/ai/ConversationSchemaTypes.mjs +16 -8
- package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -1
- package/dist/esm/ai/ConversationType.d.ts +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/SchemaProcessor.ts +14 -2
- package/src/ai/ConversationSchemaTypes.ts +18 -8
- package/src/ai/ConversationType.ts +1 -1
package/package.json
CHANGED
package/src/SchemaProcessor.ts
CHANGED
|
@@ -510,6 +510,16 @@ function customOperationToGql(
|
|
|
510
510
|
const { aiModel, systemPrompt, inferenceConfiguration } =
|
|
511
511
|
typeDef.data.input;
|
|
512
512
|
|
|
513
|
+
// This is done to escape newlines in potentially multi-line system prompts
|
|
514
|
+
// e.g.
|
|
515
|
+
// generateStuff: a.generation({
|
|
516
|
+
// aiModel: a.ai.model('Claude 3 Haiku'),
|
|
517
|
+
// systemPrompt: `Generate a haiku
|
|
518
|
+
// make it multiline`,
|
|
519
|
+
// }),
|
|
520
|
+
//
|
|
521
|
+
// It doesn't affect non multi-line string inputs for system prompts
|
|
522
|
+
const escapedSystemPrompt = systemPrompt.replace(/\r?\n/g, '\\n');
|
|
513
523
|
const inferenceConfigurationEntries = Object.entries(
|
|
514
524
|
inferenceConfiguration ?? {},
|
|
515
525
|
);
|
|
@@ -519,7 +529,7 @@ function customOperationToGql(
|
|
|
519
529
|
.map(([key, value]) => `${key}: ${value}`)
|
|
520
530
|
.join(', ')} }`
|
|
521
531
|
: '';
|
|
522
|
-
gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${
|
|
532
|
+
gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${escapedSystemPrompt}"${inferenceConfigurationGql}) `;
|
|
523
533
|
}
|
|
524
534
|
|
|
525
535
|
const gqlField = `${callSignature}: ${returnTypeName} ${gqlHandlerContent}${authString}`;
|
|
@@ -1432,7 +1442,9 @@ const schemaPreprocessor = (
|
|
|
1432
1442
|
}
|
|
1433
1443
|
} else if (isConversationRoute(typeDef)) {
|
|
1434
1444
|
// TODO: add inferenceConfiguration values to directive.
|
|
1435
|
-
|
|
1445
|
+
const { field, functionHandler } = createConversationField(typeDef, typeName);
|
|
1446
|
+
customMutations.push(field);
|
|
1447
|
+
Object.assign(lambdaFunctions, functionHandler);
|
|
1436
1448
|
shouldAddConversationTypes = true;
|
|
1437
1449
|
}
|
|
1438
1450
|
} else if (staticSchema) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LambdaFunctionDefinition } from '@aws-amplify/data-schema-types';
|
|
1
2
|
import { InternalRef } from '../RefType';
|
|
2
3
|
import { capitalize } from '../runtime/utils';
|
|
3
4
|
import type {
|
|
@@ -8,20 +9,28 @@ import type {
|
|
|
8
9
|
export const createConversationField = (
|
|
9
10
|
typeDef: InternalConversationType,
|
|
10
11
|
typeName: string,
|
|
11
|
-
): string => {
|
|
12
|
+
): { field: string, functionHandler: LambdaFunctionDefinition } => {
|
|
12
13
|
const { aiModel, systemPrompt, handler, tools } = typeDef;
|
|
13
14
|
|
|
14
15
|
const args: Record<string, string> = {
|
|
15
16
|
aiModel: aiModel.resourcePath,
|
|
16
|
-
|
|
17
|
+
// This is done to escape newlines in potentially multi-line system prompts
|
|
18
|
+
// e.g.
|
|
19
|
+
// realtorChat: a.conversation({
|
|
20
|
+
// aiModel: a.ai.model('Claude 3 Haiku'),
|
|
21
|
+
// systemPrompt: `You are a helpful real estate assistant
|
|
22
|
+
// Respond in the poetic form of haiku.`,
|
|
23
|
+
// }),
|
|
24
|
+
//
|
|
25
|
+
// It doesn't affect non multi-line string inputs for system prompts
|
|
26
|
+
systemPrompt: systemPrompt.replace(/\r?\n/g, '\\n'),
|
|
17
27
|
};
|
|
18
28
|
|
|
29
|
+
const functionHandler: LambdaFunctionDefinition = {};
|
|
19
30
|
if (handler) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
args['functionName'] = `Fn${capitalize(typeName)}`;
|
|
24
|
-
}
|
|
31
|
+
const functionName = `Fn${capitalize(typeName)}`;
|
|
32
|
+
args['functionName'] = functionName;
|
|
33
|
+
functionHandler[functionName] = handler;
|
|
25
34
|
}
|
|
26
35
|
|
|
27
36
|
const argsString = Object.entries(args)
|
|
@@ -34,7 +43,8 @@ export const createConversationField = (
|
|
|
34
43
|
|
|
35
44
|
const conversationDirective = `@conversation(${argsString}${toolsString})`;
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;
|
|
47
|
+
return { field, functionHandler };
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
const isRef = (query: unknown): query is { data: InternalRef['data'] } =>
|
|
@@ -125,7 +125,7 @@ export interface ConversationInput {
|
|
|
125
125
|
systemPrompt: string;
|
|
126
126
|
inferenceConfiguration?: InferenceConfiguration;
|
|
127
127
|
tools?: ToolDefinition[];
|
|
128
|
-
handler?: DefineFunction
|
|
128
|
+
handler?: DefineFunction;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
export interface InternalConversationType
|