Skip to content

Commit

Permalink
chore: get ai package ready for release (#6149)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanksdesign authored Nov 19, 2024
1 parent 90ea18b commit 0d4d2b9
Show file tree
Hide file tree
Showing 18 changed files with 191 additions and 197 deletions.
7 changes: 7 additions & 0 deletions .changeset/smart-otters-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@aws-amplify/ui-react-ai": major
"@aws-amplify/ui-react": patch
"@aws-amplify/ui": patch
---

chore: get ai package ready for release
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { AIConversation, ConversationMessage } from '@aws-amplify/ui-react-ai';
import '@aws-amplify/ui-react/styles.css';

const messages: ConversationMessage[] = [
{
role: 'user',
content: [
{
text: 'hello',
},
{
image: {
format: 'png',
source: {
bytes: new Uint8Array([
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0,
0, 0, 28, 0, 0, 0, 28, 8, 3, 0, 0, 0, 69, 211, 47, 166, 0, 0, 0,
168, 80, 76, 84, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64,
0, 51, 51, 26, 26, 26, 23, 23, 46, 20, 20, 39, 18, 18, 36, 12, 24,
36, 9, 26, 35, 15, 23, 38, 15, 29, 36, 12, 23, 41, 11, 28, 40, 13,
26, 38, 12, 27, 39, 15, 26, 36, 14, 25, 39, 14, 24, 38, 13, 26,
36, 13, 27, 38, 12, 27, 39, 12, 27, 37, 12, 27, 37, 12, 27, 39,
12, 26, 38, 14, 26, 38, 13, 26, 38, 12, 26, 39, 13, 27, 38, 13,
27, 38, 12, 26, 39, 14, 26, 38, 13, 26, 38, 13, 26, 38, 13, 26,
38, 13, 26, 38, 13, 26, 38, 13, 26, 38, 13, 26, 38, 13, 27, 38,
12, 26, 39, 14, 26, 38, 13, 26, 38, 13, 26, 38, 13, 26, 38, 12,
26, 39, 13, 26, 38, 13, 26, 38, 13, 26, 38, 13, 26, 38, 13, 26,
38, 13, 26, 38, 255, 255, 255, 26, 7, 228, 96, 0, 0, 0, 54, 116,
82, 78, 83, 0, 1, 2, 3, 4, 5, 10, 11, 13, 14, 21, 29, 34, 35, 44,
45, 60, 65, 70, 72, 73, 77, 95, 105, 123, 124, 125, 126, 128, 135,
145, 153, 162, 165, 170, 174, 175, 176, 179, 209, 215, 220, 221,
225, 226, 228, 229, 243, 245, 247, 249, 250, 252, 253, 138, 189,
133, 44, 0, 0, 0, 1, 98, 75, 71, 68, 55, 48, 184, 184, 71, 0, 0,
0, 214, 73, 68, 65, 84, 40, 207, 125, 147, 233, 22, 130, 32, 16,
133, 49, 181, 210, 74, 203, 74, 219, 168, 44, 91, 21, 211, 22,
222, 255, 209, 82, 212, 57, 160, 232, 253, 197, 229, 67, 206, 48,
115, 69, 136, 147, 110, 219, 26, 146, 75, 245, 98, 74, 137, 167,
202, 216, 236, 70, 153, 238, 139, 6, 26, 29, 41, 232, 58, 17, 208,
96, 151, 82, 78, 159, 189, 1, 72, 113, 227, 114, 55, 140, 202, 69,
236, 42, 101, 141, 151, 234, 139, 196, 52, 147, 106, 29, 232, 12,
110, 225, 58, 31, 33, 31, 204, 154, 193, 39, 120, 7, 33, 7, 204,
131, 193, 95, 101, 73, 246, 68, 149, 84, 238, 203, 32, 156, 197,
185, 195, 96, 121, 72, 240, 48, 119, 6, 38, 117, 152, 158, 150,
208, 213, 222, 244, 240, 226, 97, 104, 138, 253, 50, 35, 14, 70,
93, 176, 243, 218, 162, 32, 163, 165, 160, 214, 167, 116, 54, 161,
179, 125, 27, 121, 227, 87, 197, 200, 2, 217, 200, 206, 122, 125,
216, 81, 99, 216, 153, 250, 98, 76, 222, 92, 76, 26, 1, 27, 183,
71, 115, 46, 15, 53, 105, 13, 117, 38, 205, 178, 132, 223, 225,
15, 14, 216, 81, 244, 178, 122, 71, 86, 0, 0, 0, 0, 73, 69, 78,
68, 174, 66, 96, 130,
]),
},
},
},
],
conversationId: '1',
id: '2',
createdAt: new Date(2023, 4, 21, 15, 24).toDateString(),
},
{
role: 'assistant',
content: [
{
toolUse: {
name: 'AMPLIFY_UI_foobar',
input: { foo: 'bar' },
toolUseId: '1234',
},
},
],
conversationId: '1',
id: '2',
createdAt: new Date(2023, 4, 21, 15, 24).toDateString(),
},
];

export default function Example() {
return <AIConversation messages={messages} handleSendMessage={() => {}} />;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Flex, ScrollView, Text } from '@aws-amplify/ui-react';
import { Flex, ScrollView } from '@aws-amplify/ui-react';
import {
IconAssistant,
IconUser,
Expand Down Expand Up @@ -55,9 +55,6 @@ function AIConversationBase({
...defaultAvatars,
...avatars,
},
elements: {
Text,
},
controls: {
MessageList,
PromptList,
Expand All @@ -82,9 +79,6 @@ function AIConversationBase({
);
}

/**
* @experimental
*/
export const AIConversation: AIConversationType<AIConversationBaseProps> =
Object.assign(AIConversationBase, {
Provider: AIConversationProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import React from 'react';

import { ElementsProvider } from '@aws-amplify/ui-react-core/elements';

import { AIConversationInput, AIConversationProps } from './types';
import { defaultAIConversationDisplayTextEn } from './displayText';
import {
ConversationDisplayTextProvider,
SuggestedPromptProvider,
ConversationInputContextProvider,
AvatarsProvider,
ActionsProvider,
MessageVariantProvider,
MessagesProvider,
AIContextProvider,
AttachmentProvider,
AvatarsProvider,
ControlsProvider,
ConversationDisplayTextProvider,
ConversationInputContextProvider,
FallbackComponentProvider,
LoadingContextProvider,
MessageRendererProvider,
MessagesProvider,
MessageVariantProvider,
ResponseComponentsProvider,
SendMessageContextProvider,
SuggestedPromptProvider,
WelcomeMessageProvider,
FallbackComponentProvider,
MessageRendererProvider,
AIContextProvider,
} from './context';
import { AttachmentProvider } from './context/AttachmentContext';

export interface AIConversationProviderProps
extends AIConversationInput,
Expand All @@ -37,7 +35,6 @@ export const AIConversationProvider = ({
children,
controls,
displayText,
elements,
handleSendMessage,
isLoading,
messages,
Expand All @@ -53,51 +50,47 @@ export const AIConversationProvider = ({
...displayText,
};
return (
<ElementsProvider elements={elements}>
<ControlsProvider controls={controls}>
<SuggestedPromptProvider suggestedPrompts={suggestedPrompts}>
<WelcomeMessageProvider welcomeMessage={welcomeMessage}>
<FallbackComponentProvider
FallbackComponent={FallbackResponseComponent}
>
<MessageRendererProvider {...messageRenderer}>
<ResponseComponentsProvider
responseComponents={responseComponents}
>
<AttachmentProvider allowAttachments={allowAttachments}>
<ConversationDisplayTextProvider {..._displayText}>
<ConversationInputContextProvider>
<SendMessageContextProvider
handleSendMessage={handleSendMessage}
>
<AvatarsProvider avatars={avatars}>
<ActionsProvider actions={actions}>
<MessageVariantProvider variant={variant}>
<MessagesProvider messages={messages}>
{/* aiContext should be as close as possible to the bottom */}
{/* because the intent is users should update the context */}
{/* without it affecting the already rendered messages */}
<AIContextProvider aiContext={aiContext}>
<LoadingContextProvider
isLoading={isLoading}
>
{children}
</LoadingContextProvider>
</AIContextProvider>
</MessagesProvider>
</MessageVariantProvider>
</ActionsProvider>
</AvatarsProvider>
</SendMessageContextProvider>
</ConversationInputContextProvider>
</ConversationDisplayTextProvider>
</AttachmentProvider>
</ResponseComponentsProvider>
</MessageRendererProvider>
</FallbackComponentProvider>
</WelcomeMessageProvider>
</SuggestedPromptProvider>
</ControlsProvider>
</ElementsProvider>
<ControlsProvider controls={controls}>
<SuggestedPromptProvider suggestedPrompts={suggestedPrompts}>
<WelcomeMessageProvider welcomeMessage={welcomeMessage}>
<FallbackComponentProvider
FallbackComponent={FallbackResponseComponent}
>
<MessageRendererProvider {...messageRenderer}>
<ResponseComponentsProvider
responseComponents={responseComponents}
>
<AttachmentProvider allowAttachments={allowAttachments}>
<ConversationDisplayTextProvider {..._displayText}>
<ConversationInputContextProvider>
<SendMessageContextProvider
handleSendMessage={handleSendMessage}
>
<AvatarsProvider avatars={avatars}>
<ActionsProvider actions={actions}>
<MessageVariantProvider variant={variant}>
<MessagesProvider messages={messages}>
{/* aiContext should be as close as possible to the bottom */}
{/* because the intent is users should update the context */}
{/* without it affecting the already rendered messages */}
<AIContextProvider aiContext={aiContext}>
<LoadingContextProvider isLoading={isLoading}>
{children}
</LoadingContextProvider>
</AIContextProvider>
</MessagesProvider>
</MessageVariantProvider>
</ActionsProvider>
</AvatarsProvider>
</SendMessageContextProvider>
</ConversationInputContextProvider>
</ConversationDisplayTextProvider>
</AttachmentProvider>
</ResponseComponentsProvider>
</MessageRendererProvider>
</FallbackComponentProvider>
</WelcomeMessageProvider>
</SuggestedPromptProvider>
</ControlsProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ControlsContextProps {
{
handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
allowAttachments?: boolean;
isLoading?: boolean;
} & Required<ConversationInputContext>
>;
MessageList?: React.ComponentType<{ messages: ConversationMessage[] }>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ import { ViewElement as View } from './context/elements/definitions';
import { AIConversationProvider } from './AIConversationProvider';
import { DefaultMessageControl } from './views/Controls/DefaultMessageControl';

/**
* @experimental
*/
export function createAIConversation(input: AIConversationInput = {}): {
AIConversation: AIConversation;
} {
const {
elements,
suggestedPrompts,
actions,
responseComponents,
Expand All @@ -31,7 +27,6 @@ export function createAIConversation(input: AIConversationInput = {}): {
function AIConversation(props: AIConversationProps): JSX.Element {
const { messages, avatars, handleSendMessage, isLoading } = props;
const providerProps = {
elements,
actions,
suggestedPrompts,
responseComponents,
Expand Down
2 changes: 0 additions & 2 deletions packages/react-ai/src/components/AIConversation/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import { AIConversationElements } from './context/elements';
import {
ActionsBarControl,
AvatarControl,
Expand Down Expand Up @@ -29,7 +28,6 @@ export interface Controls {
}

export interface AIConversationInput {
elements?: Partial<AIConversationElements>;
displayText?: DisplayTextTemplate<AIConversationDisplayText>;
welcomeMessage?: React.ReactNode;
suggestedPrompts?: SuggestedPrompt[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const FormControl: FormControl = () => {
const handleSendMessage = React.useContext(SendMessageContext);
const allowAttachments = React.useContext(AttachmentContext);
const responseComponents = React.useContext(ResponseComponentsContext);
const isLoading = React.useContext(LoadingContext);
const aiContext = React.useContext(AIContextContext);
const ref = React.useRef<HTMLFormElement | null>(null);
const controls = React.useContext(ControlsContext);
Expand Down Expand Up @@ -219,6 +220,7 @@ export const FormControl: FormControl = () => {
input={input!}
setInput={setInput!}
allowAttachments={allowAttachments}
isLoading={isLoading}
/>
);
}
Expand Down
Loading

0 comments on commit 0d4d2b9

Please sign in to comment.