feat: implement connection and database types

This commit is contained in:
steven
2023-03-22 16:32:12 +08:00
parent 90a6fec65c
commit 5dc3c05a2a
11 changed files with 58 additions and 17 deletions

View File

@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react";
import { toast } from "react-hot-toast";
import TextareaAutosize from "react-textarea-autosize";
import { localUser, useChatStore, useMessageStore } from "../../store";
import { CreatorRole } from "../../types";
import { generateUUID } from "../../utils";
import Icon from "../Icon";
@ -45,6 +46,7 @@ const MessageTextarea = (props: Props) => {
id: generateUUID(),
chatId: chatStore.currentChat.id,
creatorId: localUser.id,
creatorRole: CreatorRole.User,
createdAt: Date.now(),
content: value,
});

View File

@ -1,7 +1,7 @@
import axios from "axios";
import { useEffect, useRef, useState } from "react";
import { defaultChat, getAssistantById, getPromptOfAssistant, localUser, useChatStore, useMessageStore } from "../../store";
import { Chat, Message, UserRole } from "../../types";
import { Chat, CreatorRole, Message } from "../../types";
import { generateUUID } from "../../utils";
import Icon from "../Icon";
import Header from "./Header";
@ -50,11 +50,11 @@ const ChatView = () => {
const { data } = await axios.post<string>("/api/chat", {
messages: [
{
role: "system",
role: CreatorRole.System,
content: prompt,
},
...messageList.map((message) => ({
role: message.creatorId === localUser.id ? UserRole.User : UserRole.Assistant,
role: message.creatorId === localUser.id ? CreatorRole.User : CreatorRole.Assistant,
content: message.content,
})),
],
@ -63,6 +63,7 @@ const ChatView = () => {
id: generateUUID(),
chatId: currentChat.id,
creatorId: currentChat.assistantId,
creatorRole: CreatorRole.Assistant,
createdAt: Date.now(),
content: data,
});