-
Notifications
You must be signed in to change notification settings - Fork 79
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
chore: move json schema generation for tool use into transformer-core #2824
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48cd860
move json schema generation for tool use into transformer-core
atierian 3145285
adjust branches threshold. not sure why needed
atierian 61e17cd
fix typo in inline comment
atierian c8df1ef
lint
atierian 6712dac
update api extract for generation and transformer-core
atierian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/amplify-graphql-generation-transformer/src/utils/tools.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...graphql-scalar-json-schema-definitions.ts → ...graphql-scalar-json-schema-definitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/amplify-graphql-transformer-core/src/utils/ai/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type { JSONSchema } from './json-schema'; | ||
export { isDisallowedScalarType, supportedScalarTypes, GraphQLScalarJSONSchemaDefinition } from './graphql-scalar-json-schema-definitions'; | ||
export { convertNamedTypeToJSONSchema } from './named-type-conversion'; |
18 changes: 18 additions & 0 deletions
18
packages/amplify-graphql-transformer-core/src/utils/ai/json-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type JSONSchema = { | ||
type: string; | ||
properties?: Record<string, JSONSchema>; | ||
required?: string[]; | ||
items?: JSONSchema; | ||
enum?: (string | number | boolean | null)[]; | ||
minimum?: number; | ||
maximum?: number; | ||
minLength?: number; | ||
maxLength?: number; | ||
pattern?: string; | ||
format?: string; | ||
description?: string; | ||
default?: JSONLike; | ||
additionalProperties?: boolean | JSONSchema; | ||
}; | ||
|
||
type JSONLike = string | number | boolean | null | { [key: string]: JSONLike } | JSONLike[]; |
47 changes: 47 additions & 0 deletions
47
packages/amplify-graphql-transformer-core/src/utils/ai/named-type-conversion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { NamedTypeNode } from 'graphql'; | ||
import { JSONSchema } from './json-schema'; | ||
import { GraphQLScalarJSONSchemaDefinition } from './graphql-scalar-json-schema-definitions'; | ||
|
||
/** | ||
* Processes a NamedTypeNode and returns the corresponding JSON Schema. | ||
* @param {NamedTypeNode} namedType - The NamedTypeNode to process. | ||
* @returns {JSONSchema} The JSON Schema representation of the named type. | ||
*/ | ||
export const convertNamedTypeToJSONSchema = (namedType: NamedTypeNode): JSONSchema => { | ||
switch (namedType.name.value) { | ||
case 'Int': | ||
return GraphQLScalarJSONSchemaDefinition.Int; | ||
case 'Float': | ||
return GraphQLScalarJSONSchemaDefinition.Float; | ||
case 'String': | ||
return GraphQLScalarJSONSchemaDefinition.String; | ||
case 'ID': | ||
return GraphQLScalarJSONSchemaDefinition.ID; | ||
case 'Boolean': | ||
return GraphQLScalarJSONSchemaDefinition.Boolean; | ||
case 'AWSJSON': | ||
return GraphQLScalarJSONSchemaDefinition.AWSJSON; | ||
case 'AWSEmail': | ||
return GraphQLScalarJSONSchemaDefinition.AWSEmail; | ||
case 'AWSDate': | ||
return GraphQLScalarJSONSchemaDefinition.AWSDate; | ||
case 'AWSTime': | ||
return GraphQLScalarJSONSchemaDefinition.AWSTime; | ||
case 'AWSDateTime': | ||
return GraphQLScalarJSONSchemaDefinition.AWSDateTime; | ||
case 'AWSTimestamp': | ||
return GraphQLScalarJSONSchemaDefinition.AWSTimestamp; | ||
case 'AWSPhone': | ||
return GraphQLScalarJSONSchemaDefinition.AWSPhone; | ||
case 'AWSURL': | ||
return GraphQLScalarJSONSchemaDefinition.AWSURL; | ||
case 'AWSIPAddress': | ||
return GraphQLScalarJSONSchemaDefinition.AWSIPAddress; | ||
default: | ||
return { | ||
type: 'object', | ||
properties: {}, | ||
required: [], | ||
}; | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not sure why this was necessary. Will figure it out in a follow up -- for now it's still well above the 80% threshold.