Skip to content

Commit

Permalink
update test cases for new supporting type names
Browse files Browse the repository at this point in the history
  • Loading branch information
atierian committed Nov 14, 2024
1 parent 92f8c53 commit ce81d20
Show file tree
Hide file tree
Showing 24 changed files with 2,102 additions and 499 deletions.
2,177 changes: 1,885 additions & 292 deletions packages/amplify-graphql-api-construct-tests/src/__tests__/conversations/API.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { createCognitoUser, signInCognitoUser, TestDefinition, writeStackConfig,
import { AppSyncSubscriptionClient, mergeNamedAsyncIterators } from '../../utils/appsync-graphql/subscription';
import { DURATION_20_MINUTES, DURATION_5_MINUTES, ONE_MINUTE } from '../../utils/duration-constants';
import {
ContentBlock,
ConversationMessageStreamPart,
AmplifyAIContentBlock,
AmplifyAIConversationMessageStreamPart,
OnCreateAssistantResponsePirateChatSubscription,
ToolConfigurationInput,
AmplifyAIToolConfigurationInput,
} from './API';
import { onCreateAssistantResponseDisabledModelChat, onCreateAssistantResponsePirateChat } from './graphql/subscriptions';
import {
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('conversation', () => {
expect(message.content[0].text).toEqual('Hello, world!');
expect(message.conversationId).toEqual(conversationId);

const events: ConversationMessageStreamPart[] = [];
const events: AmplifyAIConversationMessageStreamPart[] = [];
// expect to receive the assistant response in the subscription
for await (const event of subscription) {
events.push(event.onCreateAssistantResponsePirateChat);
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('conversation', () => {
});

// define the client tool configuration
const toolConfiguration: ToolConfigurationInput = {
const toolConfiguration: AmplifyAIToolConfigurationInput = {
tools: [
{
toolSpec: {
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('conversation', () => {
expect(message1.toolConfiguration).toEqual(toolConfiguration);

// expect to receive the assistant response including a toolUse block in the subscription
const events: ConversationMessageStreamPart[] = [];
const events: AmplifyAIConversationMessageStreamPart[] = [];
for await (const event of subscription) {
events.push(event.onCreateAssistantResponsePirateChat);
if (event.onCreateAssistantResponsePirateChat.stopReason) break;
Expand Down Expand Up @@ -608,7 +608,7 @@ const deployCdk = async (projRoot: string): Promise<{ apiEndpoint: string; userP
return { apiEndpoint: awsAppsyncApiEndpoint, userPoolClientId: UserPoolClientId, userPoolId: UserPoolId };
};

const reconcileStreamEvents = (events: ConversationMessageStreamPart[]): ContentBlock[] => {
const reconcileStreamEvents = (events: AmplifyAIConversationMessageStreamPart[]): AmplifyAIContentBlock[] => {
return events
.sort((a, b) => {
let aValue = a.contentBlockIndex * 1000 + (a.contentBlockDeltaIndex || 0);
Expand All @@ -626,5 +626,5 @@ const reconcileStreamEvents = (events: ConversationMessageStreamPart[]): Content
acc[event.contentBlockIndex] = { toolUse: event.contentBlockToolUse };
}
return acc;
}, [] as ContentBlock[]);
}, [] as AmplifyAIContentBlock[]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ export const deleteConversationPirateChat = /* GraphQL */ `mutation DeleteConver

export const disabledModelChat = /* GraphQL */ `mutation DisabledModelChat(
$aiContext: AWSJSON
$content: [ContentBlockInput]
$content: [AmplifyAIContentBlockInput]
$conversationId: ID!
$toolConfiguration: ToolConfigurationInput
$toolConfiguration: AmplifyAIToolConfigurationInput
) {
disabledModelChat(
aiContext: $aiContext
Expand Down Expand Up @@ -408,9 +408,9 @@ export const disabledModelChat = /* GraphQL */ `mutation DisabledModelChat(

export const pirateChat = /* GraphQL */ `mutation PirateChat(
$aiContext: AWSJSON
$content: [ContentBlockInput]
$content: [AmplifyAIContentBlockInput]
$conversationId: ID!
$toolConfiguration: ToolConfigurationInput
$toolConfiguration: AmplifyAIToolConfigurationInput
) {
pirateChat(
aiContext: $aiContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
type Mutation {
pirateChat(
conversationId: ID!
content: [ContentBlockInput]
content: [AmplifyAIContentBlockInput]
aiContext: AWSJSON
toolConfiguration: ToolConfigurationInput
): ConversationMessage
toolConfiguration: AmplifyAIToolConfigurationInput
): AmplifyAIConversationMessage
@conversation(
aiModel: "anthropic.claude-3-haiku-20240307-v1:0"
systemPrompt: "You are a helpful chatbot that responds in the voice and tone of a pirate. Respond in 20 words or less."
Expand All @@ -14,10 +14,10 @@ type Mutation {

disabledModelChat(
conversationId: ID!
content: [ContentBlockInput]
content: [AmplifyAIContentBlockInput]
aiContext: AWSJSON
toolConfiguration: ToolConfigurationInput
): ConversationMessage
toolConfiguration: AmplifyAIToolConfigurationInput
): AmplifyAIConversationMessage
@conversation(
aiModel: "mistral.mistral-large-2407-v1:0"
systemPrompt: "You are a helpful chatbot."
Expand All @@ -26,186 +26,187 @@ type Mutation {
@aws_cognito_user_pools
}

enum ConversationParticipantRole {
enum AmplifyAIConversationParticipantRole {
user
assistant
}

interface ConversationMessage {
interface AmplifyAIConversationMessage {
id: ID!
conversationId: ID!
role: ConversationParticipantRole
content: [ContentBlock]
associatedUserMessageId: ID
role: AmplifyAIConversationParticipantRole
content: [AmplifyAIContentBlock]
aiContext: AWSJSON
toolConfiguration: ToolConfiguration
toolConfiguration: AmplifyAIToolConfiguration
createdAt: AWSDateTime
updatedAt: AWSDateTime
owner: String
}

input DocumentBlockSourceInput {
input AmplifyAIDocumentBlockSourceInput {
bytes: String
}

input DocumentBlockInput {
input AmplifyAIDocumentBlockInput {
format: String!
name: String!
source: DocumentBlockSourceInput!
source: AmplifyAIDocumentBlockSourceInput!
}

input ImageBlockSourceInput {
input AmplifyAIImageBlockSourceInput {
bytes: String
}

input ImageBlockInput {
input AmplifyAIImageBlockInput {
format: String!
source: ImageBlockSourceInput!
source: AmplifyAIImageBlockSourceInput!
}

input ToolUseBlockInput {
input AmplifyAIToolUseBlockInput {
toolUseId: String!
name: String!
input: AWSJSON!
}

input ToolResultContentBlockInput {
document: DocumentBlockInput
image: ImageBlockInput
input AmplifyAIToolResultContentBlockInput {
document: AmplifyAIDocumentBlockInput
image: AmplifyAIImageBlockInput
json: AWSJSON
text: String
}

input ToolResultBlockInput {
content: [ToolResultContentBlockInput!]!
input AmplifyAIToolResultBlockInput {
content: [AmplifyAIToolResultContentBlockInput!]!
toolUseId: String!
status: String
}

type DocumentBlockSource {
type AmplifyAIDocumentBlockSource {
bytes: String
}

type DocumentBlock {
type AmplifyAIDocumentBlock {
format: String!
name: String!
source: DocumentBlockSource!
source: AmplifyAIDocumentBlockSource!
}

type ImageBlock {
type AmplifyAIImageBlock {
format: String!
source: ImageBlockSource!
source: AmplifyAIImageBlockSource!
}

type ImageBlockSource {
type AmplifyAIImageBlockSource {
bytes: String
}

type ToolUseBlock {
type AmplifyAIToolUseBlock {
toolUseId: String!
name: String!
input: AWSJSON!
}

type ToolResultContentBlock {
document: DocumentBlock
image: ImageBlock
type AmplifyAIToolResultContentBlock {
document: AmplifyAIDocumentBlock
image: AmplifyAIImageBlock
json: AWSJSON
text: String
}

type ToolResultBlock {
content: [ToolResultContentBlock!]!
type AmplifyAIToolResultBlock {
content: [AmplifyAIToolResultContentBlock!]!
toolUseId: String!
status: String
}

type ContentBlockText {
type AmplifyAIContentBlockText {
text: String
}

type ContentBlockImage {
image: ImageBlock
type AmplifyAIContentBlockImage {
image: AmplifyAIImageBlock
}

type ContentBlockDocument {
document: DocumentBlock
type AmplifyAIContentBlockDocument {
document: AmplifyAIDocumentBlock
}

type ContentBlockToolUse {
toolUse: ToolUseBlock
type AmplifyAIContentBlockToolUse {
toolUse: AmplifyAIToolUseBlock
}

type ContentBlockToolResult {
toolResult: ToolResultBlock
type AmplifyAIContentBlockToolResult {
toolResult: AmplifyAIToolResultBlock
}

input ContentBlockInput {
input AmplifyAIContentBlockInput {
text: String
document: DocumentBlockInput
image: ImageBlockInput
toolResult: ToolResultBlockInput
toolUse: ToolUseBlockInput
document: AmplifyAIDocumentBlockInput
image: AmplifyAIImageBlockInput
toolResult: AmplifyAIToolResultBlockInput
toolUse: AmplifyAIToolUseBlockInput
}

type ContentBlock {
type AmplifyAIContentBlock {
text: String
document: DocumentBlock
image: ImageBlock
toolResult: ToolResultBlock
toolUse: ToolUseBlock
document: AmplifyAIDocumentBlock
image: AmplifyAIImageBlock
toolResult: AmplifyAIToolResultBlock
toolUse: AmplifyAIToolUseBlock
}

input ToolConfigurationInput {
tools: [ToolInput]
input AmplifyAIToolConfigurationInput {
tools: [AmplifyAIToolInput]
}

input ToolInput {
toolSpec: ToolSpecificationInput
input AmplifyAIToolInput {
toolSpec: AmplifyAIToolSpecificationInput
}

input ToolSpecificationInput {
input AmplifyAIToolSpecificationInput {
name: String!
description: String
inputSchema: ToolInputSchemaInput!
inputSchema: AmplifyAIToolInputSchemaInput!
}

input ToolInputSchemaInput {
input AmplifyAIToolInputSchemaInput {
json: AWSJSON
}

type ToolConfiguration {
tools: [Tool]
type AmplifyAIToolConfiguration {
tools: [AmplifyAITool]
}

type Tool {
toolSpec: ToolSpecification
type AmplifyAITool {
toolSpec: AmplifyAIToolSpecification
}

type ToolSpecification {
type AmplifyAIToolSpecification {
name: String!
description: String
inputSchema: ToolInputSchema!
inputSchema: AmplifyAIToolInputSchema!
}

type ToolInputSchema {
type AmplifyAIToolInputSchema {
json: AWSJSON
}

type ConversationMessageStreamPart {
type AmplifyAIConversationMessageStreamPart @aws_cognito_user_pools {
id: ID!
owner: String
conversationId: ID!
associatedUserMessageId: ID!
contentBlockIndex: Int
contentBlockText: String
contentBlockDeltaIndex: Int
contentBlockToolUse: ToolUseBlock
contentBlockToolUse: AmplifyAIToolUseBlock
contentBlockDoneAtIndex: Int
stopReason: String
errors: [ConversationTurnError]
errors: [AmplifyAIConversationTurnError]
}

type ConversationTurnError {
type AmplifyAIConversationTurnError @aws_cognito_user_pools {
message: String!
errorType: String!
}
Loading

0 comments on commit ce81d20

Please sign in to comment.