Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release PR #3038

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/amplify-data-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-auth-transformer": "4.1.7",
"@aws-amplify/graphql-conversation-transformer": "0.7.1",
"@aws-amplify/graphql-conversation-transformer": "1.1.0",
"@aws-amplify/graphql-default-value-transformer": "3.1.4",
"@aws-amplify/graphql-directives": "2.6.0",
"@aws-amplify/graphql-function-transformer": "3.1.6",
"@aws-amplify/graphql-generation-transformer": "0.2.7",
"@aws-amplify/graphql-generation-transformer": "1.1.0",
"@aws-amplify/graphql-http-transformer": "3.0.9",
"@aws-amplify/graphql-index-transformer": "3.0.9",
"@aws-amplify/graphql-maps-to-transformer": "4.0.9",
Expand All @@ -23,7 +23,7 @@
"@aws-amplify/graphql-relational-transformer": "3.1.1",
"@aws-amplify/graphql-searchable-transformer": "3.0.9",
"@aws-amplify/graphql-sql-transformer": "0.4.9",
"@aws-amplify/graphql-transformer": "2.1.8",
"@aws-amplify/graphql-transformer": "2.2.0",
"@aws-amplify/graphql-transformer-core": "3.3.1",
"@aws-amplify/graphql-transformer-interfaces": "4.2.0",
"@aws-amplify/platform-core": "^1.0.0",
Expand Down Expand Up @@ -130,7 +130,7 @@
"zod": "^3.22.2"
},
"dependencies": {
"@aws-amplify/graphql-api-construct": "1.17.3",
"@aws-amplify/graphql-api-construct": "1.18.0",
"aws-cdk-lib": "^2.158.0",
"constructs": "^10.3.0"
},
Expand Down Expand Up @@ -4026,6 +4026,6 @@
}
},
"types": {},
"version": "1.13.3",
"fingerprint": "IHJwVBq9IwAsKxatjZFB5oGr2BjL9pJEOTdmn4HlmTc="
"version": "1.14.0",
"fingerprint": "O9tbfsjr+oFjPs0QnyeyJp/+ohWA9xCM+E3XUv2PDGw="
}
10 changes: 5 additions & 5 deletions packages/amplify-graphql-api-construct/.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"@aws-amplify/backend-output-schemas": "^1.0.0",
"@aws-amplify/backend-output-storage": "^1.0.0",
"@aws-amplify/graphql-auth-transformer": "4.1.7",
"@aws-amplify/graphql-conversation-transformer": "0.7.1",
"@aws-amplify/graphql-conversation-transformer": "1.1.0",
"@aws-amplify/graphql-default-value-transformer": "3.1.4",
"@aws-amplify/graphql-directives": "2.6.0",
"@aws-amplify/graphql-function-transformer": "3.1.6",
"@aws-amplify/graphql-generation-transformer": "0.2.7",
"@aws-amplify/graphql-generation-transformer": "1.1.0",
"@aws-amplify/graphql-http-transformer": "3.0.9",
"@aws-amplify/graphql-index-transformer": "3.0.9",
"@aws-amplify/graphql-maps-to-transformer": "4.0.9",
Expand All @@ -23,7 +23,7 @@
"@aws-amplify/graphql-relational-transformer": "3.1.1",
"@aws-amplify/graphql-searchable-transformer": "3.0.9",
"@aws-amplify/graphql-sql-transformer": "0.4.9",
"@aws-amplify/graphql-transformer": "2.1.8",
"@aws-amplify/graphql-transformer": "2.2.0",
"@aws-amplify/graphql-transformer-core": "3.3.1",
"@aws-amplify/graphql-transformer-interfaces": "4.2.0",
"@aws-amplify/platform-core": "^1.0.0",
Expand Down Expand Up @@ -9031,6 +9031,6 @@
"symbolId": "src/model-datasource-strategy-types:VpcConfig"
}
},
"version": "1.17.3",
"fingerprint": "qWoJ1MnrNidPzpA7LUqCtNglSoHcTQ4YC7U3xRaYgIA="
"version": "1.18.0",
"fingerprint": "z0rzJHCDSTpFx/GRBG2+htlUdGLnrEhuLsVbf5AbNdM="
}
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ export function request(ctx) {
const clientTools = args.toolConfiguration?.tools?.map((tool) => {
return { ...tool.toolSpec };
});
const dataTools = [{"name":"list_customers","description":"Provides data about the customer sending a message","inputSchema":{"json":{"type":"object","properties":{},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"items { name email activeCart { products { name price } customerId id createdAt updatedAt owner } orderHistory { items { products { name price } customerId id createdAt updatedAt owner } nextToken } id createdAt updatedAt owner } nextToken","propertyTypes":{},"queryName":"listCustomers"}}];
const dataTools = [{"name":"random_name","description":"Provides data about the customer sending a message","inputSchema":{"json":{"type":"object","properties":{},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"items { name email activeCart { products { name price } customerId id createdAt updatedAt owner } orderHistory { items { products { name price } customerId id createdAt updatedAt owner } nextToken } id createdAt updatedAt owner } nextToken","propertyTypes":{},"queryName":"listCustomers"}}];
const toolsConfiguration = { dataTools, clientTools };

const messageHistoryQuery = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Mutation {
systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.",
tools: [
{
name: "list_customers",
name: "random_name",
description: "Provides data about the customer sending a message",
modelName: "Customer",
modelOperation: list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ export const processTools = (toolDefinitions: ToolDefinition[], ctx: Transformer

// Process each tool definition
const tools: Tool[] = toolDefinitions.map((toolDefinition) => {
const { name: toolName, description } = toolDefinition;
const queryName = isModelOperationToolPredicate(toolDefinition) ? modelListQueryName(toolDefinition, ctx) : toolDefinition.queryName;
const queryField = queryType.fields?.find((field) => field.name.value === queryName);

if (!queryField) {
throw new InvalidDirectiveError(`Tool "${toolName}" defined in @conversation directive has no matching Query field definition`);
throw new InvalidDirectiveError(
`Tool "${toolDefinition.name}" defined in @conversation directive has no matching Query field definition`,
);
}

return createTool({ toolName, description, queryField, ctx });
return createTool({ toolDefinition, queryField, ctx });
});

return tools;
Expand Down Expand Up @@ -150,23 +151,19 @@ const getObjectTypeFromName = (name: string, ctx: TransformerContextProvider): O
* @param {TransformerContextProvider} ctx - The transformer context provider.
* @returns {Tool} A Tool object.
*/
const createTool = (input: {
toolName: string;
description: string;
queryField: FieldDefinitionNode;
ctx: TransformerContextProvider;
}): Tool => {
const { toolName, description, queryField, ctx } = input;
const createTool = (input: { toolDefinition: ToolDefinition; queryField: FieldDefinitionNode; ctx: TransformerContextProvider }): Tool => {
const { toolDefinition, queryField, ctx } = input;
const { name: toolName, description } = toolDefinition;
const { type: returnType, arguments: fieldArguments } = queryField;

// Generate tool properties and required fields
const { properties, required } = generateToolProperties(fieldArguments, ctx, toolName, returnType);
const { properties, required } = generateToolProperties(fieldArguments, ctx, toolDefinition);

// Generate selection set for the return type
const selectionSet = generateSelectionSet(returnType, ctx).trim();

// Generate property types for GraphQL request input
const propertyTypes = generatePropertyTypes(fieldArguments, toolName, returnType);
const propertyTypes = generatePropertyTypes(fieldArguments, toolDefinition);

// Create GraphQL request input descriptor
const graphqlRequestInputDescriptor: GraphQLRequestInputDescriptor = {
Expand Down Expand Up @@ -199,14 +196,13 @@ const createTool = (input: {
const generateToolProperties = (
fieldArguments: readonly InputValueDefinitionNode[] | undefined,
ctx: TransformerContextProvider,
toolName: string,
returnType: TypeNode,
toolDefinition: ToolDefinition,
): { properties: Record<string, JSONSchema>; required: string[] } => {
if (!fieldArguments || fieldArguments.length === 0) {
return { properties: {}, required: [] };
}

if (isModelListOperation(toolName, returnType)) {
if (isModelOperationToolPredicate(toolDefinition)) {
return { properties: {}, required: [] };
}

Expand All @@ -233,14 +229,13 @@ const generateToolProperties = (
*/
const generatePropertyTypes = (
fieldArguments: readonly InputValueDefinitionNode[] | undefined,
toolName: string,
returnType: TypeNode,
toolDefinition: ToolDefinition,
): Record<string, string> => {
if (!fieldArguments || fieldArguments.length === 0) {
return {};
}

if (isModelListOperation(toolName, returnType)) {
if (isModelOperationToolPredicate(toolDefinition)) {
return {};
}

Expand All @@ -252,10 +247,6 @@ const generatePropertyTypes = (
}, {} as Record<string, string>);
};

const isModelListOperation = (toolName: string, responseType: TypeNode): boolean => {
return getBaseType(responseType).startsWith('Model') && toolName.startsWith('list');
};

const modelListQueryName = (modelTool: ModelOperationTool, ctx: TransformerContextProvider): string => {
const { modelName } = modelTool;
const model = getObjectTypeFromName(modelName, ctx);
Expand Down
Loading