-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use same clickhouse and postgres message ids
- Loading branch information
1 parent
7e8c31c
commit 5fc7799
Showing
9 changed files
with
145 additions
and
6 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
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,114 @@ | ||
import { makePersisted } from "@solid-primitives/storage"; | ||
import { IconTypes } from "solid-icons"; | ||
import { | ||
BsHandThumbsDown, | ||
BsHandThumbsDownFill, | ||
BsHandThumbsUp, | ||
BsHandThumbsUpFill, | ||
} from "solid-icons/bs"; | ||
import { Show, useContext } from "solid-js"; | ||
import { createStore } from "solid-js/store"; | ||
import { UserContext } from "../contexts/UserContext"; | ||
|
||
interface MessageVotingProps { | ||
queryId: string; | ||
} | ||
|
||
type MessageVoteStore = { | ||
[key: string]: number; | ||
}; | ||
|
||
const apiHost = import.meta.env.VITE_API_HOST as unknown as string; | ||
|
||
// Create store exepcted to be directly destructured, this is fine | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, solid/reactivity | ||
const [store, setStore] = makePersisted(createStore<MessageVoteStore>({}), { | ||
name: "vote-cache", | ||
}); | ||
|
||
export const MessageVoting = (props: MessageVotingProps) => { | ||
const userContext = useContext(UserContext); | ||
|
||
const updateVote = async (queryId: string, vote: number) => { | ||
const prevVote = store[queryId]; | ||
setStore(queryId, vote); | ||
const dataset = userContext.currentDataset?.(); | ||
if (dataset?.dataset.id) { | ||
const response = await fetch(apiHost + "/analytics/rag", { | ||
method: "PUT", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"TR-Dataset": dataset.dataset.id, | ||
}, | ||
credentials: "include", | ||
body: JSON.stringify({ | ||
query_id: queryId, | ||
rating: vote, | ||
}), | ||
}); | ||
|
||
if (response.status !== 204) { | ||
console.error("Failed to update vote", response); | ||
// Rollback the vote | ||
setStore(queryId, prevVote); | ||
} | ||
} | ||
}; | ||
|
||
const VoteIcon = (props: { | ||
icon: IconTypes; | ||
onClick: (e: MouseEvent) => void; | ||
}) => { | ||
return ( | ||
<div onClick={(e) => props.onClick(e)} class="p-2"> | ||
{props.icon({})} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div class="flex flex-col"> | ||
<Show | ||
fallback={ | ||
<VoteIcon | ||
icon={BsHandThumbsUp} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
updateVote(props.queryId, 1); | ||
}} | ||
/> | ||
} | ||
when={store[props.queryId] === 1} | ||
> | ||
<VoteIcon | ||
icon={BsHandThumbsUpFill} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
updateVote(props.queryId, 0); | ||
}} | ||
/> | ||
</Show> | ||
|
||
<Show | ||
fallback={ | ||
<VoteIcon | ||
icon={BsHandThumbsDown} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
updateVote(props.queryId, -1); | ||
}} | ||
/> | ||
} | ||
when={store[props.queryId] === -1} | ||
> | ||
<VoteIcon | ||
icon={BsHandThumbsDownFill} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
updateVote(props.queryId, 0); | ||
}} | ||
/> | ||
</Show> | ||
</div> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export interface Message { | ||
id?: string | undefined; | ||
content: string; | ||
} | ||
|
||
|
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