Skip to content

Commit 8569be6

Browse files
authored
Feat docs (#82)
* feat(AzureOpenAI): 添加resource_name字段支持Azure OpenAI资源名称 在Azure OpenAI集成中添加resource_name字段用于指定资源名称,并自动生成base_url。同时禁用AzureOpenAI提供商的urlWrite选项,强制使用资源名称生成URL。添加相关表单验证和自动填充逻辑。 * feat(模型弹窗): 添加模型教程链接字段并在UI中显示 为模型提供商配置添加addingModelTutorial字段,用于存储添加模型的教程链接 在API地址输入框旁添加教程链接按钮,点击可跳转到对应教程页面
1 parent d160483 commit 8569be6

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

ui/ModelModal/src/ModelModal.tsx

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
115115
api_version: '',
116116
api_header_key: '',
117117
api_header_value: '',
118+
resource_name: '',
118119
// 重置高级设置
119120
context_window_size: 64000,
120121
max_output_tokens: 8192,
@@ -157,6 +158,14 @@ export const ModelModal: React.FC<ModelModalProps> = ({
157158
return forceUseOriginalHost() ? baseUrl : `${baseUrl}/v1`;
158159
};
159160

161+
// 从Azure OpenAI base_url中提取resource_name
162+
const extractResourceNameFromUrl = (baseUrl: string): string => {
163+
if (!baseUrl) return '';
164+
// 匹配 https://<resource_name>.openai.azure.com 格式
165+
const match = baseUrl.match(/https:\/\/([^.]+)\.openai\.azure\.com/);
166+
return match ? match[1] : '';
167+
};
168+
160169
const getModel = (value: AddModelForm) => {
161170
let header = '';
162171
if (value.api_header_key && value.api_header_value) {
@@ -337,6 +346,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
337346
api_header_value: value.api_header?.split('=')[1] || '',
338347
model_type,
339348
show_name: value.show_name || '',
349+
resource_name: value.provider === 'AzureOpenAI' ? extractResourceNameFromUrl(value.base_url || '') : '',
340350
context_window_size: 64000,
341351
max_output_tokens: 8192,
342352
enable_r1_params: false,
@@ -355,6 +365,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
355365
api_header_key: value.api_header?.split('=')[0] || '',
356366
api_header_value: value.api_header?.split('=')[1] || '',
357367
show_name: value.show_name || '',
368+
resource_name: value.provider === 'AzureOpenAI' ? extractResourceNameFromUrl(value.base_url || '') : '',
358369
context_window_size: value.param?.context_window || 64000,
359370
max_output_tokens: value.param?.max_tokens || 8192,
360371
enable_r1_params: value.param?.r1_enabled || false,
@@ -379,6 +390,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
379390
api_header_key: '',
380391
api_header_value: '',
381392
show_name: '',
393+
resource_name: '',
382394
// 高级设置默认值
383395
context_window_size: 64000,
384396
max_output_tokens: 8192,
@@ -533,6 +545,7 @@ export const ModelModal: React.FC<ModelModalProps> = ({
533545
api_header_key: '',
534546
api_header_value: '',
535547
show_name: '',
548+
resource_name: '',
536549
// 重置高级设置
537550
context_window_size: 64000,
538551
max_output_tokens: 8192,
@@ -571,12 +584,38 @@ export const ModelModal: React.FC<ModelModalProps> = ({
571584
},
572585
}}
573586
>
574-
<Box sx={{ fontSize: 14, lineHeight: '32px' }}>
575-
API 地址{' '}
576-
<Box component={'span'} sx={{ color: 'red' }}>
577-
*
587+
<Stack
588+
direction={'row'}
589+
alignItems={'center'}
590+
justifyContent={'space-between'}
591+
sx={{ fontSize: 14, lineHeight: '32px' }}
592+
>
593+
<Box>
594+
API 地址{' '}
595+
<Box component={'span'} sx={{ color: 'red' }}>
596+
*
597+
</Box>
578598
</Box>
579-
</Box>
599+
{providers[providerBrand].addingModelTutorial && (
600+
<Box
601+
component={'span'}
602+
sx={{
603+
color: 'info.main',
604+
cursor: 'pointer',
605+
ml: 1,
606+
textAlign: 'right',
607+
}}
608+
onClick={() =>
609+
window.open(
610+
providers[providerBrand].addingModelTutorial,
611+
'_blank'
612+
)
613+
}
614+
>
615+
添加模型教程
616+
</Box>
617+
)}
618+
</Stack>
580619
<Controller
581620
control={control}
582621
name='base_url'
@@ -765,6 +804,45 @@ export const ModelModal: React.FC<ModelModalProps> = ({
765804
)}
766805
{providerBrand === 'AzureOpenAI' && (
767806
<>
807+
<Box sx={{ fontSize: 14, lineHeight: '32px', mt: 2 }}>
808+
Resource Name
809+
<Box component={'span'} sx={{ color: 'red' }}>
810+
*
811+
</Box>
812+
</Box>
813+
<Controller
814+
control={control}
815+
name='resource_name'
816+
rules={{
817+
required: {
818+
value: true,
819+
message: 'Resource Name 不能为空',
820+
},
821+
}}
822+
render={({ field }) => (
823+
<TextField
824+
{...field}
825+
fullWidth
826+
size='small'
827+
error={!!errors.resource_name}
828+
helperText={errors.resource_name?.message}
829+
onChange={(e) => {
830+
field.onChange(e.target.value);
831+
// 动态更新base_url
832+
const resourceName = e.target.value;
833+
if (resourceName) {
834+
setValue('base_url', `https://${resourceName}.openai.azure.com`);
835+
} else {
836+
setValue('base_url', '');
837+
}
838+
setModelUserList([]);
839+
setValue('model_name', '');
840+
setSuccess(false);
841+
setAddModelError('');
842+
}}
843+
/>
844+
)}
845+
/>
768846
<Box sx={{ fontSize: 14, lineHeight: '32px', mt: 2 }}>
769847
API Version
770848
</Box>

ui/ModelModal/src/constants/providers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
128128
analysis: true,
129129
analysis_vl: true,
130130
modelDocumentUrl: 'https://github.com/ollama/ollama/tree/main/docs',
131+
addingModelTutorial: 'https://pandawiki.docs.baizhi.cloud/node/019a160d-0528-736a-b88e-32a2d1207f3e',
131132
defaultBaseUrl: 'http://172.17.0.1:11434',
132133
},
133134
SiliconFlow: {
@@ -166,7 +167,7 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
166167
label: 'AzureOpenAI',
167168
cn: 'Azure OpenAI',
168169
icon: 'ikun-azure',
169-
urlWrite: true,
170+
urlWrite: false,
170171
secretRequired: true,
171172
customHeader: false,
172173
chat: true,
@@ -264,6 +265,7 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
264265
analysis: true,
265266
analysis_vl: true,
266267
modelDocumentUrl: 'https://inference.readthedocs.io/zh-cn/v1.2.0/getting_started/installation.html#installation',
268+
addingModelTutorial: 'https://pandawiki.docs.baizhi.cloud/node/019a160d-0528-736a-b88e-32a2d1207f3e',
267269
defaultBaseUrl: 'http://172.17.0.1:9997',
268270
},
269271
gpustack: {
@@ -280,6 +282,7 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
280282
analysis: true,
281283
analysis_vl: true,
282284
modelDocumentUrl: 'https://docs.gpustack.ai/latest/quickstart/',
285+
addingModelTutorial: 'https://pandawiki.docs.baizhi.cloud/node/019a160d-0528-736a-b88e-32a2d1207f3e',
283286
defaultBaseUrl: 'http://172.17.0.1',
284287
},
285288
Yi: {
@@ -755,6 +758,7 @@ export const DEFAULT_MODEL_PROVIDERS: ModelProviderMap = {
755758
analysis: true,
756759
analysis_vl: true,
757760
modelDocumentUrl: '',
761+
addingModelTutorial: 'https://pandawiki.docs.baizhi.cloud/node/019a160d-0528-736a-b88e-32a2d1207f3e',
758762
defaultBaseUrl: '',
759763
},
760764
};

ui/ModelModal/src/types/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export interface ModelProviderConfig {
6060
analysis: boolean;
6161
analysis_vl: boolean;
6262
modelDocumentUrl?: string;
63+
addingModelTutorial?: string;
6364
defaultBaseUrl: string;
6465
}
6566

@@ -147,6 +148,7 @@ export interface AddModelForm {
147148
model_type: string;
148149
show_name: string;
149150
api_header: string;
151+
resource_name: string; // Azure OpenAI resource name
150152
// 高级设置字段
151153
context_window_size: number;
152154
max_output_tokens: number;

0 commit comments

Comments
 (0)