fix: style adjustment

This commit is contained in:
changhuiping.chp 2023-06-30 18:00:49 +08:00
parent a050b49d4b
commit 8aeab465f1
13 changed files with 137 additions and 108 deletions

View File

@ -16,7 +16,7 @@ const Item = styled(Sheet)(({ theme }) => ({
const Agents = () => {
const { handleChatSubmit, history } = useAgentChat({
queryAgentURL: `http://30.183.153.109:5000/v1/chat/completions`,
queryAgentURL: `/v1/chat/completions`,
});
const data = [

View File

@ -1 +0,0 @@
export const fetchBaseURL = 'http://30.183.153.109:5000';

View File

@ -4,7 +4,6 @@ import { useSearchParams } from 'next/navigation'
import React, { useState, useEffect } from 'react'
import { useColorScheme, Table, Stack } from '@/lib/mui'
import { Popover, Pagination } from 'antd'
import { fetchBaseURL } from '@/app/datastores/constants'
const page_size = 20
const ChunkList = () => {
@ -17,7 +16,7 @@ const ChunkList = () => {
useEffect(() => {
async function fetchChunks() {
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/chunk/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/chunk/list`,
{
method: 'POST',
headers: {
@ -107,7 +106,7 @@ const ChunkList = () => {
total={total}
onChange={async (page) => {
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/chunk/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/chunk/list`,
{
method: 'POST',
headers: {

View File

@ -19,7 +19,6 @@ import moment from 'moment'
import { InboxOutlined } from '@ant-design/icons'
import type { UploadProps } from 'antd'
import { Upload, Pagination, message } from 'antd'
import { fetchBaseURL } from '@/app/datastores/constants'
const { Dragger } = Upload
const Item = styled(Sheet)(({ theme }) => ({
@ -89,7 +88,7 @@ const Documents = () => {
useEffect(() => {
async function fetchDocuments() {
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`,
{
method: 'POST',
headers: {
@ -194,7 +193,7 @@ const Documents = () => {
size="sm"
onClick={async () => {
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/sync`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
@ -247,7 +246,7 @@ const Documents = () => {
total={total}
onChange={async (page) => {
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`,
{
method: 'POST',
headers: {
@ -400,7 +399,7 @@ const Documents = () => {
return
}
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/add`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/add`,
{
method: 'POST',
headers: {
@ -418,7 +417,7 @@ const Documents = () => {
message.success('success')
setIsAddDocumentModalShow(false)
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`,
{
method: 'POST',
headers: {
@ -449,7 +448,7 @@ const Documents = () => {
formData.append('doc_file', originFileObj)
formData.append('doc_type', 'DOCUMENT')
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/upload`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/upload`,
{
method: 'POST',
body: formData
@ -460,7 +459,7 @@ const Documents = () => {
message.success('success')
setIsAddDocumentModalShow(false)
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`,
{
method: 'POST',
headers: {
@ -487,7 +486,7 @@ const Documents = () => {
return
}
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/add`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/add`,
{
method: 'POST',
headers: {
@ -506,7 +505,7 @@ const Documents = () => {
message.success('success')
setIsAddDocumentModalShow(false)
const res = await fetch(
`${fetchBaseURL}/knowledge/${spaceName}/document/list`,
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/list`,
{
method: 'POST',
headers: {

View File

@ -18,7 +18,6 @@ import {
Chip,
styled
} from '@/lib/mui'
import { fetchBaseURL } from '@/app/datastores/constants'
const { Dragger } = Upload
@ -87,7 +86,7 @@ const Index = () => {
}
useEffect(() => {
async function fetchData() {
const res = await fetch(`${fetchBaseURL}/knowledge/space/list`, {
const res = await fetch(`${process.env.API_BASE_URL}/knowledge/space/list`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@ -237,7 +236,7 @@ const Index = () => {
message.error('please input the name')
return
}
const res = await fetch(`${fetchBaseURL}/knowledge/space/add`, {
const res = await fetch(`${process.env.API_BASE_URL}/knowledge/space/add`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
@ -254,7 +253,7 @@ const Index = () => {
message.success('success')
setActiveStep(1)
const res = await fetch(
`${fetchBaseURL}/knowledge/space/list`,
`${process.env.API_BASE_URL}/knowledge/space/list`,
{
method: 'POST',
headers: {
@ -371,7 +370,7 @@ const Index = () => {
return
}
const res = await fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/add`,
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/add`,
{
method: 'POST',
headers: {
@ -401,7 +400,7 @@ const Index = () => {
formData.append('doc_file', originFileObj)
formData.append('doc_type', 'DOCUMENT')
const res = await fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/upload`,
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/upload`,
{
method: 'POST',
body: formData
@ -420,7 +419,7 @@ const Index = () => {
return
}
const res = await fetch(
`${fetchBaseURL}/knowledge/${knowledgeSpaceName}/document/add`,
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/add`,
{
method: 'POST',
headers: {

View File

@ -1,7 +1,7 @@
"use client";
import { useRequest } from 'ahooks';
import { useState } from 'react';
import { Button, Input, useColorScheme } from '@/lib/mui';
import { Button, Input, useColorScheme, Box, buttonClasses } from '@/lib/mui';
import IconButton from '@mui/joy/IconButton';
import SendRoundedIcon from '@mui/icons-material/SendRounded';
import { zodResolver } from '@hookform/resolvers/zod';
@ -38,25 +38,30 @@ export default function Home() {
};
return (
<>
<div className={`absolute z-20 top-0 inset-x-0 flex justify-center overflow-hidden pointer-events-none`}>
<div className='w-[108rem] flex-none flex justify-end'>
<picture>
<source srcSet='/bg1.avif' type='image/avif'></source>
<img srcSet='/bg2.png' alt="" className='w-[71.75rem] flex-none max-w-none '/>
</picture>
</div>
</div>
<div className='mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl'>
<div className='lg:my-auto grid gap-8 lg:grid-cols-3'>
<div className='lg:col-span-3 lg:mt-12'>
<p className='mb-3'>Scenes</p>
<div className='grid gap-2 lg:grid-cols-3 lg:gap-4'>
<>
<div className='mx-auto justify-end flex max-w-3xl flex-col h-3/4 gap-6 px-5 pt-6 sm:gap-16 xl:max-w-4xl'>
<div className='grid gap-8 lg:grid-cols-3'>
<div className='lg:col-span-3'>
<p className='mb-8 text-center text-2xl'>Scenes</p>
<Box
className='grid gap-2 lg:grid-cols-3 lg:gap-6'
sx={{
[`& .${buttonClasses.root}`]: {
color: 'var(--joy-palette-primary-solidColor)',
backgroundColor: 'var(--joy-palette-primary-solidBg)',
height: '52px',
'&: hover': {
backgroundColor: 'var(--joy-palette-primary-solidHoverBg)',
}
}
}}
>
{scenesList?.data?.map(scene => (
<Button
key={scene['chat_scene']}
size="md"
variant="soft"
variant="solid"
className='text-base rounded-none '
onClick={async () => {
const res = await sendPostRequest('/v1/chat/dialogue/new', {
chat_mode: scene['chat_scene']
@ -69,42 +74,42 @@ export default function Home() {
{scene['scene_name']
}</Button>
))}
</div>
</Box>
</div>
</div>
<div className='h-60 flex-none'></div>
</div>
<div className='pointer-events-none absolute inset-x-0 bottom-0 z-0 mx-auto flex w-full max-w-3xl flex-col items-center justify-center px-3.5 py-4 max-md:border-t sm:px-5 md:py-8 xl:max-w-4xl [&>*]:pointer-events-auto'>
<form
style={{
maxWidth: '100%',
width: '100%',
position: 'relative',
display: 'flex',
marginTop: 'auto',
overflow: 'visible',
background: 'none',
justifyContent: 'center',
marginLeft: 'auto',
marginRight: 'auto',
}}
onSubmit={(e) => {
methods.handleSubmit(submit)(e);
}}
>
<Input
sx={{ width: '100%' }}
variant="outlined"
placeholder='Ask anything'
endDecorator={
<IconButton type="submit" disabled={isLoading}>
<SendRoundedIcon />
</IconButton>
}
{...methods.register('query')}
/>
</form>
<div className='mt-6 pointer-events-none inset-x-0 bottom-0 z-0 mx-auto flex w-full max-w-3xl flex-col items-center justify-center max-md:border-t xl:max-w-4xl [&>*]:pointer-events-auto'>
<form
style={{
maxWidth: '100%',
width: '100%',
position: 'relative',
display: 'flex',
marginTop: 'auto',
overflow: 'visible',
background: 'none',
justifyContent: 'center',
marginLeft: 'auto',
marginRight: 'auto',
}}
onSubmit={(e) => {
methods.handleSubmit(submit)(e);
}}
>
<Input
sx={{ width: '100%' }}
variant="outlined"
placeholder='Ask anything'
endDecorator={
<IconButton type="submit" disabled={isLoading}>
<SendRoundedIcon />
</IconButton>
}
{...methods.register('query')}
/>
</form>
</div>
</div>
</>
)

View File

@ -27,7 +27,7 @@ const AgentPage = (props: {
});
const { history, handleChatSubmit } = useAgentChat({
queryAgentURL: `http://30.183.153.109:5000/v1/chat/completions`,
queryAgentURL: `/v1/chat/completions`,
queryBody: {
conv_uid: props.params?.agentId,
chat_mode: props.searchParams?.scene || 'chat_normal',

View File

@ -2,14 +2,14 @@
import React, { useEffect, useMemo } from 'react';
import { usePathname, useRouter } from 'next/navigation';
import Link from 'next/link';
import { Popconfirm } from 'antd';
import { Modal } from 'antd';
import { Box, List, ListItem, ListItemButton, ListItemDecorator, ListItemContent, Typography, Button, useColorScheme, IconButton } from '@/lib/mui';
import Article from '@mui/icons-material/Article';
import DarkModeIcon from '@mui/icons-material/DarkMode';
import WbSunnyIcon from '@mui/icons-material/WbSunny';
import MenuIcon from '@mui/icons-material/Menu';
import AddIcon from '@mui/icons-material/Add';
import { useDialogueContext } from '@/app/context/dialogue';
import SmsOutlinedIcon from '@mui/icons-material/SmsOutlined';import { useDialogueContext } from '@/app/context/dialogue';
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
import { sendPostRequest } from '@/utils/request';
@ -110,6 +110,7 @@ const LeftSider = () => {
aria-labelledby="nav-list-browse"
sx={{
'& .JoyListItemButton-root': { p: '8px' },
gap: '4px'
}}
>
{dialogueList?.data?.map((each) => {
@ -119,32 +120,46 @@ const LeftSider = () => {
<ListItemButton
selected={isSelect}
variant={isSelect ? 'soft' : 'plain'}
sx={{
'&:hover .del-btn': {
visibility: 'visible'
}
}}
>
<ListItemContent>
<Link href={`/agents/${each.conv_uid}?scene=${each?.chat_mode}`}>
<Link href={`/agents/${each.conv_uid}?scene=${each?.chat_mode}`} className="flex items-center justify-between">
<Typography fontSize={14} noWrap={true}>
<SmsOutlinedIcon className='mr-2' />
{each?.user_name || each?.user_input || 'undefined'}
</Typography>
<IconButton
color="neutral"
variant="plain"
size="sm"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
Modal.confirm({
title: 'Delete Chat',
content: 'Are you sure delete this chat?',
width: '276px',
centered: true,
async onOk() {
await sendPostRequest(`v1/chat/dialogue/delete?con_uid=${each.conv_uid}`);
await refreshDialogList();
if (pathname === `/agents/${each.conv_uid}`) {
router.push('/');
}
}
})
}}
className='del-btn invisible'
>
<DeleteOutlineOutlinedIcon />
</IconButton>
</Link>
</ListItemContent>
</ListItemButton>
<Popconfirm
title="删除对话"
description="确认要删除该对话吗"
onConfirm={async() => {
await sendPostRequest(`v1/chat/dialogue/delete?con_uid=${each.conv_uid}`);
await refreshDialogList();
if (pathname === `/agents/${each.conv_uid}`) {
router.push('/');
}
}}
okText="Yes"
cancelText="No"
>
<IconButton color="neutral" variant="plain">
<DeleteOutlineOutlinedIcon />
</IconButton>
</Popconfirm>
</ListItem>
)
})}
@ -157,6 +172,8 @@ const LeftSider = () => {
<Box
sx={{
p: 2,
pt: 3,
pb: 6,
borderTop: '1px solid',
borderColor: 'divider',
display: {
@ -183,6 +200,7 @@ const LeftSider = () => {
<ListItem>
<ListItemButton
color="neutral"
sx={{ marginBottom: 1, height: '2.5rem' }}
selected={each.active}
variant={each.active ? 'soft' : 'plain'}
>
@ -202,6 +220,7 @@ const LeftSider = () => {
</ListItem>
<ListItem>
<ListItemButton
sx={{ height: '2.5rem' }}
onClick={handleChangeTheme}
>
<ListItemDecorator>

View File

@ -7,7 +7,11 @@ export const joyTheme = extendTheme({
palette: {
mode: 'dark',
primary: {
...colors.purple,
...colors.grey,
solidBg: '#dfdfdf91',
solidColor: '#4e4e4e',
solidHoverBg: '#d5d5d5',
outlinedColor: '#4e4e59'
},
neutral: {
plainColor: '#4d4d4d',
@ -21,16 +25,13 @@ export const joyTheme = extendTheme({
surface: '#fff'
},
text: {
primary: '#25252D'
primary: '#505050'
},
},
},
dark: {
palette: {
mode: 'light',
primary: {
...colors.purple,
},
neutral: {
plainColor: '#D8D8DF',
plainHoverColor: '#F7F7F8',

View File

@ -49,7 +49,7 @@ import { useDialogueContext } from '@/app/context/dialogue';
const ctrl = new AbortController();
let buffer = '';
await fetchEventSource(queryAgentURL, {
await fetchEventSource(`${process.env.API_BASE_URL + queryAgentURL}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',

View File

@ -6,6 +6,9 @@ const nextConfig = {
},
typescript: {
ignoreBuildErrors: true
},
env: {
API_BASE_URL: process.env.API_BASE_URL || 'http://30.183.154.76:5000'
}
}

View File

@ -0,0 +1,14 @@
import axios from 'axios';
const api = axios.create({
baseURL: process.env.API_BASE_URL,
});
api.defaults.timeout = 10000;
api.interceptors.response.use(
response => response.data,
err => Promise.reject(err)
);
export default api;

View File

@ -1,16 +1,7 @@
import { message } from 'antd';
import axios from 'axios';
import axios from './ctx-axios';
import { isPlainObject } from 'lodash';
axios.defaults.baseURL = 'http://30.183.153.109:5000';
axios.defaults.timeout = 10000;
axios.interceptors.response.use(
response => response.data,
err => Promise.reject(err)
);
const DEFAULT_HEADERS = {
'content-type': 'application/json',
};