head ,csv template and limit content size

This commit is contained in:
archer 2023-08-02 14:52:27 +08:00
parent ae95a8908e
commit 58d94e1018
No known key found for this signature in database
GPG Key ID: 569A5660D2379E28
6 changed files with 20 additions and 9 deletions

View File

@ -1,4 +1,5 @@
import React, { useCallback, useRef } from 'react'; import React, { useCallback, useRef } from 'react';
import Head from 'next/head';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { getInitChatSiteInfo, delChatRecordByIndex, putChatHistory } from '@/api/chat'; import { getInitChatSiteInfo, delChatRecordByIndex, putChatHistory } from '@/api/chat';
import { import {
@ -244,6 +245,9 @@ const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => {
return ( return (
<Flex h={'100%'}> <Flex h={'100%'}>
<Head>
<title>{chatData.app.name}</title>
</Head>
{/* pc show myself apps */} {/* pc show myself apps */}
{isPc && ( {isPc && (
<Box p={5} borderRight={theme.borders.base} w={'220px'} flexShrink={0}> <Box p={5} borderRight={theme.borders.base} w={'220px'} flexShrink={0}>

View File

@ -1,4 +1,5 @@
import React, { useCallback, useMemo, useRef } from 'react'; import React, { useCallback, useMemo, useRef } from 'react';
import Head from 'next/head';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { initShareChatInfo } from '@/api/chat'; import { initShareChatInfo } from '@/api/chat';
import { Box, Flex, useDisclosure, Drawer, DrawerOverlay, DrawerContent } from '@chakra-ui/react'; import { Box, Flex, useDisclosure, Drawer, DrawerOverlay, DrawerContent } from '@chakra-ui/react';
@ -146,6 +147,9 @@ const OutLink = ({ shareId, chatId }: { shareId: string; chatId: string }) => {
return ( return (
<PageContainer> <PageContainer>
<Head>
<title>{shareChatData.app.name}</title>
</Head>
<Flex h={'100%'} flexDirection={['column', 'row']}> <Flex h={'100%'} flexDirection={['column', 'row']}>
{((children: React.ReactNode) => { {((children: React.ReactNode) => {
return isPc ? ( return isPc ? (

View File

@ -20,7 +20,7 @@ const fileExtension = '.csv';
type FileItemType = { type FileItemType = {
id: string; id: string;
filename: string; filename: string;
chunks: { q: string; a: string }[]; chunks: { q: string; a: string; source?: string }[];
}; };
const CsvImport = ({ kbId }: { kbId: string }) => { const CsvImport = ({ kbId }: { kbId: string }) => {
@ -61,7 +61,8 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
filename: file.name, filename: file.name,
chunks: data.map((item) => ({ chunks: data.map((item) => ({
q: item[0], q: item[0],
a: item[1] a: item[1],
source: item[2]
})) }))
}, },
...state ...state
@ -88,7 +89,7 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
file.chunks.forEach((chunk) => { file.chunks.forEach((chunk) => {
chunks.push({ chunks.push({
...chunk, ...chunk,
source: file.filename source: chunk.source || file.filename
}); });
}) })
); );
@ -210,6 +211,7 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
<Box px={3} py={'1px'} border={theme.borders.base} borderRadius={'md'}> <Box px={3} py={'1px'} border={theme.borders.base} borderRadius={'md'}>
# {i + 1} # {i + 1}
</Box> </Box>
{item.source && <Box ml={1}>({item.source})</Box>}
<Box flex={1} /> <Box flex={1} />
<DeleteIcon <DeleteIcon
onClick={() => { onClick={() => {

View File

@ -23,7 +23,7 @@ const FileSelect = ({
...props ...props
}: Props) => { }: Props) => {
const { Loading: FileSelectLoading } = useLoading(); const { Loading: FileSelectLoading } = useLoading();
const csvTemplate = `question,answer\n"什么是 laf","laf 是一个云函数开发平台……"\n"什么是 sealos","Sealos 是以 kubernetes 为内核的云操作系统发行版,可以……"`; const csvTemplate = `question,answer,source\n"什么是 laf","laf 是一个云函数开发平台……","laf git doc"\n"什么是 sealos","Sealos 是以 kubernetes 为内核的云操作系统发行版,可以……","sealos git doc"`;
const { File, onOpen } = useSelectFile({ const { File, onOpen } = useSelectFile({
fileType: fileExtension, fileType: fileExtension,
@ -72,7 +72,7 @@ const FileSelect = ({
}) })
} }
> >
csv模 CSV
</Box> </Box>
)} )}
<FileSelectLoading loading={isLoading} fixed={false} /> <FileSelectLoading loading={isLoading} fixed={false} />

View File

@ -35,12 +35,13 @@ export async function saveChat({
if (chatHistory) { if (chatHistory) {
promise.push( promise.push(
Chat.findOneAndUpdate( Chat.updateOne(
{ chatId, userId }, { chatId, userId },
{ {
$push: { $push: {
content: { content: {
$each: content $each: content,
$slice: -50
} }
}, },
title: content[0].value.slice(0, 20), title: content[0].value.slice(0, 20),

View File

@ -264,7 +264,7 @@ const simpleChatTemplate = (formData: EditFormType): AppModuleItemType[] => [
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
value: 10, value: 6,
connected: true connected: true
}, },
{ {
@ -340,7 +340,7 @@ const kbTemplate = (formData: EditFormType): AppModuleItemType[] => [
inputs: [ inputs: [
{ {
key: 'maxContext', key: 'maxContext',
value: 10, value: 6,
connected: true connected: true
}, },
{ {