Skip to content
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: Citations event via __event_emitter__ #3615

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use data field
  • Loading branch information
michaelpoluektov committed Jul 4, 2024
commit 05277556005230847f552b55c2d896ecd57fe281
31 changes: 13 additions & 18 deletions src/lib/components/chat/Chat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -133,29 133,24 @@
let message = history.messages[data.message_id];

const type = data?.data?.type ?? null;
if (type === "status") {
const status = {
done: data?.data?.done ?? null,
description: data?.data?.status ?? null
};

const payload = data?.data?.data ?? null;
if (!type || !payload) {
console.log("Data and type fields must be provided.", data);
return;
}
const status_keys = ["done", "description"];
const citation_keys = ["document", "metadata", "source"];
if (type === "status" && status_keys.every(key => key in payload)) {
if (message.statusHistory) {
message.statusHistory.push(status);
message.statusHistory.push(payload);
} else {
message.statusHistory = [status];
message.statusHistory = [payload];
}
} else if (type === "citation") {
console.log(data);
const citation = {
document: data?.data?.document ?? null,
metadata: data?.data?.metadata ?? null,
source: data?.data?.source ?? null
};

} else if (type === "citation" && citation_keys.every(key => key in payload)) {
if (message.citations) {
message.citations.push(citation);
message.citations.push(payload);
} else {
message.citations = [citation];
message.citations = [payload];
}
} else {
console.log("Unknown message type", data);
Expand Down
Loading