Skip to content

Commit

Permalink
Refactor: Remove unnecessary features and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
akkadaska committed May 3, 2024
1 parent 7e23c9c commit 1718c24
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
10 changes: 5 additions & 5 deletions app/components/chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
max-width: 80%;
}

.assistantMessage img {
max-width: 100%;
padding: 8px 0px 8px 0px;
}

.userMessage {
align-self: flex-end;
color: #fff;
Expand All @@ -87,8 +92,3 @@
color: #b8b8b8;
margin-right: 8px;
}

.chatImageContent {
max-width: 100%;
padding: 8px 0px 8px 0px;
}
31 changes: 3 additions & 28 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React, { useState, useEffect, useRef, ReactNode, MouseEventHandler } from "react";
import styles from "./chat.module.css";
import { AssistantStream } from "openai/lib/AssistantStream";
import Markdown, { Options, defaultUrlTransform } from "react-markdown";
import Markdown from "react-markdown";
// @ts-expect-error - no types for this yet
import { AssistantStreamEvent } from "openai/resources/beta/assistants/assistants";
import { RequiredActionFunctionToolCall } from "openai/resources/beta/threads/runs/runs";
Expand All @@ -17,35 +17,10 @@ const UserMessage = ({ text }: { text: string }) => {
return <div className={styles.userMessage}>{text}</div>;
};

const markdownOptions: Options = {
components:{
a(props) {
const { href } = props;
if (href.indexOf('fileid:') === 0) {
const fileId = href.replace('fileid:', '');
const fileLink = `/api/files/${fileId}`;
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>;
}
},

urlTransform(url) {
if (url.indexOf('fileid:') === 0) {
return url;
}
return defaultUrlTransform(url);
}
}

const AssistantMessage = ({ text }: { text: string }) => {
return (
<div className={styles.assistantMessage}>
<Markdown {...markdownOptions}>{text}</Markdown>
<Markdown>{text}</Markdown>
</div>
);
};
Expand Down Expand Up @@ -264,7 +239,7 @@ const Chat = ({
if (annotation.type === 'file_path') {
updatedLastMessage.text = updatedLastMessage.text.replaceAll(
annotation.text,
`fileid:${annotation.file_path.file_id}`
`/api/files/${annotation.file_path.file_id}`
);
}
})
Expand Down

0 comments on commit 1718c24

Please sign in to comment.