-
Notifications
You must be signed in to change notification settings - Fork 89
refactor(conversation): consolidate resolver generation logic #2957
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
Changes from all commits
30d2087
b2b2135
11de0e3
06c295a
c8d7500
b3a9e19
1170798
019e01f
d35bd88
90d6131
b75b80d
a9df4e9
dbc52bf
175fa36
90afcb5
5162880
22e2b68
a0062d0
f0e51d9
fc5d8fb
77da9b1
2acdfc1
8893a15
ef784a5
288d076
60683e7
204019a
5dc7752
5e7e0a6
5f6712b
0e8eaee
9c8c72c
aa252f7
ac1148f
80948aa
a3111dc
0b84777
fb1f132
3c52969
61052fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,7 +152,6 @@ export function request(ctx) { | |
| const { args, request } = ctx; | ||
| const { graphqlApiEndpoint } = ctx.stash; | ||
|
|
||
|
|
||
| const selectionSet = 'id conversationId content { image { format source { bytes }} text toolUse { toolUseId name input } toolResult { status toolUseId content { json text image { format source { bytes }} document { format name source { bytes }} }}} role owner createdAt updatedAt'; | ||
|
|
||
| const responseMutation = { | ||
|
|
@@ -161,18 +160,18 @@ export function request(ctx) { | |
| selectionSet, | ||
| }; | ||
| const currentMessageId = ctx.stash.defaultValues.id; | ||
|
|
||
| const modelConfiguration = { | ||
| modelId: 'anthropic.claude-3-haiku-20240307-v1:0', | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
| inferenceConfiguration: {"temperature":0.5,"topP":0.9,"maxTokens":100}, | ||
| }; | ||
| modelId: "anthropic.claude-3-haiku-20240307-v1:0", | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
| inferenceConfiguration: {"temperature":0.5,"topP":0.9,"maxTokens":100}, | ||
| }; | ||
|
|
||
| const clientTools = args.toolConfiguration?.tools?.map((tool) => { | ||
| return { ...tool.toolSpec }; | ||
| }); | ||
| const toolsConfiguration = { | ||
| clientTools | ||
| }; | ||
| const dataTools = undefined; | ||
| const toolsConfiguration = { dataTools, clientTools }; | ||
|
Comment on lines
+173
to
+174
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is expected if no tools are provided in the conversation directive. It was part of reworking the resolver function generation to stop constructed fragments of the JS resolver runtime code as strings within the transformer. |
||
|
|
||
| const messageHistoryQuery = { | ||
| getQueryName: 'getConversationMessagePirateChat', | ||
|
|
@@ -373,7 +372,6 @@ export function request(ctx) { | |
| const { args, request } = ctx; | ||
| const { graphqlApiEndpoint } = ctx.stash; | ||
|
|
||
| const toolDefinitions = {"tools":[{"name":"listTodos","description":"lists todos","inputSchema":{"json":{"type":"object","properties":{},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"items { content isDone id createdAt updatedAt owner } nextToken","propertyTypes":{},"queryName":"listTodos"}}]}; | ||
| const selectionSet = 'id conversationId content { image { format source { bytes }} text toolUse { toolUseId name input } toolResult { status toolUseId content { json text image { format source { bytes }} document { format name source { bytes }} }}} role owner createdAt updatedAt'; | ||
|
|
||
| const responseMutation = { | ||
|
|
@@ -382,20 +380,18 @@ export function request(ctx) { | |
| selectionSet, | ||
| }; | ||
| const currentMessageId = ctx.stash.defaultValues.id; | ||
|
|
||
| const modelConfiguration = { | ||
| modelId: 'anthropic.claude-3-haiku-20240307-v1:0', | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
|
|
||
| }; | ||
| modelId: "anthropic.claude-3-haiku-20240307-v1:0", | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
| inferenceConfiguration: undefined, | ||
| }; | ||
|
|
||
| const clientTools = args.toolConfiguration?.tools?.map((tool) => { | ||
| return { ...tool.toolSpec }; | ||
| }); | ||
| const dataTools = toolDefinitions.tools; | ||
| const toolsConfiguration = { | ||
| dataTools, | ||
| clientTools, | ||
| }; | ||
| const dataTools = [{"name":"listTodos","description":"lists todos","inputSchema":{"json":{"type":"object","properties":{},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"items { content isDone id createdAt updatedAt owner } nextToken","propertyTypes":{},"queryName":"listTodos"}}]; | ||
| const toolsConfiguration = { dataTools, clientTools }; | ||
|
|
||
| const messageHistoryQuery = { | ||
| getQueryName: 'getConversationMessagePirateChat', | ||
|
|
@@ -596,7 +592,6 @@ export function request(ctx) { | |
| const { args, request } = ctx; | ||
| const { graphqlApiEndpoint } = ctx.stash; | ||
|
|
||
| const toolDefinitions = {"tools":[{"name":"listCustomers","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 selectionSet = 'id conversationId content { image { format source { bytes }} text toolUse { toolUseId name input } toolResult { status toolUseId content { json text image { format source { bytes }} document { format name source { bytes }} }}} role owner createdAt updatedAt'; | ||
|
|
||
| const responseMutation = { | ||
|
|
@@ -605,20 +600,18 @@ export function request(ctx) { | |
| selectionSet, | ||
| }; | ||
| const currentMessageId = ctx.stash.defaultValues.id; | ||
|
|
||
| const modelConfiguration = { | ||
| modelId: 'anthropic.claude-3-haiku-20240307-v1:0', | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
|
|
||
| }; | ||
| modelId: "anthropic.claude-3-haiku-20240307-v1:0", | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
| inferenceConfiguration: undefined, | ||
| }; | ||
|
|
||
| const clientTools = args.toolConfiguration?.tools?.map((tool) => { | ||
| return { ...tool.toolSpec }; | ||
| }); | ||
| const dataTools = toolDefinitions.tools; | ||
| const toolsConfiguration = { | ||
| dataTools, | ||
| clientTools, | ||
| }; | ||
| const dataTools = [{"name":"listCustomers","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 = { | ||
| getQueryName: 'getConversationMessagePirateChat', | ||
|
|
@@ -819,7 +812,6 @@ export function request(ctx) { | |
| const { args, request } = ctx; | ||
| const { graphqlApiEndpoint } = ctx.stash; | ||
|
|
||
| const toolDefinitions = {"tools":[{"name":"getTemperature","description":"does a thing","inputSchema":{"json":{"type":"object","properties":{"city":{"type":"string","description":"A UTF-8 character sequence."}},"required":["city"]}},"graphqlRequestInputDescriptor":{"selectionSet":"value unit","propertyTypes":{"city":"String!"},"queryName":"getTemperature"}},{"name":"plus","description":"does a different thing","inputSchema":{"json":{"type":"object","properties":{"a":{"type":"number","description":"A signed 32-bit integer value."},"b":{"type":"number","description":"A signed 32-bit integer value."}},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"","propertyTypes":{"a":"Int","b":"Int"},"queryName":"plus"}}]}; | ||
| const selectionSet = 'id conversationId content { image { format source { bytes }} text toolUse { toolUseId name input } toolResult { status toolUseId content { json text image { format source { bytes }} document { format name source { bytes }} }}} role owner createdAt updatedAt'; | ||
|
|
||
| const responseMutation = { | ||
|
|
@@ -828,20 +820,18 @@ export function request(ctx) { | |
| selectionSet, | ||
| }; | ||
| const currentMessageId = ctx.stash.defaultValues.id; | ||
|
|
||
| const modelConfiguration = { | ||
| modelId: 'anthropic.claude-3-haiku-20240307-v1:0', | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
|
|
||
| }; | ||
| modelId: "anthropic.claude-3-haiku-20240307-v1:0", | ||
| systemPrompt: "You are a helpful chatbot. Answer questions to the best of your ability.", | ||
| inferenceConfiguration: undefined, | ||
| }; | ||
|
|
||
| const clientTools = args.toolConfiguration?.tools?.map((tool) => { | ||
| return { ...tool.toolSpec }; | ||
| }); | ||
| const dataTools = toolDefinitions.tools; | ||
| const toolsConfiguration = { | ||
| dataTools, | ||
| clientTools, | ||
| }; | ||
| const dataTools = [{"name":"getTemperature","description":"does a thing","inputSchema":{"json":{"type":"object","properties":{"city":{"type":"string","description":"A UTF-8 character sequence."}},"required":["city"]}},"graphqlRequestInputDescriptor":{"selectionSet":"value unit","propertyTypes":{"city":"String!"},"queryName":"getTemperature"}},{"name":"plus","description":"does a different thing","inputSchema":{"json":{"type":"object","properties":{"a":{"type":"number","description":"A signed 32-bit integer value."},"b":{"type":"number","description":"A signed 32-bit integer value."}},"required":[]}},"graphqlRequestInputDescriptor":{"selectionSet":"","propertyTypes":{"a":"Int","b":"Int"},"queryName":"plus"}}]; | ||
| const toolsConfiguration = { dataTools, clientTools }; | ||
|
|
||
| const messageHistoryQuery = { | ||
| getQueryName: 'getConversationMessagePirateChat', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { DataSourceProvider } from '@aws-amplify/graphql-transformer-interfaces'; | ||
| import { DirectiveNode, FieldDefinitionNode, InputObjectTypeDefinitionNode, ObjectTypeDefinitionNode } from 'graphql'; | ||
| import { ConversationModel } from './graphql-types/conversation-model'; | ||
| import { MessageModel } from './graphql-types/message-model'; | ||
| import { Tool } from './tools/process-tools'; | ||
|
|
||
| /** | ||
| * Configuration for the Conversation Directive | ||
| */ | ||
| export type ConversationDirectiveConfiguration = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidating directive configuration relevant types here. |
||
| // From the GraphQL Schema | ||
| parent: ObjectTypeDefinitionNode; | ||
| field: FieldDefinitionNode; | ||
| directive: DirectiveNode; | ||
|
|
||
| // Raw Directive Input | ||
| aiModel: string; | ||
| systemPrompt: string; | ||
| inferenceConfiguration: ConversationInferenceConfiguration | undefined; | ||
| tools: ToolDefinition[]; | ||
| /** | ||
| * Custom handler function name. | ||
| * | ||
| * @deprecated Replaced by 'handler' | ||
| */ | ||
| functionName: string | undefined; | ||
| handler: ConversationHandlerFunctionConfiguration | undefined; | ||
|
|
||
| // Generated within the Conversation Transformer | ||
| toolSpec: Tool[] | undefined; | ||
| conversation: ConversationModel; | ||
| message: MessageModel; | ||
| assistantResponseMutation: { field: FieldDefinitionNode; input: InputObjectTypeDefinitionNode }; | ||
| assistantResponseSubscriptionField: FieldDefinitionNode; | ||
| dataSources: ConversationDirectiveDataSources; | ||
palpatim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| /** | ||
| * Conversation Directive Handler Function Configuration | ||
| */ | ||
| export type ConversationHandlerFunctionConfiguration = { | ||
| functionName: string; | ||
| eventVersion: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Conversation Directive Inference Configuration | ||
| */ | ||
| export type ConversationInferenceConfiguration = { | ||
| maxTokens?: number; | ||
| temperature?: number; | ||
| topP?: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Conversation Directive Tool Definition | ||
| */ | ||
| export type ToolDefinition = { | ||
| name: string; | ||
| description: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Conversation Directive Data Sources | ||
| */ | ||
| export type ConversationDirectiveDataSources = { | ||
| lambdaFunctionDataSource: DataSourceProvider; | ||
| messageTableDataSource: DataSourceProvider; | ||
| conversationTableDataSource: DataSourceProvider; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are from
JSON.stringify(...)(''-->"") and maintaining proper indentation.