-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a697ea
commit d65cea0
Showing
24 changed files
with
311 additions
and
329 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
"@aws-amplify/ui-react-ai": minor | ||
--- | ||
|
||
|
||
The AIConversation component is now composable if you are using the default component or the headless component using `createAIConversation()`. There are 4 parts: | ||
|
||
* Provider: provides all the necessary data/handlers for the composable components | ||
* Messages: the message history for the conversation | ||
* DefaultMessage: contains an optional welcome message and prompt suggestions, only shown if no messages present | ||
* Form: the form for sending messages, includes the text input, submit button, and attachments | ||
|
||
```jsx | ||
function Chat() { | ||
const [ | ||
{ | ||
data: { messages }, | ||
isLoading, | ||
}, | ||
sendMessage, | ||
] = useAIConversation('pirateChat'); | ||
|
||
return ( | ||
<AIConversation.Provider | ||
messages={messages} | ||
handleSendMessage={sendMessage} | ||
isLoading={isLoading} | ||
> | ||
<Flex direction="row"> | ||
<Card variation="outlined" width="50%" flex="1"> | ||
<AIConversation.DefaultMessage /> | ||
<AIConversation.Messages /> | ||
</Card> | ||
<Card variation="outlined" width="50%" flex="1"> | ||
<AIConversation.Form /> | ||
</Card> | ||
</Flex> | ||
</AIConversation.Provider> | ||
); | ||
} | ||
``` |
2 changes: 2 additions & 0 deletions
2
examples/next/pages/ui/components/ai/ai-conversation-composable/amplify_outputs.js
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,2 @@ | ||
import amplifyOutputs from '@environments/ai/gen2/amplify_outputs'; | ||
export default amplifyOutputs; |
56 changes: 56 additions & 0 deletions
56
examples/next/pages/ui/components/ai/ai-conversation-composable/index.page.tsx
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,56 @@ | ||
import * as React from 'react'; | ||
import { Amplify } from 'aws-amplify'; | ||
import { createAIHooks, AIConversation } from '@aws-amplify/ui-react-ai'; | ||
import { generateClient } from 'aws-amplify/api'; | ||
import '@aws-amplify/ui-react/styles.css'; | ||
import '@aws-amplify/ui-react-ai/ai-conversation-styles.css'; | ||
|
||
import outputs from './amplify_outputs'; | ||
import type { Schema } from '@environments/ai/gen2/amplify/data/resource'; | ||
import { Authenticator, Card, Flex } from '@aws-amplify/ui-react'; | ||
|
||
const client = generateClient<Schema>({ authMode: 'userPool' }); | ||
const { useAIConversation } = createAIHooks(client); | ||
|
||
Amplify.configure(outputs); | ||
|
||
function Chat() { | ||
const [ | ||
{ | ||
data: { messages }, | ||
isLoading, | ||
}, | ||
sendMessage, | ||
] = useAIConversation('pirateChat'); | ||
|
||
return ( | ||
<AIConversation.Provider | ||
messages={messages} | ||
handleSendMessage={sendMessage} | ||
isLoading={isLoading} | ||
avatars={{ | ||
user: { | ||
username: 'XXXX', | ||
}, | ||
}} | ||
> | ||
<Flex direction="row"> | ||
<Card variation="outlined" width="50%" flex="1"> | ||
<AIConversation.DefaultMessage /> | ||
<AIConversation.Messages /> | ||
</Card> | ||
<Card variation="outlined" width="50%" flex="1"> | ||
<AIConversation.Form /> | ||
</Card> | ||
</Flex> | ||
</AIConversation.Provider> | ||
); | ||
} | ||
|
||
export default function Example() { | ||
return ( | ||
<Authenticator> | ||
<Chat /> | ||
</Authenticator> | ||
); | ||
} |
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
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
20 changes: 20 additions & 0 deletions
20
packages/react-ai/src/components/AIConversation/context/WelcomeMessageContext.tsx
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,20 @@ | ||
import * as React from 'react'; | ||
|
||
type WelcomeMessageContextProps = React.ReactNode | undefined; | ||
|
||
export const WelcomeMessageContext = | ||
React.createContext<WelcomeMessageContextProps>(undefined); | ||
|
||
export const WelcomeMessageProvider = ({ | ||
children, | ||
welcomeMessage, | ||
}: { | ||
children?: React.ReactNode; | ||
welcomeMessage?: React.ReactNode; | ||
}): JSX.Element => { | ||
return ( | ||
<WelcomeMessageContext.Provider value={welcomeMessage}> | ||
{children} | ||
</WelcomeMessageContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.