-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into rename-fix-sha256
- Loading branch information
Showing
295 changed files
with
7,523 additions
and
6,834 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM amazonlinux:2023.4.20240528.0 | ||
FROM amazonlinux:2023.4.20240611.0 | ||
MAINTAINER Quilt Data, Inc. [email protected] | ||
|
||
ENV LC_ALL=C.UTF-8 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
import * as Lab from '@material-ui/lab' | ||
|
||
import Skeleton from 'components/Skeleton' | ||
import type * as AWS from 'utils/AWS' | ||
|
||
import History from './History' | ||
import Input from './Input' | ||
|
||
const useStyles = M.makeStyles((t) => ({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
flexGrow: 1, | ||
overflow: 'hidden', | ||
}, | ||
error: { | ||
marginTop: t.spacing(2), | ||
}, | ||
history: { | ||
...t.typography.body1, | ||
maxHeight: t.spacing(70), | ||
overflowY: 'auto', | ||
}, | ||
input: { | ||
marginTop: t.spacing(2), | ||
}, | ||
})) | ||
|
||
const noMessages: AWS.Bedrock.Message[] = [] | ||
|
||
export function ChatSkeleton() { | ||
const classes = useStyles() | ||
return ( | ||
<div className={classes.root}> | ||
<History loading messages={noMessages} /> | ||
<Skeleton className={classes.input} height="32px" /> | ||
</div> | ||
) | ||
} | ||
|
||
const Submitting = Symbol('Submitting') | ||
|
||
interface ChatProps { | ||
initializing: boolean | ||
history: AWS.Bedrock.History | ||
onSubmit: (value: string) => Promise<void> | ||
} | ||
|
||
export default function Chat({ history, onSubmit, initializing }: ChatProps) { | ||
const classes = useStyles() | ||
|
||
const [value, setValue] = React.useState('') | ||
const [state, setState] = React.useState<Error | typeof Submitting | null>(null) | ||
|
||
const handleSubmit = React.useCallback(async () => { | ||
if (state) return | ||
|
||
setState(Submitting) | ||
try { | ||
await onSubmit(value) | ||
setValue('') | ||
} catch (e) { | ||
setState(e instanceof Error ? e : new Error('Failed to submit message')) | ||
} | ||
setState(null) | ||
}, [state, onSubmit, value]) | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<History | ||
className={classes.history} | ||
loading={state === Submitting || initializing} | ||
messages={history.messages} | ||
/> | ||
{state instanceof Error && ( | ||
<Lab.Alert className={classes.error} severity="error"> | ||
{state.message} | ||
</Lab.Alert> | ||
)} | ||
<Input | ||
className={classes.input} | ||
disabled={state === Submitting} | ||
onChange={setValue} | ||
onSubmit={handleSubmit} | ||
value={value} | ||
/> | ||
</div> | ||
) | ||
} |
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,101 @@ | ||
import cx from 'classnames' | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
import usePrevious from 'utils/usePrevious' | ||
import * as AWS from 'utils/AWS' | ||
|
||
import * as Messages from './Message' | ||
|
||
const useStyles = M.makeStyles((t) => ({ | ||
assistant: { | ||
animation: `$show 300ms ease-out`, | ||
}, | ||
message: { | ||
'& + &': { | ||
marginTop: t.spacing(2), | ||
}, | ||
}, | ||
user: { | ||
animation: `$slide 150ms ease-out`, | ||
marginLeft: 'auto', | ||
width: '60%', | ||
}, | ||
'@keyframes slide': { | ||
'0%': { | ||
transform: `translateX($${t.spacing(8)}px)`, | ||
}, | ||
'100%': { | ||
transform: `translateX(0)`, | ||
}, | ||
}, | ||
'@keyframes show': { | ||
'0%': { | ||
opacity: 0.7, | ||
}, | ||
'100%': { | ||
opacity: '1', | ||
}, | ||
}, | ||
})) | ||
|
||
interface HistoryProps { | ||
className?: string | ||
loading: boolean | ||
messages: AWS.Bedrock.Message[] | ||
} | ||
|
||
export default function History({ className, loading, messages }: HistoryProps) { | ||
const classes = useStyles() | ||
|
||
const list = React.useMemo( | ||
() => messages.filter((message) => message.role !== 'system'), | ||
[messages], | ||
) | ||
|
||
const ref = React.useRef<HTMLDivElement | null>(null) | ||
usePrevious(messages, (prev) => { | ||
if (prev && messages.length > prev.length) { | ||
ref.current?.scroll({ | ||
top: ref.current?.firstElementChild?.clientHeight, | ||
behavior: 'smooth', | ||
}) | ||
} | ||
}) | ||
|
||
return ( | ||
<div className={className} ref={ref}> | ||
<div /* full height scroll area */> | ||
{list.map((message, index) => { | ||
switch (message.role) { | ||
case 'user': | ||
return ( | ||
<Messages.User | ||
key={`message_${index}`} | ||
className={cx(classes.message, classes.user)} | ||
content={message.content} | ||
/> | ||
) | ||
case 'summarize': | ||
return ( | ||
<Messages.User | ||
key={`message_${index}`} | ||
className={cx(classes.message, classes.user)} | ||
content="Summarize this document" | ||
/> | ||
) | ||
case 'assistant': | ||
return ( | ||
<Messages.Assistant | ||
key={`message_${index}`} | ||
className={cx(classes.message, classes.assistant)} | ||
content={message.content} | ||
/> | ||
) | ||
} | ||
})} | ||
{loading && <Messages.Skeleton className={classes.message} />} | ||
</div> | ||
</div> | ||
) | ||
} |
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,52 @@ | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
interface ChatInputProps { | ||
className?: string | ||
disabled?: boolean | ||
onChange: (value: string) => void | ||
onSubmit: () => void | ||
value: string | ||
} | ||
|
||
export default function ChatInput({ | ||
className, | ||
disabled, | ||
onChange, | ||
onSubmit, | ||
value, | ||
}: ChatInputProps) { | ||
const handleSubmit = React.useCallback( | ||
(event) => { | ||
event.preventDefault() | ||
if (!value || disabled) return | ||
onSubmit() | ||
}, | ||
[disabled, onSubmit, value], | ||
) | ||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<M.TextField | ||
autoFocus | ||
className={className} | ||
disabled={disabled} | ||
fullWidth | ||
helperText="Qurator may make errors. Verify critical information yourself." | ||
label="Chat" | ||
onChange={(e) => onChange(e.target.value)} | ||
size="small" | ||
value={value} | ||
variant="outlined" | ||
InputProps={{ | ||
endAdornment: ( | ||
<M.InputAdornment position="end"> | ||
<M.IconButton disabled={!value} onClick={onSubmit} type="submit"> | ||
<M.Icon>send</M.Icon> | ||
</M.IconButton> | ||
</M.InputAdornment> | ||
), | ||
}} | ||
/> | ||
</form> | ||
) | ||
} |
Oops, something went wrong.