Skip to content

Conversation

@atierian
Copy link
Contributor

@atierian atierian commented Oct 15, 2024

Description of changes

  • Consolidates regex substitution for JS resolver templates in single place.
  • Moves resolvers/*.template.js files to resolvers/templates/*.template.js
  • Defines ResolverFunctionDefinition and PipelineDefinition types to allow function and pipeline definitions to live as configuration rather than runtime logic.
  • Reworks invoke-lambda function template to remove the need for string defined JS resolver blocks in runtime code.
  • Shuffles a few type and function definitions around for file hygiene.
  • Removes any relics of "session" (property names, inline documentation) for conversation model.
  • Sorts import statements.

CDK / CloudFormation Parameters Changed

N/A

Issue #, if available

N/A

Description of how you validated changes

CI PR workflow
E2E run

Checklist

  • PR description included
  • yarn test passes
  • E2E test run linked
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Any CDK or CloudFormation parameter changes are called out explicitly

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment on lines +165 to +168
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},
};
Copy link
Contributor Author

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.

Comment on lines +173 to +174
const dataTools = undefined;
const toolsConfiguration = { dataTools, clientTools };
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

/**
* Configuration for the Conversation Directive
*/
export type ConversationDirectiveConfiguration = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidating directive configuration relevant types here.

import pluralize from 'pluralize';
import { ConversationDirectiveConfiguration } from '../conversation-directive-configuration';

export const CONVERSATION_MESSAGES_REFERENCE_FIELD_NAME = 'conversationId';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidating strings needed in various places and often multiple times.

Comment on lines -12 to -13
export type Tools = {
tools: Tool[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type was unnecessary.

Comment on lines -118 to -135
validate = (): void => {
for (const directive of this.directives) {
if (directive.field.type.kind !== 'NamedType' || directive.field.type.name.value !== 'ConversationMessage') {
throw new InvalidDirectiveError('@conversation return type must be ConversationMessage');
}
if (directive.handler && directive.functionName) {
throw new InvalidDirectiveError("'functionName' and 'handler' are mutually exclusive");
}
if (directive.handler) {
const eventVersion = semver.coerce(directive.handler.eventVersion);
if (eventVersion?.major !== 1) {
throw new Error(
`Unsupported custom conversation handler. Expected eventVersion to match 1.x, received ${directive.handler.eventVersion}`,
);
}
}
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This validation logic was moved to conversation-field-handler.ts where existing validation logic lives.

*/
function data(): ResolverFunctionDefinition {
return createResolverFunctionDefinition({
slotName: 'data',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name 'data' for this slot follows requirements set by TransformerResolver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These now live as ResolverFunctionDefinitions. For example, this one is the data() definition within assistant-response-pipeline-definition.ts.

palpatim
palpatim previously approved these changes Oct 21, 2024
Comment on lines 16 to 20
* @property {DirectiveNode} conversationAuthDirective - The auth directive for the conversation model.
* @property {DirectiveNode} conversationModelDirective - The model directive for the conversation model.
* @property {DirectiveNode} conversationDirective - The model directive for the conversation model.
* @property {DirectiveNode} conversationHasManyMessagesDirective - The has-many directive for the messages relationship.
* @property {FieldDefinitionNode} conversationMessagesField - The field definition for the messages relationship.
* @property {ObjectTypeDefinitionNode} conversationModel - The complete conversation model object type definition.
* @property {ObjectTypeDefinitionNode} conversation - The complete conversation model object type definition.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. nit: doccomment names don't match field names.
  2. nit: When I first read this I assumed this was the TS representation of the model object itself, and wasn't until I dug into it further that I realized that shape was actually not represented at all. What is this structure actually representing? The model should have the directives and fields on it -- is this just to hoist them into a dedicated property to make them easier to work with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Thanks for catching that. Addressed in a3111dc
  2. The properties represent GraphQL document nodes (DirectiveNode, FieldDefinitionNode, ObjectTypeDefinitionNode, etc) that are required input for APIs exposed by dependent transformers (model / relational / auth). For example, the modelDirective within ConversationModel is used when invoking modelTransformer.object. The alternative is passing around only the ObjectTypeDefinitionNode and extracting the other nodes as needed, but that leads to some gnarly and difficult to maintain code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong objections, but I'll note that if we need more transformers to operate on a the conversation model, you'll have to hoist more & more properties into this model structure. I suppose it's not all that different from writing utility methods to extract same, except that you're carrying the properties around everywhere rather than invoking a utility method when needed. I'll chalk this up to a stylistic preference & move on. :)

palpatim
palpatim previously approved these changes Oct 22, 2024
sundersc
sundersc previously approved these changes Oct 22, 2024
* @throws {InvalidDirectiveError} If the configuration is invalid.
*/
private validateHandler(config: ConversationDirectiveConfiguration): void {
if (config.handler && config.functionName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could remove functionName at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'll follow up with that. This PR is exclusively non-functional changes and considering its size, I'd like to keep it that way.

@atierian atierian dismissed stale reviews from sundersc and palpatim via 61052fe October 23, 2024 12:49
@atierian atierian enabled auto-merge (squash) October 23, 2024 14:56
@atierian atierian merged commit c85975b into main Oct 23, 2024
7 checks passed
@atierian atierian deleted the ai.conversation-consolidate-resolver-generation branch October 23, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants