Skip to content

Commit

Permalink
Add functionality to display images in chat interface
Browse files Browse the repository at this point in the history
  • Loading branch information
akkadaska committed May 3, 2024
1 parent b0fba4c commit 7e23c9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/components/chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@
color: #b8b8b8;
margin-right: 8px;
}

.chatImageContent {
max-width: 100%;
padding: 8px 0px 8px 0px;
}
12 changes: 12 additions & 0 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const markdownOptions: Options = {
return <a {...props} target="_blank" href={fileLink} />;
}
return <a {...props} target="_blank" />;
},

img(props) {
return <a href={props.src} target="_blank"><img {...props} className={styles.chatImageContent} /></a>;
}
},

Expand Down Expand Up @@ -169,6 +173,11 @@ const Chat = ({
}
};

// imageFileDone - show image in chat
const handleImageFileDone = (image) => {
appendToLastMessage(`\n![${image.file_id}](/api/files/${image.file_id})\n`);
}

// toolCallCreated - log new tool call
const toolCallCreated = (toolCall) => {
if (toolCall.type != "code_interpreter") return;
Expand Down Expand Up @@ -209,6 +218,9 @@ const Chat = ({
stream.on("textCreated", handleTextCreated);
stream.on("textDelta", handleTextDelta);

// image
stream.on("imageFileDone", handleImageFileDone);

// code interpreter
stream.on("toolCallCreated", toolCallCreated);
stream.on("toolCallDelta", toolCallDelta);
Expand Down

0 comments on commit 7e23c9c

Please sign in to comment.