mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-09-18 23:31:33 +00:00
fix(Library): Returns metadata back to original format so sources continue to work.
This commit is contained in:
@@ -135,9 +135,11 @@ const handleEmitterEvents = async (
|
|||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
messageId: aiMessageId,
|
messageId: aiMessageId,
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
metadata: {
|
metadata: JSON.stringify({
|
||||||
|
createdAt: new Date(),
|
||||||
|
...(sources && sources.length > 0 && { sources }),
|
||||||
modelStats: modelStats,
|
modelStats: modelStats,
|
||||||
},
|
}),
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
});
|
});
|
||||||
@@ -319,7 +321,14 @@ export const POST = async (req: Request) => {
|
|||||||
const writer = responseStream.writable.getWriter();
|
const writer = responseStream.writable.getWriter();
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
handleEmitterEvents(stream, writer, encoder, aiMessageId, message.chatId, startTime);
|
handleEmitterEvents(
|
||||||
|
stream,
|
||||||
|
writer,
|
||||||
|
encoder,
|
||||||
|
aiMessageId,
|
||||||
|
message.chatId,
|
||||||
|
startTime,
|
||||||
|
);
|
||||||
handleHistorySave(message, humanMessageId, body.focusMode, body.files);
|
handleHistorySave(message, humanMessageId, body.focusMode, body.files);
|
||||||
|
|
||||||
return new Response(responseStream.readable, {
|
return new Response(responseStream.readable, {
|
||||||
|
@@ -546,8 +546,7 @@ const Page = () => {
|
|||||||
Automatic Suggestions
|
Automatic Suggestions
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-black/60 dark:text-white/60 mt-0.5">
|
<p className="text-xs text-black/60 dark:text-white/60 mt-0.5">
|
||||||
Automatically show related suggestions after
|
Automatically show related suggestions after responses
|
||||||
responses
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -18,10 +18,6 @@ export type ModelStats = {
|
|||||||
responseTime?: number;
|
responseTime?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MessageMetadata = {
|
|
||||||
modelStats?: ModelStats;
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Message = {
|
export type Message = {
|
||||||
messageId: string;
|
messageId: string;
|
||||||
chatId: string;
|
chatId: string;
|
||||||
@@ -30,7 +26,7 @@ export type Message = {
|
|||||||
role: 'user' | 'assistant';
|
role: 'user' | 'assistant';
|
||||||
suggestions?: string[];
|
suggestions?: string[];
|
||||||
sources?: Document[];
|
sources?: Document[];
|
||||||
metadata?: MessageMetadata;
|
modelStats?: ModelStats;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface File {
|
export interface File {
|
||||||
@@ -217,6 +213,7 @@ const loadMessages = async (
|
|||||||
const messages = data.messages.map((msg: any) => {
|
const messages = data.messages.map((msg: any) => {
|
||||||
return {
|
return {
|
||||||
...msg,
|
...msg,
|
||||||
|
...JSON.parse(msg.metadata),
|
||||||
};
|
};
|
||||||
}) as Message[];
|
}) as Message[];
|
||||||
|
|
||||||
@@ -445,13 +442,10 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
sources: sources,
|
sources: sources,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
metadata: {
|
|
||||||
// modelStats will be added when we receive messageEnd event
|
|
||||||
modelStats: {
|
modelStats: {
|
||||||
modelName: data.modelName,
|
modelName: data.modelName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
@@ -483,10 +477,8 @@ const ChatWindow = ({ id }: { id?: string }) => {
|
|||||||
if (message.messageId === data.messageId) {
|
if (message.messageId === data.messageId) {
|
||||||
return {
|
return {
|
||||||
...message,
|
...message,
|
||||||
metadata: {
|
|
||||||
// Include model stats if available, otherwise null
|
// Include model stats if available, otherwise null
|
||||||
modelStats: data.modelStats || null,
|
modelStats: data.modelStats || null,
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
|
@@ -63,7 +63,9 @@ const ModelInfoButton: React.FC<ModelInfoButtonProps> = ({ modelStats }) => {
|
|||||||
</div>
|
</div>
|
||||||
{modelStats?.responseTime && (
|
{modelStats?.responseTime && (
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="text-black/70 dark:text-white/70">Response time:</span>
|
<span className="text-black/70 dark:text-white/70">
|
||||||
|
Response time:
|
||||||
|
</span>
|
||||||
<span className="text-black dark:text-white font-medium">
|
<span className="text-black dark:text-white font-medium">
|
||||||
{(modelStats.responseTime / 1000).toFixed(2)}s
|
{(modelStats.responseTime / 1000).toFixed(2)}s
|
||||||
</span>
|
</span>
|
||||||
|
@@ -58,11 +58,15 @@ const MessageBox = ({
|
|||||||
const [speechMessage, setSpeechMessage] = useState(message.content);
|
const [speechMessage, setSpeechMessage] = useState(message.content);
|
||||||
const [loadingSuggestions, setLoadingSuggestions] = useState(false);
|
const [loadingSuggestions, setLoadingSuggestions] = useState(false);
|
||||||
const [autoSuggestions, setAutoSuggestions] = useState(
|
const [autoSuggestions, setAutoSuggestions] = useState(
|
||||||
localStorage.getItem('autoSuggestions')
|
localStorage.getItem('autoSuggestions'),
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleLoadSuggestions = async () => {
|
const handleLoadSuggestions = async () => {
|
||||||
if (loadingSuggestions || (message?.suggestions && message.suggestions.length > 0)) return;
|
if (
|
||||||
|
loadingSuggestions ||
|
||||||
|
(message?.suggestions && message.suggestions.length > 0)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
setLoadingSuggestions(true);
|
setLoadingSuggestions(true);
|
||||||
try {
|
try {
|
||||||
@@ -202,8 +206,8 @@ const MessageBox = ({
|
|||||||
<h3 className="text-black dark:text-white font-medium text-xl">
|
<h3 className="text-black dark:text-white font-medium text-xl">
|
||||||
Answer
|
Answer
|
||||||
</h3>
|
</h3>
|
||||||
{message.metadata?.modelStats && (
|
{message.modelStats && (
|
||||||
<ModelInfoButton modelStats={message.metadata.modelStats} />
|
<ModelInfoButton modelStats={message.modelStats} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Markdown
|
<Markdown
|
||||||
@@ -251,7 +255,8 @@ const MessageBox = ({
|
|||||||
<div className="flex flex-row items-center space-x-2 mt-4">
|
<div className="flex flex-row items-center space-x-2 mt-4">
|
||||||
<Layers3 />
|
<Layers3 />
|
||||||
<h3 className="text-xl font-medium">Related</h3>{' '}
|
<h3 className="text-xl font-medium">Related</h3>{' '}
|
||||||
{(!autoSuggestions || autoSuggestions === 'false') && (!message.suggestions ||
|
{(!autoSuggestions || autoSuggestions === 'false') &&
|
||||||
|
(!message.suggestions ||
|
||||||
message.suggestions.length === 0) ? (
|
message.suggestions.length === 0) ? (
|
||||||
<div className="bg-light-secondary dark:bg-dark-secondary">
|
<div className="bg-light-secondary dark:bg-dark-secondary">
|
||||||
<button
|
<button
|
||||||
|
Reference in New Issue
Block a user