@aws-amplify/graphql-generation-transformer
v1.1.1
Published
Amplify GraphQL @generation transformer
Downloads
24,813
Maintainers
Keywords
Readme
Amplify GraphQL Generation Transformer
The Amplify GraphQL Generation Transformer is a tool that enables the quick and easy creation of AI-powered Generation routes within your AWS AppSync API. This transformer can be leveraged by using the @generation
directive to configure AI models and system prompts for generating content.
Installation
npm install @aws-amplify/graphql-generation-transformer
Directive Definition
The @generation
directive is defined as follows:
directive @generation(aiModel: String!, systemPrompt: String!, inferenceConfiguration: GenerationInferenceConfiguration) on FIELD_DEFINITION
Features
- AI Model Integration: Specify the AI model to be used for generation.
- System Prompt Configuration: Define a system prompt to guide the AI's output.
- Inference Configuration: Fine-tune generation parameters like max tokens, temperature, and top-p.
- Integrates with
@auth
Directive: Supports existing auth modes like IAM, API key, and Amazon Cognito User Pools. - Resolver Creation: Generates resolvers with tool definitions based on the Query field's return type to interact with the specified AI model.
- Bedrock HTTP Data Source Creation: Creates a AppSync HTTP Data Source for Bedrock to interact with the specified AI model.
Examples
Basic Usage
Scalar Type Generation
type Query {
generateStory(topic: String!): String
@generation(
aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
systemPrompt: "You are a creative storyteller. Generate a short story based on the given topic."
)
}
Complex Type Generation
type Recipe {
name: String!
ingredients: [String!]!
instructions: [String!]!
prepTime: Int!
cookTime: Int!
servings: Int!
difficulty: String!
}
type Query {
generateRecipe(cuisine: String!, dietaryRestrictions: [String]): Recipe
@generation(
aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
systemPrompt: "You are a professional chef specializing in creating recipes. Generate a detailed recipe based on the given cuisine and dietary restrictions."
)
}
Advanced Configuration
type Query {
generateCode(description: String!): String
@generation(
aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
systemPrompt: "You are an expert programmer. Generate code based on the given description."
inferenceConfiguration: { maxTokens: 500, temperature: 0.7, topP: 0.9 }
)
}
Limitations
- The
@generation
directive can only be used on Query fields. - The AI model specified must:
- be supported by Amazon Bedrock's /converse API
- support tool usage
- Some AppSync scalar types are not currently supported.