Skip to content

Commit dcf1870

Browse files
committed
Merge remote-tracking branch 'github-pro/main' into feature/1.5-local-model
2 parents 61ae37d + 10488a6 commit dcf1870

4 files changed

Lines changed: 123 additions & 94 deletions

File tree

frontend/packages/common/src/components/aoplatform/BasicLayout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ function BasicLayout({ project = 'core' }: { project: string }) {
241241
headerTitleRender={() => (
242242
<div className="w-[192px] flex items-center">
243243
<img className="h-[20px] cursor-pointer " src={Logo} onClick={() => navigator(mainPage)} />
244+
<a className="align-text-top" href="https://github.com/APIParkLab/APIPark" target="_blank" className="ml-[5px] h-[25px] relative">
245+
<img src="https://img.shields.io/github/stars/APIParkLab/APIPark?style=social" className='absolute top-[6px]' width={75} alt="" />
246+
</a>
244247
</div>
245248
)}
246249
logo={Logo}

frontend/packages/core/src/const/ai-service/type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type AiServiceConfigFieldType = {
99
name?: string;
1010
id?: string;
1111
provider?:string
12+
model?:string
1213
prefix?:string;
1314
logo?:string;
1415
logoFile?:UploadFile;

frontend/packages/core/src/pages/aiService/api/AiServiceInsideRouterCreate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const AiServiceInsideRouterCreate = () => {
189189
const { code, data, msg } = response
190190
if (code === STATUS_CODE.SUCCESS) {
191191
setLlmList(data.models)
192-
const localId = id || aiServiceInfo?.id
192+
const localId = id || aiServiceInfo?.model
193193

194194
if (replaceDefaultLlm) {
195195
setDefaultLlm((prev) => {

frontend/packages/core/src/pages/system/SystemConfig.tsx

Lines changed: 118 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { LoadingOutlined } from '@ant-design/icons'
22
import WithPermission from '@common/components/aoplatform/WithPermission.tsx'
3-
import {
4-
BasicResponse,
5-
DELETE_TIPS,
6-
PLACEHOLDER,
7-
RESPONSE_TIPS,
8-
STATUS_CODE
9-
} from '@common/const/const.tsx'
3+
import { BasicResponse, DELETE_TIPS, PLACEHOLDER, RESPONSE_TIPS, STATUS_CODE } from '@common/const/const.tsx'
104
import { EntityItem, MemberItem, SimpleTeamItem } from '@common/const/type.ts'
115
import { useBreadcrumb } from '@common/contexts/BreadcrumbContext.tsx'
126
import { useGlobalContext } from '@common/contexts/GlobalStateContext.tsx'
@@ -50,15 +44,10 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
5044
const [tagOptionList, setTagOptionList] = useState<DefaultOptionType[]>([])
5145
const [serviceClassifyOptionList, setServiceClassifyOptionList] = useState<DefaultOptionType[]>()
5246
const [uploadLoading, setUploadLoading] = useState<boolean>(false)
53-
const {
54-
checkPermission,
55-
accessInit,
56-
getGlobalAccessData,
57-
state,
58-
aiConfigFlushed,
59-
setAiConfigFlushed
60-
} = useGlobalContext()
47+
const { checkPermission, accessInit, getGlobalAccessData, state, aiConfigFlushed, setAiConfigFlushed } =
48+
useGlobalContext()
6149
const [providerOptionList, setProviderOptionList] = useState<DefaultOptionType[]>()
50+
const [modelList, setModelList] = useState<DefaultOptionType[]>()
6251
const location = useLocation()
6352
const currentUrl = location.pathname
6453

@@ -77,18 +66,80 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
7766
fetchData<BasicResponse<{ providers: SimpleAiProviderItem[] }>>('simple/ai/providers/configured', {
7867
method: 'GET',
7968
eoTransformKeys: [],
80-
eoParams: { all: true}
81-
}).then(response => {
69+
eoParams: { all: true }
70+
}).then((response) => {
8271
const { code, data, msg } = response
8372
if (code === STATUS_CODE.SUCCESS) {
8473
const configuredProvider = data.providers
85-
?.filter(x => x.configured)
74+
?.filter((x) => x.configured)
8675
?.map((x: SimpleAiProviderItem) => {
8776
return { ...x, label: x.name, value: x.id }
8877
})
8978
setProviderOptionList(configuredProvider)
9079
if (!serviceId && configuredProvider.length > 0) {
9180
form.setFieldsValue({ provider: configuredProvider[0]?.id })
81+
if (configuredProvider[0]?.type === 'local') {
82+
getLocalModelList()
83+
} else {
84+
getOnlineModelList(configuredProvider[0]?.id)
85+
}
86+
}
87+
if (serviceId && configuredProvider.length > 0) {
88+
const providerID = form.getFieldValue('provider')
89+
const provider = configuredProvider?.find((item: any) => item.id === providerID)
90+
if (provider?.type === 'local') {
91+
getLocalModelList(false)
92+
} else {
93+
getOnlineModelList(provider?.id, false)
94+
}
95+
}
96+
} else {
97+
message.error(msg || $t(RESPONSE_TIPS.error))
98+
}
99+
})
100+
}
101+
102+
const modelProviderChange = (id: string) => {
103+
const provider = providerOptionList?.find((item) => item.id === id)
104+
if (provider?.type === 'local') {
105+
getLocalModelList()
106+
} else {
107+
getOnlineModelList(provider?.id)
108+
}
109+
}
110+
111+
const getLocalModelList = (setDefaultLlm = true) => {
112+
fetchData<BasicResponse<{ providers: any[] }>>('simple/ai/models/local/configured', {
113+
method: 'GET'
114+
}).then((response) => {
115+
const { code, data, msg } = response
116+
if (code === STATUS_CODE.SUCCESS) {
117+
const localModelList = data.models?.map((x: any) => {
118+
return { ...x, label: x.name, value: x.id }
119+
})
120+
setModelList(localModelList)
121+
if (setDefaultLlm && localModelList.length > 0) {
122+
form.setFieldsValue({ model: localModelList[0]?.id })
123+
}
124+
} else {
125+
message.error(msg || $t(RESPONSE_TIPS.error))
126+
}
127+
})
128+
}
129+
const getOnlineModelList = (id: string, setDefaultLlm = true) => {
130+
fetchData<BasicResponse<{ providers: any[] }>>('ai/provider/llms', {
131+
method: 'GET',
132+
eoParams: { provider: id },
133+
eoTransformKeys: ['default_llm']
134+
}).then((response) => {
135+
const { code, data, msg } = response
136+
if (code === STATUS_CODE.SUCCESS) {
137+
const localModelList = data.llms?.map((x: any) => {
138+
return { ...x, label: x.id, value: x.id }
139+
})
140+
setModelList(localModelList)
141+
if (setDefaultLlm && localModelList.length > 0) {
142+
form.setFieldsValue({ model: localModelList[0]?.id })
92143
}
93144
} else {
94145
message.error(msg || $t(RESPONSE_TIPS.error))
@@ -137,17 +188,15 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
137188
}
138189

139190
const uploadButton = (
140-
<div>
141-
{uploadLoading ? <LoadingOutlined /> : <Icon icon="ic:baseline-add" width="24" height="24" />}
142-
</div>
191+
<div>{uploadLoading ? <LoadingOutlined /> : <Icon icon="ic:baseline-add" width="24" height="24" />}</div>
143192
)
144193

145194
const getTagAndServiceClassifyList = () => {
146195
setTagOptionList([])
147196
setServiceClassifyOptionList([])
148197
fetchData<BasicResponse<{ catalogues: CategorizesType[]; tags: EntityItem[] }>>('catalogues', {
149198
method: 'GET'
150-
}).then(response => {
199+
}).then((response) => {
151200
const { code, data, msg } = response
152201
if (code === STATUS_CODE.SUCCESS) {
153202
setTagOptionList(
@@ -175,7 +224,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
175224
method: 'GET',
176225
eoParams: { team: teamId, service: serviceId },
177226
eoTransformKeys: ['team_id', 'service_type', 'approval_type', 'service_kind']
178-
}).then(response => {
227+
}).then((response) => {
179228
const { code, data, msg } = response
180229
if (code === STATUS_CODE.SUCCESS) {
181230
setTimeout(() => {
@@ -196,6 +245,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
196245
})
197246
setImageBase64(data.service.logo)
198247
setShowClassify(data.service.serviceType === 'public')
248+
getProviderOptionList()
199249
}, 0)
200250
} else {
201251
message.error(msg || $t(RESPONSE_TIPS.error))
@@ -204,21 +254,19 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
204254
}
205255

206256
const onFinish: () => Promise<boolean | string> = () => {
207-
return form.validateFields().then(value => {
257+
return form.validateFields().then((value) => {
208258
return fetchData<BasicResponse<{ service: { id: string } }>>(
209259
serviceId === undefined ? 'team/service' : 'service/info',
210260
{
211261
method: serviceId === undefined ? 'POST' : 'PUT',
212262
eoParams: {
213-
...(serviceId === undefined
214-
? { team: value.team }
215-
: { service: serviceId, team: teamId })
263+
...(serviceId === undefined ? { team: value.team } : { service: serviceId, team: teamId })
216264
},
217265
eoBody: { ...value, prefix: value.prefix?.trim() },
218266
eoTransformKeys: ['serviceType', 'approvalType', 'serviceKind']
219267
}
220268
)
221-
.then(response => {
269+
.then((response) => {
222270
const { code, data, msg } = response
223271
if (code === STATUS_CODE.SUCCESS) {
224272
message.success(msg || $t(RESPONSE_TIPS.success))
@@ -229,7 +277,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
229277
return Promise.reject(msg || $t(RESPONSE_TIPS.error))
230278
}
231279
})
232-
.catch(errorInfo => {
280+
.catch((errorInfo) => {
233281
return Promise.reject(errorInfo)
234282
})
235283
})
@@ -241,7 +289,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
241289
fetchData<BasicResponse<{ teams: SimpleTeamItem[] }>>(
242290
!checkPermission('system.workspace.team.view_all') ? 'simple/teams/mine' : 'simple/teams',
243291
{ method: 'GET', eoTransformKeys: [] }
244-
).then(response => {
292+
).then((response) => {
245293
const { code, data, msg } = response
246294
if (code === STATUS_CODE.SUCCESS) {
247295
setTeamOptionList(
@@ -262,7 +310,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
262310
fetchData<BasicResponse<null>>('team/service', {
263311
method: 'DELETE',
264312
eoParams: { team: teamId, service: serviceId }
265-
}).then(response => {
313+
}).then((response) => {
266314
const { code, msg } = response
267315
if (code === STATUS_CODE.SUCCESS) {
268316
message.success(msg || $t(RESPONSE_TIPS.success))
@@ -285,7 +333,6 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
285333
getTeamOptionList()
286334
})
287335
}
288-
getProviderOptionList()
289336
getTagAndServiceClassifyList()
290337
if (serviceId !== undefined) {
291338
setOnEdit(true)
@@ -299,6 +346,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
299346
}
300347
])
301348
} else {
349+
getProviderOptionList()
302350
setOnEdit(false)
303351
const id = uuidv4()
304352
form.setFieldValue('id', id)
@@ -333,7 +381,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
333381
// const serviceTypeOptions = useMemo(()=>SERVICE_KIND_OPTIONS.map((x)=>({...x, label:$t(x.label)})),[state.language]);
334382
// const visualizationOptions = useMemo(()=>SERVICE_VISUALIZATION_OPTIONS.map((x)=>({...x, label:$t(x.label)})),[state.language])
335383
const approvalOptions = useMemo(
336-
() => SERVICE_APPROVAL_OPTIONS.map(x => ({ ...x, label: $t(x.label) })),
384+
() => SERVICE_APPROVAL_OPTIONS.map((x) => ({ ...x, label: $t(x.label) })),
337385
[state.language]
338386
)
339387

@@ -364,21 +412,13 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
364412
name="id"
365413
rules={[{ required: true, whitespace: true }]}
366414
>
367-
<Input
368-
className="w-INPUT_NORMAL"
369-
disabled={onEdit}
370-
placeholder={$t(PLACEHOLDER.input)}
371-
/>
415+
<Input className="w-INPUT_NORMAL" disabled={onEdit} placeholder={$t(PLACEHOLDER.input)} />
372416
</Form.Item>
373417
{!onEdit && (
374-
<Form.Item<SystemConfigFieldType>
375-
label={$t('服务类型')}
376-
name="serviceKind"
377-
rules={[{ required: true }]}
378-
>
418+
<Form.Item<SystemConfigFieldType> label={$t('服务类型')} name="serviceKind" rules={[{ required: true }]}>
379419
<Radio.Group
380420
disabled={onEdit}
381-
onChange={e => {
421+
onChange={(e) => {
382422
setShowAI(e.target.value === 'ai')
383423
}}
384424
>
@@ -398,58 +438,51 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
398438
</Form.Item>
399439
)}
400440
{showAI && (
401-
<Form.Item<AiServiceConfigFieldType>
402-
label={$t('默认 AI 供应商')}
403-
name="provider"
404-
rules={[{ required: true }]}
405-
extra={
406-
serviceId
407-
? $t('创建 API 时会默认选择该供应商,修改默认供应商不会影响现有 API')
408-
: ''
409-
}
410-
>
411-
{providerOptionList && providerOptionList.length > 0 ? (
412-
<Select
413-
className="w-INPUT_NORMAL"
414-
placeholder={$t(PLACEHOLDER.input)}
415-
options={providerOptionList}
416-
></Select>
417-
) : (
418-
<p>
419-
{$t('未配置任何 AI 模型供应商,')}
420-
<a href="/aisetting" target="_blank" onClick={() => setAiConfigFlushed(false)}>
421-
{$t('立即配置')}
422-
</a>
423-
</p>
424-
)}
425-
</Form.Item>
441+
<>
442+
<Form.Item<AiServiceConfigFieldType>
443+
label={$t('默认 AI 供应商')}
444+
name="provider"
445+
rules={[{ required: true }]}
446+
extra={serviceId ? $t('创建 API 时会默认选择该供应商,修改默认供应商不会影响现有 API') : ''}
447+
>
448+
{providerOptionList && providerOptionList.length > 0 ? (
449+
<Select
450+
className="w-INPUT_NORMAL"
451+
placeholder={$t(PLACEHOLDER.input)}
452+
options={providerOptionList}
453+
onChange={(e) => {
454+
modelProviderChange(e)
455+
}}
456+
></Select>
457+
) : (
458+
<p>
459+
{$t('未配置任何 AI 模型供应商,')}
460+
<a href="/aisetting" target="_blank" onClick={() => setAiConfigFlushed(false)}>
461+
{$t('立即配置')}
462+
</a>
463+
</p>
464+
)}
465+
</Form.Item>
466+
<Form.Item<AiServiceConfigFieldType> label={$t('默认模型')} name="model" rules={[{ required: true }]}>
467+
<Select className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} options={modelList}></Select>
468+
</Form.Item>
469+
</>
426470
)}
427-
428471
<Form.Item<SystemConfigFieldType>
429472
label={$t('API 调用前缀')}
430473
name="prefix"
431-
extra={$t(
432-
'作为服务内所有API的前缀,比如host/{service_name}/{api_path},影响较大,谨慎修改'
433-
)}
474+
extra={$t('作为服务内所有API的前缀,比如host/{service_name}/{api_path},影响较大,谨慎修改')}
434475
rules={[
435476
{ required: true, whitespace: true },
436477
{
437478
validator: validateUrlSlash
438479
}
439480
]}
440481
>
441-
<Input
442-
prefix={onEdit ? '' : '/'}
443-
className="w-INPUT_NORMAL"
444-
placeholder={$t(PLACEHOLDER.input)}
445-
/>
482+
<Input prefix={onEdit ? '' : '/'} className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
446483
</Form.Item>
447484
{!onEdit && (
448-
<Form.Item<SystemConfigFieldType>
449-
label={$t('所属团队')}
450-
name="team"
451-
rules={[{ required: true }]}
452-
>
485+
<Form.Item<SystemConfigFieldType> label={$t('所属团队')} name="team" rules={[{ required: true }]}>
453486
<Select
454487
className="w-INPUT_NORMAL"
455488
disabled={onEdit}
@@ -459,11 +492,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
459492
</Form.Item>
460493
)}
461494

462-
<Form.Item<SystemConfigFieldType>
463-
label={$t('订阅审核')}
464-
name="approvalType"
465-
rules={[{ required: true }]}
466-
>
495+
<Form.Item<SystemConfigFieldType> label={$t('订阅审核')} name="approvalType" rules={[{ required: true }]}>
467496
<Radio.Group className="flex flex-col" options={approvalOptions} />
468497
</Form.Item>
469498

@@ -515,11 +544,7 @@ const SystemConfig = forwardRef<SystemConfigHandle>((_, ref) => {
515544
style={{ marginTop: 8 }}
516545
>
517546
{imageBase64 ? (
518-
<img
519-
src={imageBase64}
520-
alt="Logo"
521-
style={{ maxWidth: '200px', width: '68px', height: '68px' }}
522-
/>
547+
<img src={imageBase64} alt="Logo" style={{ maxWidth: '200px', width: '68px', height: '68px' }} />
523548
) : (
524549
uploadButton
525550
)}

0 commit comments

Comments
 (0)