fix: model list watch data

This commit is contained in:
jialin
2024-07-15 08:21:06 +08:00
parent 0a0b96735c
commit ec28523daa
17 changed files with 119 additions and 61 deletions
@@ -121,7 +121,7 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
</Col>
<Col span={5}>
<span style={{ paddingLeft: 38 }}>
{dayjs(item.updated_at).format('YYYY-MM-DD HH:mm:ss')}
{dayjs.utc(item.created_at).format('YYYY-MM-DD HH:mm:ss')}
</span>
</Col>
<Col span={4}>
+1 -2
View File
@@ -371,8 +371,7 @@ const Models: React.FC<ModelsProps> = ({
showSorterTooltip={false}
sorter={true}
render={(val, row) => {
console.log('val=====', val, row['created_at'], row.name);
return dayjs(val).format('YYYY-MM-DD HH:mm:ss');
return dayjs.utc(val).format('YYYY-MM-DD HH:mm:ss');
}}
/>
<SealColumn
@@ -15,7 +15,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const { open, url, onCancel } = props || {};
const [modalSize, setModalSize] = useState<any>({
width: 600,
height: 450
height: 420
});
const isFullScreenRef = React.useRef(false);
const intl = useIntl();
@@ -24,7 +24,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
setModalSize((size: any) => {
return {
width: size.width === 600 ? '100%' : 600,
height: size.height === 450 ? 'calc(100vh - 100px)' : 450
height: size.height === 420 ? 'calc(100vh - 100px)' : 420
};
});
};
+7 -2
View File
@@ -30,7 +30,8 @@ const Models: React.FC = () => {
dataSourceRef.current = dataSource;
const { updateChunkedList } = useUpdateChunkedList({
const { updateChunkedList, cacheDataListRef } = useUpdateChunkedList({
dataList: dataSource,
setDataList: setDataSource
});
@@ -46,7 +47,9 @@ const Models: React.FC = () => {
cancelToken: axiosToken.token
});
console.log('res=======', res);
setDataSource(res.items);
if (!firstLoad) {
setDataSource(res.items);
}
setTotal(res.pagination.total);
} catch (error) {
setDataSource([]);
@@ -118,8 +121,10 @@ const Models: React.FC = () => {
if (!firstLoad) {
createModelsChunkRequest();
}
createModelsChunkRequest();
return () => {
chunkRequedtRef.current?.current?.cancel?.();
cacheDataListRef.current = [];
};
}, [firstLoad]);
@@ -1,7 +1,8 @@
import EditorWrap from '@/components/editor-wrap';
import { BulbOutlined } from '@ant-design/icons';
import Editor from '@monaco-editor/react';
import { useIntl } from '@umijs/max';
import { Modal, Spin } from 'antd';
import { Button, Modal, Spin } from 'antd';
import _ from 'lodash';
import React, { useEffect, useRef, useState } from 'react';
@@ -30,6 +31,8 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const [codeValue, setCodeValue] = useState('');
const [lang, setLang] = useState('shell');
const BaseURL = `${window.location.origin}/v1-openai/chat/completions`;
const langOptions = [
{ label: 'Curl', value: 'shell' },
{ label: 'Python', value: 'python' },
@@ -66,7 +69,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const systemList = systemMessage
? [{ role: 'system', content: systemMessage }]
: [];
const code = `import OpenAI from "openai";\nconst openai = new OpenAI();\n\nasync function main(){\nconst params = ${JSON.stringify(
const code = `import OpenAI from "openai";\nconst openai = new OpenAI();\n\nconst baseURL = "${BaseURL}"\n\nasync function main(){\nconst params = ${JSON.stringify(
{
...parameters,
messages: [...systemList, ...messageList]
@@ -92,7 +95,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const systemList = systemMessage
? [{ role: 'system', content: systemMessage }]
: [];
const code = `from openai import OpenAI\nclient = OpenAI()\n\ncompletion = client.chat.completions.create(\n${formattedParams} messages=${JSON.stringify([...systemList, ...messageList], null, 2)})\nprint(completion.choices[0].message)`;
const code = `from openai import OpenAI\nclient = OpenAI()\n\nbaseURL = ${BaseURL}\n\ncompletion = client.chat.completions.create(\n${formattedParams} messages=${JSON.stringify([...systemList, ...messageList], null, 2)})\nprint(completion.choices[0].message)`;
setCodeValue(code);
}
formatCode();
@@ -152,7 +155,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
onChangeLang={handleOnChangeLang}
>
<Editor
height="min(450px, 90vh)"
height={380}
theme="vs-dark"
className="monaco-editor"
defaultLanguage="shell"
@@ -162,6 +165,29 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
onMount={handleEditorDidMount}
/>
</EditorWrap>
<div style={{ marginTop: 10 }}>
<BulbOutlined className="m-r-8" />
<span>
{intl.formatMessage(
{ id: 'playground.viewcode.tips' },
{
here: (
<Button
type="link"
size="small"
href="#/api-keys"
target="_blank"
>
<span>
{' '}
{intl.formatMessage({ id: 'playground.viewcode.here' })}
</span>
</Button>
)
}
)}
</span>
</div>
</Spin>
</Modal>
</>