放大图形QL 生成变换器
AWS AppSync API内部的 Amplify GraphQL 世代变换器是一个工具,可以快速而轻松地创建AI-power Crowth 路由. 这个变压器可以通过使用 @generation 指令配置生成内容的AI模型和系统提示.
安装
npm install @aws-amplify/graphql-generation-transformer
指令定义
这个 @generation 指令的定义如下:
directive @generation(aiModel: String!, systemPrompt: String!, inferenceConfiguration: GenerationInferenceConfiguration) on FIELD_DEFINITION
特征
- AI模型集成:指定用于生成的AI模型.
- 系统快取配置:定义一个系统快取来指导AI的输出.
- 推论配置:微调生成参数,如最大符号,温度,和上-p.
- 与
@auth指令:支持IAM,API密钥等现有认证模式,以及Amazon Cognitto用户池. - 解析器创建:生成基于Query字段返回类型的工具定义的解析器与指定的AI模型进行交互.
- Bedrock HTTP Data Source Create:为Bedrock创建了AppSync HTTP Data Source,用于与指定的AI模型交互.
实例
基本用途
Scalar 类型生成
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."
)
}
复杂类型生成
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."
)
}
高级配置
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 }
)
}
限制
- 这个
@generation指令只能用于查询字段. - 规定的AI模式必须:
- 由 Amazon Bedrock 的 / 逆向 API 支持
- 支持工具的使用
- 目前不支持一些AppSync scalar类型.