-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(assistant): assistant improvements #4214
base: main
Are you sure you want to change the base?
Changes from all commits
c0306ee
a7f97ce
8c5203e
9c2f827
41c55c0
deb5441
4d47a2d
9fe763e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
import { AIChatMessage, AIChatMessageAuthor, AIChatMessageBody } from "@twilio-paste/ai-chat-log"; | ||
import { | ||
AIChatMessage, | ||
AIChatMessageAuthor, | ||
AIChatMessageBody, | ||
AIChatMessageBodyProps, | ||
} from "@twilio-paste/ai-chat-log"; | ||
import { compiler } from "markdown-to-jsx"; | ||
import { type Message } from "openai/resources/beta/threads/messages"; | ||
import * as React from "react"; | ||
|
||
import { formatTimestamp } from "../../utils/formatTimestamp"; | ||
import { AssistantMarkdown } from "./AssistantMarkdown"; | ||
import { assistantMarkdownOptions } from "./AssistantMarkdown"; | ||
|
||
export const AssistantMessage: React.FC<{ threadMessage: Message }> = ({ threadMessage }) => { | ||
interface AssistantMessageProps extends AIChatMessageBodyProps { | ||
threadMessage: Message; | ||
} | ||
|
||
export const AssistantMessage: React.FC<AssistantMessageProps> = ({ threadMessage, ...props }) => { | ||
return ( | ||
<AIChatMessage variant="bot"> | ||
<AIChatMessageAuthor aria-label={`said by paste assistant at ${formatTimestamp(threadMessage.created_at)}`}> | ||
PasteBot | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
{threadMessage.content[0].type === "text" && ( | ||
<AssistantMarkdown key={threadMessage.id}>{threadMessage.content[0].text.value}</AssistantMarkdown> | ||
)} | ||
<AIChatMessageBody {...props}> | ||
{threadMessage.content.length > 0 && | ||
threadMessage.content[0]?.type === "text" && | ||
compiler(threadMessage.content[0].text.value, assistantMarkdownOptions)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Vercel issue where it would sometimes throw the 500 Sarah was talking about was due to deleting a thread the |
||
</AIChatMessageBody> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to use compiler because the animated children was causing the component in the library to throw errors. I also added some information to our docs for how to overcome this. |
||
</AIChatMessage> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import { AIChatMessage, AIChatMessageAuthor, AIChatMessageBody } from "@twilio-paste/ai-chat-log"; | ||
import { | ||
AIChatMessage, | ||
AIChatMessageAuthor, | ||
AIChatMessageBody, | ||
AIChatMessageBodyProps, | ||
} from "@twilio-paste/ai-chat-log"; | ||
import { UserIcon } from "@twilio-paste/icons/esm/UserIcon"; | ||
import { type Message } from "openai/resources/beta/threads/messages"; | ||
import * as React from "react"; | ||
|
||
import { formatTimestamp } from "../../utils/formatTimestamp"; | ||
import { AssistantMarkdown } from "./AssistantMarkdown"; | ||
|
||
export const UserMessage: React.FC<{ threadMessage: Message }> = ({ threadMessage }) => { | ||
interface UserMessageProps extends AIChatMessageBodyProps { | ||
threadMessage: Message; | ||
} | ||
|
||
export const UserMessage: React.FC<UserMessageProps> = ({ threadMessage, ...props }) => { | ||
return ( | ||
<AIChatMessage variant="user"> | ||
<AIChatMessageAuthor | ||
|
@@ -15,7 +24,7 @@ export const UserMessage: React.FC<{ threadMessage: Message }> = ({ threadMessag | |
> | ||
You | ||
</AIChatMessageAuthor> | ||
<AIChatMessageBody> | ||
<AIChatMessageBody {...props}> | ||
{threadMessage.content[0].type === "text" && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed so we can pass in props for the body, for this one the size="fullScreen" |
||
<AssistantMarkdown key={threadMessage.id}>{threadMessage.content[0].text.value}</AssistantMarkdown> | ||
)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this was taking too much space on medium displays