Skip to content

Commit

Permalink
feat: implement message sending functionality in thread input component
Browse files Browse the repository at this point in the history
  • Loading branch information
vaayne committed Sep 3, 2024
1 parent 75070b5 commit bd96853
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
39 changes: 17 additions & 22 deletions web/src/components/thread-input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ export function ThreadChatInput() {
}
};

const handleSendMessage = async () => {
if (text.trim() !== "") {
const localText = text.trim();
const localImages = images;
setText("");
setImages([]);
await sendThreadMessage.mutateAsync({
model: chatModel,
text: localText,
images: localImages,
});
}
};

const uploadImageButton = () => {
return (
<FileButton
Expand Down Expand Up @@ -212,7 +226,7 @@ export function ThreadChatInput() {
onClick={() => {
// Function to remove image
setImages((prevImages) =>
prevImages.filter((image) => image !== imgUrl)
prevImages.filter((image) => image !== imgUrl),
);
}}
>
Expand Down Expand Up @@ -256,24 +270,7 @@ export function ThreadChatInput() {
disabled={sendThreadMessage.isPending}
onKeyDown={async (e) => {
e.stopPropagation();
getHotkeyHandler([
[
sendKey,
async () => {
if (text.trim() !== "") {
const localText = text.trim();
const localImages = images
setText("");
setImages([])
await sendThreadMessage.mutateAsync({
model: chatModel,
text: localText,
images: localImages,
});
}
},
],
])(e);
getHotkeyHandler([[sendKey, handleSendMessage]])(e);
}}
styles={{
input: {
Expand All @@ -286,9 +283,7 @@ export function ThreadChatInput() {
radius="lg"
aria-label="Settings"
disabled={text === "" || sendThreadMessage.isPending}
onClick={async () => {
await sendThreadMessage.mutateAsync();
}}
onClick={handleSendMessage}
>
{sendThreadMessage.isPending ? (
<Icon icon="svg-spinners:180-ring" />
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/thread-sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function Sidebar() {
data={listThreads.data}
onChange={(item) => {
var filteredItems = listThreads.data.filter(
(i) => i.value == item
(i) => i.value == item,
);
if (filteredItems.length > 0) {
toggleMobileSidebar();
Expand Down
14 changes: 7 additions & 7 deletions web/src/libs/query-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function QueryContextProvider({ children }) {
},
onError: (error) => {
toastError(
`Failed to upsert assistant ${assistantId} : ${error.message}`
`Failed to upsert assistant ${assistantId} : ${error.message}`,
);
},
});
Expand All @@ -95,7 +95,7 @@ export function QueryContextProvider({ children }) {
},
onError: (error) => {
toastError(
`Failed to delete assistant ${assistantId} : ${error.message}`
`Failed to delete assistant ${assistantId} : ${error.message}`,
);
},
});
Expand All @@ -105,7 +105,7 @@ export function QueryContextProvider({ children }) {
const res = await post(
`/api/v1/assistants/${assistantId}/threads`,
null,
data
data,
);
return res.data;
},
Expand All @@ -124,7 +124,7 @@ export function QueryContextProvider({ children }) {
const res = await post(
`/api/v1/assistants/${assistantId}/threads/${threadId}/generate-title`,
null,
{}
{},
);
return res.data;
},
Expand Down Expand Up @@ -173,7 +173,7 @@ export function QueryContextProvider({ children }) {
const res = await post(
`/api/v1/assistants/${assistantId}/threads/${newThreadId}/messages`,
null,
payload
payload,
);
return res.data;
},
Expand Down Expand Up @@ -203,7 +203,7 @@ export function QueryContextProvider({ children }) {
queryKey: ["get-thread", threadId],
queryFn: async () => {
const res = await get(
`/api/v1/assistants/${assistantId}/threads/${threadId}`
`/api/v1/assistants/${assistantId}/threads/${threadId}`,
);

return res.data || {};
Expand Down Expand Up @@ -233,7 +233,7 @@ export function QueryContextProvider({ children }) {
const res = await put(
`/api/v1/assistants/${assistantId}/threads/${threadId}`,
null,
data
data,
);
return res.data;
},
Expand Down

0 comments on commit bd96853

Please sign in to comment.