forked from aws-samples/amplify-next-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from cabcookie:add-ai-tools
fix: allow levels for heading (was just h1 right now)
- Loading branch information
Showing
14 changed files
with
917 additions
and
356 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,23 @@ | ||
import { JSONContent } from "@tiptap/core"; | ||
import { Dispatch, FC, SetStateAction } from "react"; | ||
import InboxEditor from "../ui-elements/editors/inbox-editor/InboxEditor"; | ||
|
||
interface ChatInputProps { | ||
prompt: JSONContent; | ||
setPrompt: Dispatch<SetStateAction<JSONContent>>; | ||
handleSend: () => void; | ||
} | ||
|
||
const ChatInput: FC<ChatInputProps> = ({ prompt, setPrompt, handleSend }) => ( | ||
<InboxEditor | ||
notes={prompt} | ||
saveNotes={(editor) => setPrompt(editor.getJSON())} | ||
autoFocus | ||
placeholder="Send a message" | ||
saveAtCmdEnter={handleSend} | ||
showSaveStatus={false} | ||
className="pb-12 max-h-60 md:max-h-80 overflow-y-auto" | ||
/> | ||
); | ||
|
||
export default ChatInput; |
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,30 @@ | ||
import { MentionedPerson } from "@/helpers/chat/set-mentioned-people"; | ||
import { PersonJob } from "@/pages/chat"; | ||
import { FC } from "react"; | ||
|
||
interface ChatMetadataProps { | ||
currentJob?: PersonJob; | ||
mentionedPeople?: MentionedPerson[]; | ||
} | ||
|
||
const ChatMetadata: FC<ChatMetadataProps> = ({ currentJob, mentionedPeople }) => | ||
currentJob?.user && ( | ||
<div className="text-xs text-muted-foreground p-2 pt-1 space-y-1 bg-white/95"> | ||
<div>We will integrate the following information in the request:</div> | ||
<ul className="list-disc list-inside"> | ||
<li> | ||
Your name: {currentJob.user} ( | ||
{currentJob.jobRole && `${currentJob.jobRole} `}at{" "} | ||
{currentJob.employer}) | ||
</li> | ||
{mentionedPeople && mentionedPeople.length > 0 && ( | ||
<li> | ||
Information about these people:{" "} | ||
{mentionedPeople.map((person) => person.name).join(", ")} | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
); | ||
|
||
export default ChatMetadata; |
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,22 @@ | ||
import { ArrowUp, Loader2 } from "lucide-react"; | ||
import { FC } from "react"; | ||
import { Button } from "../ui/button"; | ||
|
||
interface ChatSendBtnProps { | ||
isSending: boolean; | ||
handleSend: () => void; | ||
} | ||
|
||
const ChatSendBtn: FC<ChatSendBtnProps> = ({ isSending, handleSend }) => { | ||
return ( | ||
<Button | ||
className="rounded-full w-10 h-10 absolute bottom-1 right-1" | ||
onClick={handleSend} | ||
disabled={isSending} | ||
> | ||
{!isSending ? <ArrowUp /> : <Loader2 className="animate-spin" />} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default ChatSendBtn; |
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,5 @@ | ||
const ChatUiGradient = () => ( | ||
<div className="h-8 bg-gradient-to-t from-background/95 via-background/80 to-background/0" /> | ||
); | ||
|
||
export default ChatUiGradient; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PromptWithContext } from "@/components/chat/MessageInput"; | ||
import { PersonJob } from "@/pages/chat"; | ||
import { MentionedPerson } from "./set-mentioned-people"; | ||
|
||
export const createAiContext = ( | ||
currentJob: PersonJob | undefined, | ||
mentionedPeople: MentionedPerson[] | undefined | ||
): PromptWithContext["aiContext"] => ({ | ||
...(!currentJob && (!mentionedPeople || mentionedPeople.length === 0) | ||
? {} | ||
: { | ||
description: | ||
"Use the information from context as valid information to leverage for your response. Do not mention you are referring these information.", | ||
}), | ||
...(!currentJob ? {} : { user: currentJob }), | ||
...(!mentionedPeople || mentionedPeople.length === 0 | ||
? {} | ||
: { mentionedPeople }), | ||
}); |
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,26 @@ | ||
import { Person } from "@/api/usePerson"; | ||
import { User } from "@/api/useUser"; | ||
import { PersonAccount } from "@/helpers/person/accounts"; | ||
import { PersonJob } from "@/pages/chat"; | ||
import { find, flow, get, identity } from "lodash/fp"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
|
||
export const setCurrentJobByUser = ( | ||
user: User | undefined, | ||
person: Person | undefined, | ||
setCurrentJob: Dispatch<SetStateAction<PersonJob | undefined>> | ||
) => | ||
flow( | ||
identity<typeof person>, | ||
get("accounts"), | ||
find<PersonAccount>(["isCurrent", true]), | ||
(account) => | ||
!account | ||
? undefined | ||
: { | ||
user: user?.userName, | ||
employer: account.accountName, | ||
jobRole: account.position, | ||
}, | ||
setCurrentJob | ||
)(person); |
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,27 @@ | ||
import { PromptWithContext } from "@/components/chat/MessageInput"; | ||
import { emptyDocument } from "@/components/ui-elements/editors/helpers/document"; | ||
import { getTextFromJsonContent } from "@/components/ui-elements/editors/helpers/text-generation"; | ||
import { createAiContext } from "@/helpers/chat/create-ai-context"; | ||
import { PersonJob } from "@/pages/chat"; | ||
import { SendMessage } from "@aws-amplify/ui-react-ai"; | ||
import { JSONContent } from "@tiptap/core"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
import { MentionedPerson } from "./set-mentioned-people"; | ||
|
||
export const handlePromptSend = ( | ||
setIsSending: Dispatch<SetStateAction<boolean>>, | ||
currentJob: PersonJob | undefined, | ||
mentionedPeople: MentionedPerson[] | undefined, | ||
onSend: SendMessage, | ||
prompt: JSONContent, | ||
setPrompt: Dispatch<SetStateAction<JSONContent>> | ||
) => { | ||
setIsSending(true); | ||
const message = { | ||
content: [{ text: getTextFromJsonContent(prompt) }], | ||
aiContext: createAiContext(currentJob, mentionedPeople), | ||
} as PromptWithContext; | ||
console.log({ message }); | ||
onSend(message); | ||
setPrompt(emptyDocument); | ||
}; |
Oops, something went wrong.