fix: playground view code

This commit is contained in:
jialin
2024-11-29 15:26:39 +08:00
parent 435161854c
commit cd1d3005e9
15 changed files with 243 additions and 88 deletions
@@ -251,6 +251,12 @@
} }
} }
:global(.ant-input-number.ant-input-number-disabled) {
&:hover {
background-color: inherit;
}
}
:global(.ant-input-outlined) { :global(.ant-input-outlined) {
display: flex; display: flex;
align-items: center; align-items: center;
+1 -1
View File
@@ -87,7 +87,7 @@ const SealSelect: React.FC<SelectProps & SealFormItemProps> = (props) => {
<Select <Select
{...rest} {...rest}
ref={inputRef} ref={inputRef}
options={_options} options={children ? null : _options}
onFocus={handleOnFocus} onFocus={handleOnFocus}
onBlur={handleOnBlur} onBlur={handleOnBlur}
onChange={handleChange} onChange={handleChange}
@@ -88,6 +88,7 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
value: `${item.worker_name}-${item.name}-${item.index}` value: `${item.worker_name}-${item.name}-${item.index}`
}; };
}); });
console.log('queryGPUList========', list);
setGpuOptions(list); setGpuOptions(list);
}; };
@@ -2,6 +2,7 @@ import AlertInfo from '@/components/alert-info';
import ScatterChart from '@/components/echarts/scatter'; import ScatterChart from '@/components/echarts/scatter';
import HighlightCode from '@/components/highlight-code'; import HighlightCode from '@/components/highlight-code';
import IconFont from '@/components/icon-font'; import IconFont from '@/components/icon-font';
import HotKeys, { KeyMap } from '@/config/hotkeys';
import useOverlayScroller from '@/hooks/use-overlay-scroller'; import useOverlayScroller from '@/hooks/use-overlay-scroller';
import useRequestToken from '@/hooks/use-request-token'; import useRequestToken from '@/hooks/use-request-token';
import { import {
@@ -28,6 +29,7 @@ import {
useRef, useRef,
useState useState
} from 'react'; } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { handleEmbedding } from '../apis'; import { handleEmbedding } from '../apis';
import { OpenAIViewCode } from '../config'; import { OpenAIViewCode } from '../config';
import { ParamsSchema } from '../config/types'; import { ParamsSchema } from '../config/types';
@@ -100,6 +102,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
]); ]);
const [scatterData, setScatterData] = useState<any[]>([]); const [scatterData, setScatterData] = useState<any[]>([]);
const resizeRef = useRef<any>(null);
const resizeMaxHeight = 400; const resizeMaxHeight = 400;
const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } = const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } =
@@ -264,6 +267,14 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
} }
}; };
const handleScaleResize = () => {
console.log('handleScaleResize', resizeRef.current);
const height = resizeRef.current?.state?.height;
if (height) {
setOutputHeight(height);
}
};
const handleDeleteFile = (uid: number | string) => { const handleDeleteFile = (uid: number | string) => {
setFileList((preList) => { setFileList((preList) => {
return preList.filter((item) => item.uid !== uid); return preList.filter((item) => item.uid !== uid);
@@ -374,6 +385,18 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
setTokenResult(null); setTokenResult(null);
}, [parameters.model]); }, [parameters.model]);
useHotkeys(
HotKeys.SUBMIT,
(e: any) => {
e.preventDefault();
handleSendMessage();
},
{
enabled: !loading,
preventDefault: true
}
);
useEffect(() => { useEffect(() => {
if (scroller.current) { if (scroller.current) {
initialize(scroller.current); initialize(scroller.current);
@@ -427,6 +450,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
{intl.formatMessage({ {intl.formatMessage({
id: 'playground.input.multiplePaste' id: 'playground.input.multiplePaste'
})} })}
<InfoCircleOutlined className="m-l-4" />
</Checkbox> </Checkbox>
</Tooltip> </Tooltip>
@@ -442,14 +466,25 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
{intl.formatMessage({ id: 'common.button.clear' })} {intl.formatMessage({ id: 'common.button.clear' })}
</Button> </Button>
{!loading ? ( {!loading ? (
<Tooltip
title={
<span>
[{KeyMap.SUBMIT.textKeybinding}]{' '}
{intl.formatMessage({ id: 'common.button.submit' })}
</span>
}
>
<Button <Button
size="middle" size="middle"
type="primary" type="primary"
disabled={inputEmpty} disabled={inputEmpty}
onClick={handleSendMessage} onClick={handleSendMessage}
icon={<SendOutlined rotate={0} className="font-size-14" />} icon={
<SendOutlined rotate={0} className="font-size-14" />
}
style={{ width: 60 }} style={{ width: 60 }}
></Button> ></Button>
</Tooltip>
) : ( ) : (
<Tooltip <Tooltip
title={intl.formatMessage({ id: 'common.button.stop' })} title={intl.formatMessage({ id: 'common.button.stop' })}
@@ -547,6 +582,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
</h3> </h3>
<div className="embed-chart"> <div className="embed-chart">
<Resizable <Resizable
ref={resizeRef}
enable={{ enable={{
top: true top: true
}} }}
@@ -577,13 +613,13 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
}} }}
maxHeight={resizeMaxHeight} maxHeight={resizeMaxHeight}
minHeight={180} minHeight={180}
onResize={handleScaleResize}
onResizeStop={handleScaleOutputSize} onResizeStop={handleScaleOutputSize}
> >
<div <div
style={{ style={{
border: '1px solid var(--ant-color-border)', border: '1px solid var(--ant-color-border)',
borderRadius: 'var(--border-radius-base)', borderRadius: 'var(--border-radius-base)',
overflow: 'hidden',
width: '100%' width: '100%'
}} }}
className="scatter " className="scatter "
@@ -622,7 +658,7 @@ const GroundEmbedding: React.FC<MessageProps> = forwardRef((props, ref) => {
<ViewCodeModal <ViewCodeModal
{...OpenAIViewCode.embeddings} {...OpenAIViewCode.embeddings}
open={show} open={show}
payLoad={{ payload={{
input: [ input: [
...textList.map((item) => item.text).filter((item) => item), ...textList.map((item) => item.text).filter((item) => item),
...fileList.map((item) => item.text).filter((item) => item) ...fileList.map((item) => item.text).filter((item) => item)
@@ -39,6 +39,7 @@ import '../style/system-message-wrap.less';
import DynamicParams from './dynamic-params'; import DynamicParams from './dynamic-params';
import MessageInput from './message-input'; import MessageInput from './message-input';
import ViewCodeModal from './view-code-modal'; import ViewCodeModal from './view-code-modal';
import ViewCommonCode from './view-common-code';
interface MessageProps { interface MessageProps {
modelList: Global.BaseOption<string>[]; modelList: Global.BaseOption<string>[];
@@ -73,45 +74,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
loading?: boolean; loading?: boolean;
progress?: number; progress?: number;
}[] }[]
>([ >([]);
// {
// dataUrl:
// 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
// height: 'auto',
// width: 'auto',
// uid: 0,
// span: 12,
// loading: false,
// progress: 60
// },
// {
// dataUrl:
// 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
// height: 'auto',
// width: 'auto',
// uid: 1,
// span: 12,
// progress: 15
// },
// {
// dataUrl:
// 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
// height: 'auto',
// width: 'auto',
// uid: 3,
// span: 12,
// progress: 10
// },
// {
// dataUrl:
// 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
// height: 'auto',
// width: 'auto',
// uid: 4,
// span: 12,
// progress: 15
// }
]);
const intl = useIntl(); const intl = useIntl();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
@@ -221,6 +184,7 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
const size: any = setImageSize(); const size: any = setImageSize();
setLoading(true); setLoading(true);
setMessageId(); setMessageId();
setTokenResult(null);
setCurrentPrompt(current?.content || ''); setCurrentPrompt(current?.content || '');
let newImageList = Array(parameters.n) let newImageList = Array(parameters.n)
@@ -309,9 +273,6 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
} }
}; };
const handleClear = () => { const handleClear = () => {
if (!imageList.length) {
return;
}
setMessageId(); setMessageId();
setImageList([]); setImageList([]);
setTokenResult(null); setTokenResult(null);
@@ -628,10 +589,11 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
</div> </div>
</div> </div>
{isOpenaiCompatible ? (
<ViewCodeModal <ViewCodeModal
{...OpenAIViewCode.images} {...OpenAIViewCode.images}
open={show} open={show}
payLoad={{ payload={{
prompt: currentPrompt prompt: currentPrompt
}} }}
parameters={{ parameters={{
@@ -640,6 +602,20 @@ const GroundImages: React.FC<MessageProps> = forwardRef((props, ref) => {
onCancel={handleCloseViewCode} onCancel={handleCloseViewCode}
title={intl.formatMessage({ id: 'playground.viewcode' })} title={intl.formatMessage({ id: 'playground.viewcode' })}
></ViewCodeModal> ></ViewCodeModal>
) : (
<ViewCommonCode
{...OpenAIViewCode.imageAdvanced}
open={show}
payload={{
prompt: currentPrompt
}}
parameters={{
...finalParameters
}}
onCancel={handleCloseViewCode}
title={intl.formatMessage({ id: 'playground.viewcode' })}
></ViewCommonCode>
)}
</div> </div>
); );
}); });
@@ -329,7 +329,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
<ViewCodeModal <ViewCodeModal
{...OpenAIViewCode.chat} {...OpenAIViewCode.chat}
open={show} open={show}
payLoad={{ payload={{
messages: viewCodeMessage messages: viewCodeMessage
}} }}
parameters={parameters} parameters={parameters}
@@ -1,6 +1,12 @@
import HotKeys, { KeyMap } from '@/config/hotkeys';
import useOverlayScroller from '@/hooks/use-overlay-scroller'; import useOverlayScroller from '@/hooks/use-overlay-scroller';
import useRequestToken from '@/hooks/use-request-token'; import useRequestToken from '@/hooks/use-request-token';
import { ClearOutlined, PlusOutlined, SendOutlined } from '@ant-design/icons'; import {
ClearOutlined,
InfoCircleOutlined,
PlusOutlined,
SendOutlined
} from '@ant-design/icons';
import { useIntl, useSearchParams } from '@umijs/max'; import { useIntl, useSearchParams } from '@umijs/max';
import { Button, Checkbox, Input, Spin, Tag, Tooltip } from 'antd'; import { Button, Checkbox, Input, Spin, Tag, Tooltip } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
@@ -15,14 +21,16 @@ import {
useRef, useRef,
useState useState
} from 'react'; } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { rerankerQuery } from '../apis'; import { rerankerQuery } from '../apis';
import { OpenAIViewCode } from '../config';
import { MessageItem, ParamsSchema } from '../config/types'; import { MessageItem, ParamsSchema } from '../config/types';
import '../style/ground-left.less'; import '../style/ground-left.less';
import '../style/rerank.less'; import '../style/rerank.less';
import '../style/system-message-wrap.less'; import '../style/system-message-wrap.less';
import DynamicParams from './dynamic-params'; import DynamicParams from './dynamic-params';
import InputList from './input-list'; import InputList from './input-list';
import ViewRerankCode from './view-rerank-code'; import ViewCommonCode from './view-common-code';
interface MessageProps { interface MessageProps {
modelList: Global.BaseOption<string>[]; modelList: Global.BaseOption<string>[];
@@ -113,6 +121,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
} }
]); ]);
const [sortIndexMap, setSortIndexMap] = useState<number[]>([]); const [sortIndexMap, setSortIndexMap] = useState<number[]>([]);
const queryValueRef = useRef<string>('');
const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } = const { initialize, updateScrollerPosition: updateDocumentScrollerPosition } =
useOverlayScroller(); useOverlayScroller();
@@ -305,10 +314,16 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
}; };
const handleSearch = (val: string) => { const handleSearch = (val: string) => {
console.log('val:', val); if (!val) {
return;
}
submitMessage({ content: val }); submitMessage({ content: val });
}; };
const handleQueryChange = (e: any) => {
queryValueRef.current = e.target.value;
};
const handleCloseViewCode = () => { const handleCloseViewCode = () => {
setShow(false); setShow(false);
}; };
@@ -409,6 +424,18 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
setTokenResult(null); setTokenResult(null);
}; };
useHotkeys(
HotKeys.SUBMIT,
(e: any) => {
e.preventDefault();
handleSearch(queryValueRef.current);
},
{
enabled: !loading,
preventDefault: true
}
);
useEffect(() => { useEffect(() => {
setMessageId(); setMessageId();
setMessageList([]); setMessageList([]);
@@ -450,8 +477,21 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
</h3> </h3>
<div style={{ margin: '16px 32px 10px' }}> <div style={{ margin: '16px 32px 10px' }}>
<Input.Search <Input.Search
allowClear
onSearch={handleSearch} onSearch={handleSearch}
enterButton={<SendOutlined rotate={0} className="font-size-14" />} onChange={handleQueryChange}
enterButton={
<Tooltip
title={
<span>
[{KeyMap.SUBMIT.textKeybinding}]{' '}
{intl.formatMessage({ id: 'common.button.submit' })}
</span>
}
>
<SendOutlined rotate={0} className="font-size-14" />
</Tooltip>
}
placeholder={intl.formatMessage({ placeholder={intl.formatMessage({
id: 'playground.rerank.query.holder' id: 'playground.rerank.query.holder'
})} })}
@@ -490,6 +530,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
{intl.formatMessage({ {intl.formatMessage({
id: 'playground.input.multiplePaste' id: 'playground.input.multiplePaste'
})} })}
<InfoCircleOutlined className="m-l-4" />
</Checkbox> </Checkbox>
</Tooltip> </Tooltip>
<Button size="middle" onClick={handleAddText}> <Button size="middle" onClick={handleAddText}>
@@ -557,7 +598,8 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
</div> </div>
</div> </div>
<ViewRerankCode <ViewCommonCode
{...OpenAIViewCode.rerank}
open={show} open={show}
payload={{ payload={{
documents: [...textList, ...fileList] documents: [...textList, ...fileList]
@@ -570,7 +612,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
}} }}
onCancel={handleCloseViewCode} onCancel={handleCloseViewCode}
title={intl.formatMessage({ id: 'playground.viewcode' })} title={intl.formatMessage({ id: 'playground.viewcode' })}
></ViewRerankCode> ></ViewCommonCode>
</div> </div>
); );
}); });
@@ -390,7 +390,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
<ViewCodeModal <ViewCodeModal
open={show} open={show}
payLoad={{}} payload={{}}
api="audio/transcriptions" api="audio/transcriptions"
clientType="audio.transcriptions" clientType="audio.transcriptions"
parameters={parameters} parameters={parameters}
@@ -342,7 +342,7 @@ const GroundLeft: React.FC<MessageProps> = forwardRef((props, ref) => {
<ViewCodeModal <ViewCodeModal
open={show} open={show}
payLoad={{ payload={{
input: currentPrompt input: currentPrompt
}} }}
api="audio/speech" api="audio/speech"
@@ -466,7 +466,7 @@ const ModelItem: React.FC<ModelItemProps> = forwardRef(
<ViewCodeModal <ViewCodeModal
{...OpenAIViewCode.chat} {...OpenAIViewCode.chat}
open={show} open={show}
payLoad={{ payload={{
messages: viewCodeMessage messages: viewCodeMessage
}} }}
parameters={params} parameters={params}
+31
View File
@@ -13,3 +13,34 @@ Cuidado de la piel orgánico para piel sensible con aloe vera y manzanilla: Desc
新的化妆趋势注重鲜艳的颜色和创新的技巧:进入化妆艺术的新纪元,本季的化妆趋势以大胆的颜色和创新的技巧为主。无论是霓虹眼线还是全息高光,每一款妆容都能让您脱颖而出,展现独特魅力。 新的化妆趋势注重鲜艳的颜色和创新的技巧:进入化妆艺术的新纪元,本季的化妆趋势以大胆的颜色和创新的技巧为主。无论是霓虹眼线还是全息高光,每一款妆容都能让您脱颖而出,展现独特魅力。
新しいメイクのトレンドは鮮やかな色と革新的な技術に焦点を当てています: 今シーズンのメイクアップトレンドは、大胆な色彩と革新的な技術に注目しています。ネオンアイライナーからホログラフィックハイライターまで、クリエイティビティを解き放ち、毎回ユニークなルックを演出しましょう。 新しいメイクのトレンドは鮮やかな色と革新的な技術に焦点を当てています: 今シーズンのメイクアップトレンドは、大胆な色彩と革新的な技術に注目しています。ネオンアイライナーからホログラフィックハイライターまで、クリエイティビティを解き放ち、毎回ユニークなルックを演出しましょう。
asdfas
dfaf
defsdf
aloe
fd
Farbensdf
asdfasdf
asdfasdfas
dfafas
dfafasdf
saludadf
1
2
2
2
2
2
222
2
2
2
2
2
2
2
2
2
@@ -9,7 +9,7 @@ import React, { useMemo, useState } from 'react';
type ViewModalProps = { type ViewModalProps = {
systemMessage?: string; systemMessage?: string;
messageList?: any[]; messageList?: any[];
payLoad: Record<string, any>; payload: Record<string, any>;
parameters: any; parameters: any;
title: string; title: string;
api: string; api: string;
@@ -39,7 +39,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
clientType, clientType,
logcommand, logcommand,
onCancel, onCancel,
payLoad, payload,
parameters = {} parameters = {}
} = props || {}; } = props || {};
@@ -72,7 +72,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const code = `curl ${window.location.origin}/v1-openai/${api} \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify( const code = `curl ${window.location.origin}/v1-openai/${api} \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify(
{ {
...parameters, ...parameters,
...payLoad ...payload
}, },
null, null,
2 2
@@ -83,7 +83,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const code = `const OpenAI = require("openai");\n\nconst openai = new OpenAI({\n "apiKey": "YOUR_GPUSTACK_API_KEY",\n "baseURL": "${BaseURL}"\n});\n\nasync function main(){\n const params = ${JSON.stringify( const code = `const OpenAI = require("openai");\n\nconst openai = new OpenAI({\n "apiKey": "YOUR_GPUSTACK_API_KEY",\n "baseURL": "${BaseURL}"\n});\n\nasync function main(){\n const params = ${JSON.stringify(
{ {
...parameters, ...parameters,
...payLoad ...payload
}, },
null, null,
4 4
@@ -105,12 +105,12 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
}, },
'' ''
); );
const params = formatPyParams(payLoad); const params = formatPyParams(payload);
const code = `from openai import OpenAI\n\nclient = OpenAI(\n base_url="${BaseURL}", \n api_key="YOUR_GPUSTACK_API_KEY"\n)\n\nresponse = client.${clientType}(\n${formattedParams}${params})\n${printLog}`; const code = `from openai import OpenAI\n\nclient = OpenAI(\n base_url="${BaseURL}", \n api_key="YOUR_GPUSTACK_API_KEY"\n)\n\nresponse = client.${clientType}(\n${formattedParams}${params})\n${printLog}`;
return code; return code;
} }
return ''; return '';
}, [lang, payLoad, parameters, api, clientType, logcommand]); }, [lang, payload, parameters, api, clientType, logcommand]);
const handleOnChangeLang = (value: string) => { const handleOnChangeLang = (value: string) => {
setLang(value); setLang(value);
@@ -9,8 +9,9 @@ type ViewModalProps = {
parameters: any; parameters: any;
title: string; title: string;
open: boolean; open: boolean;
apiType?: string; api: string;
payload?: Record<string, any>; payload?: Record<string, any>;
logcommand: Record<string, any>;
onCancel: () => void; onCancel: () => void;
}; };
@@ -27,17 +28,25 @@ const langOptions = [
]; ];
const ViewCodeModal: React.FC<ViewModalProps> = (props) => { const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const { title, open, onCancel, payload, parameters = {} } = props || {}; const {
title,
open,
onCancel,
payload,
parameters = {},
api,
logcommand
} = props || {};
const intl = useIntl(); const intl = useIntl();
const [codeValue, setCodeValue] = useState(''); const [codeValue, setCodeValue] = useState('');
const [lang, setLang] = useState(langMap.shell); const [lang, setLang] = useState(langMap.shell);
const BaseURL = `${window.location.origin}/v1/rerank`; const BaseURL = `${window.location.origin}${api}`;
const generateCode = () => { const generateCode = () => {
if (lang === langMap.shell) { if (lang === langMap.shell) {
const code = `curl ${window.location.origin}/v1/rerank \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify( const code = `curl ${window.location.origin}${api} \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify(
{ {
...parameters, ...parameters,
...payload ...payload
@@ -55,7 +64,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
'Content-type': 'application/json', 'Content-type': 'application/json',
Authorization: `Bearer $\{YOUR_GPUSTACK_API_KEY}` Authorization: `Bearer $\{YOUR_GPUSTACK_API_KEY}`
}; };
const code = `import axios from 'axios';\n\nconst url = "${BaseURL}";\n\nconst headers = ${JSON.stringify(headers, null, 2)};\n\nconst data = ${JSON.stringify(data, null, 2)};\n\naxios.post(url, data, { headers }).then((response) => {\n console.log(response.data);\n});`; const code = `import axios from 'axios';\n\nconst url = "${BaseURL}";\n\nconst headers = ${JSON.stringify(headers, null, 2)};\n\nconst data = ${JSON.stringify(data, null, 2)};\n\naxios.post(url, data, { headers }).then((response) => {\n console.log(response.${logcommand.node});\n});`;
setCodeValue(code); setCodeValue(code);
} else if (lang === langMap.python) { } else if (lang === langMap.python) {
const data = { const data = {
@@ -66,7 +75,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
'Content-type': 'application/json', 'Content-type': 'application/json',
Authorization: `Bearer $\{YOUR_GPUSTACK_API_KEY}` Authorization: `Bearer $\{YOUR_GPUSTACK_API_KEY}`
}; };
const code = `import requests\n\nurl="${BaseURL}"\n\nheaders = ${JSON.stringify(headers, null, 2)}\n\ndata=${JSON.stringify(data, null, 2)}\n\nresponse = requests.post(url, headers=headers, json=data)\n\nprint(response.json())`; const code = `import requests\n\nurl="${BaseURL}"\n\nheaders = ${JSON.stringify(headers, null, 2)}\n\ndata=${JSON.stringify(data, null, 2)}\n\nresponse = requests.post(url, headers=headers, json=data)\n\nprint(response.${logcommand.python})`;
setCodeValue(code); setCodeValue(code);
} }
}; };
+15
View File
@@ -119,6 +119,21 @@ export const OpenAIViewCode = {
api: 'images/generations', api: 'images/generations',
clientType: 'images.generate', clientType: 'images.generate',
logcommand: 'data[0].b64_json' logcommand: 'data[0].b64_json'
},
imageAdvanced: {
api: '/v1/images/generations',
clientType: 'images.generate',
logcommand: {
python: 'json().data[0].b64_json',
node: 'data[0].b64_json'
}
},
rerank: {
api: '/v1/rerank',
logcommand: {
python: 'json()',
node: 'data'
}
} }
}; };
+39
View File
@@ -0,0 +1,39 @@
export default [
{
dataUrl:
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
height: 'auto',
width: 'auto',
uid: 0,
span: 12,
loading: false,
progress: 60
},
{
dataUrl:
'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
height: 'auto',
width: 'auto',
uid: 1,
span: 12,
progress: 15
},
{
dataUrl:
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
height: 'auto',
width: 'auto',
uid: 3,
span: 12,
progress: 10
},
{
dataUrl:
'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp',
height: 'auto',
width: 'auto',
uid: 4,
span: 12,
progress: 15
}
];