mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
feat: enhance UI components and add accordion functionality
- Updated DraggableWindow.vue to improve shadow effects. - Refactored AboutWindow.vue for better structure and readability. - Added chatbot functionality in chatbot.vue with cookie management. - Improved navigation component for better code clarity. - Created a new chat history table in the database schema. - Modified error handling in error.vue to display error messages correctly. - Integrated ChatbotWindow into the desktop application layout. - Implemented accordion component in home.vue for Q/A section. - Enhanced API for chat functionality with improved error handling. - Removed unused routes for cleaner codebase. - Added custom animations for accordion components in tailwind.config.js. - Developed accordion UI components (Accordion, AccordionContent, AccordionItem, AccordionTrigger) for better user interaction.
This commit is contained in:
parent
f89e6aaa48
commit
5bf857f3cd
21 changed files with 402 additions and 182 deletions
|
@ -5,31 +5,60 @@ const groq = new Groq();
|
|||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const slug = getRouterParam(event, "slug");
|
||||
if (!slug) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: "A UUID is required for this action.",
|
||||
});
|
||||
}
|
||||
const getChatHistory = await sql`
|
||||
select * from chatHistory
|
||||
where uuid = ${slug}
|
||||
order by created_ata asc
|
||||
`;
|
||||
if (getChatHistory.length === 0) {
|
||||
}
|
||||
const body = await readBody(event);
|
||||
const fetchNewsArticle = await sql`
|
||||
select * from newArticle
|
||||
where slug = ${slug}
|
||||
where newsid = ${body.newsid}
|
||||
`;
|
||||
const chatCompletion = await groq.chat.completions.create({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: `${body}`,
|
||||
},
|
||||
{
|
||||
role: "system",
|
||||
content: `You are a news chat, the following content will be used to chat with the user title: ${fetchNewsArticle.title}\n content: ${fetchNewsArticle.content}`,
|
||||
},
|
||||
...getChatHistory.map((chat) => ({
|
||||
role: chat.role,
|
||||
content: chat.content,
|
||||
})),
|
||||
{
|
||||
role: "user",
|
||||
content: `${body}`,
|
||||
},
|
||||
],
|
||||
model: "llama3-70b-8192",
|
||||
model: "llama-3.1-8b-instant",
|
||||
temperature: 1,
|
||||
max_completion_tokens: 1024,
|
||||
top_p: 1,
|
||||
stream: true,
|
||||
stop: null,
|
||||
});
|
||||
|
||||
await sql`
|
||||
INSERT INTO chat_history (uuid, role, content)
|
||||
VALUES (${slug}, 'user', ${body})
|
||||
`;
|
||||
let assistantResponse = "";
|
||||
for await (const chunk of chatCompletion) {
|
||||
process.stdout.write(chunk.choices[0]?.delta?.content || "");
|
||||
const content = chunk.choices[0]?.delta?.content || "";
|
||||
assistantResponse += content;
|
||||
process.stdout.write(content);
|
||||
}
|
||||
if (assistantResponse) {
|
||||
await sql`
|
||||
INSERT INTO chat_history (uuid, role, content)
|
||||
VALUES (${slug}, 'assistant', ${assistantResponse})
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue