mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-07-28 17:53:21 +08:00
feat: add prompt for assistant
This commit is contained in:
@ -15,7 +15,7 @@ const MessageView = (props: Props) => {
|
||||
return (
|
||||
<div className={`w-full flex flex-row justify-start items-start my-4 ${isCurrentUser ? "justify-end pl-8 sm:pl-24" : "pr-8 sm:pr-24"}`}>
|
||||
{isCurrentUser ? (
|
||||
<div className="w-auto max-w-full bg-indigo-600 text-white px-4 py-2 rounded-lg rounded-tr-none shadow whitespace-pre">
|
||||
<div className="w-auto max-w-full bg-indigo-600 text-white px-4 py-2 rounded-lg rounded-tr-none shadow whitespace-pre-wrap">
|
||||
{message.content}
|
||||
</div>
|
||||
) : (
|
||||
|
@ -1,6 +1,6 @@
|
||||
import axios from "axios";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { defaultChat, useChatStore, useMessageStore, useUserStore } from "../../store";
|
||||
import { defaultChat, getPromptOfAssistant, useChatStore, useMessageStore, useUserStore } from "../../store";
|
||||
import { Chat, Message, UserRole } from "../../types";
|
||||
import { generateUUID } from "../../utils";
|
||||
import Icon from "../Icon";
|
||||
@ -47,11 +47,18 @@ const ChatView = () => {
|
||||
|
||||
setIsRequesting(true);
|
||||
const messageList = messageStore.getState().messageList.filter((message) => message.chatId === currentChat.id);
|
||||
const prompt = getPromptOfAssistant(userStore.getAssistantById(currentChat.assistantId)!);
|
||||
const { data } = await axios.post<string>("/api/chat", {
|
||||
messages: messageList.map((message) => ({
|
||||
role: message.creatorId === userStore.currentUser.id ? UserRole.User : UserRole.Assistant,
|
||||
content: message.content,
|
||||
})),
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: prompt,
|
||||
},
|
||||
...messageList.map((message) => ({
|
||||
role: message.creatorId === userStore.currentUser.id ? UserRole.User : UserRole.Assistant,
|
||||
content: message.content,
|
||||
})),
|
||||
],
|
||||
});
|
||||
messageStore.addMessage({
|
||||
id: generateUUID(),
|
||||
|
Reference in New Issue
Block a user