@@ -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 ( / h t t p s : \/ \/ ( [ ^ . ] + ) \. o p e n a i \. a z u r e \. c o m / ) ;
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 >
0 commit comments