Skip to content

Commit

Permalink
first card
Browse files Browse the repository at this point in the history
  • Loading branch information
Zewed committed Jan 24, 2024
1 parent 1dc00a1 commit 79bec42
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
21 changes: 20 additions & 1 deletion frontend/app/chat/[chatId]/components/DataPanel/DataPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
"use client";

import { useEffect, useState } from "react";

import { useChatContext } from "@/lib/context";
import { CloseBrain } from "@/lib/types/MessageMetadata";

import styles from "./DataPanel.module.scss";
import RelatedBrains from "./components/RelatedBrains/RelatedBrains";

const DataPanel = (): JSX.Element => {
const { messages } = useChatContext();
const [lastMessageRelatedBrain, setLastMessageRelatedBrain] = useState<
CloseBrain[]
>([]);

useEffect(() => {
if (messages.length > 0) {
const lastMessage = messages[messages.length - 1];
if (lastMessage?.metadata?.close_brains) {
setLastMessageRelatedBrain(lastMessage.metadata.close_brains);
}
}
}, [lastMessageRelatedBrain, messages]);

return (
<div className={styles.data_panel_wrapper}>
<RelatedBrains />
<RelatedBrains closeBrains={lastMessageRelatedBrain} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
"use client";
import { CloseBrain } from "@/lib/types/MessageMetadata";

import styles from "./RelatedBrains.module.scss";

const RelatedBrains = (): JSX.Element => {
return <div className={styles.related_brains_wrapper}>hey</div>;
interface RelatedBrainsProps {
closeBrains: CloseBrain[];
}

const RelatedBrains = ({ closeBrains }: RelatedBrainsProps): JSX.Element => {
return (
<div className={styles.related_brains_wrapper}>
{closeBrains.map((brain, index) => (
<div key={index}>
<p>Brain: {brain.name}</p>
<p>Similarity: {brain.similarity}</p>
</div>
))}
</div>
);
};

export default RelatedBrains;
5 changes: 4 additions & 1 deletion frontend/app/chat/[chatId]/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { UUID } from "crypto";

import { CloseBrain } from "@/lib/types/MessageMetadata";

export type ChatQuestion = {
model?: string;
question?: string;
Expand All @@ -17,7 +19,8 @@ export type ChatMessage = {
prompt_title?: string;
brain_name?: string;
metadata?: {
sources?: [string];
sources?: string[];
close_brains?: CloseBrain[];
};
};

Expand Down
9 changes: 9 additions & 0 deletions frontend/lib/types/MessageMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface CloseBrain {
id: string;
similarity: number;
name: string;
}

export interface MessageMetadata {
closeBrains: CloseBrain[];
}

0 comments on commit 79bec42

Please sign in to comment.