1
1
'use client' ;
2
2
3
- import { FC , useCallback } from 'react' ;
3
+ import { FC , useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
4
4
5
5
import { getModelsTopics } from '@/src/app/[lang]/models/actions' ;
6
6
import { TextInputField } from '@/src/components/Common/InputField/InputField' ;
7
7
import Multiselect from '@/src/components/Common/Multiselect/Multiselect' ;
8
8
import RadioField from '@/src/components/Common/RadioField/RadioField' ;
9
- import ReadonlyField from '@/src/components/Common/ReadonlyField/ReadonlyField' ;
10
9
import EntityAttachments from '@/src/components/EntityView/Properties/EntityAttachments' ;
11
10
import EntityIcon from '@/src/components/EntityView/Properties/EntityIcon' ;
12
11
import { EntitiesI18nKey , ModelViewI18nKey , TopicsI18nKey } from '@/src/constants/i18n' ;
13
12
import { RadioFieldOrientation } from '@/src/types/radio-orientation' ;
13
+ import { getModelsAdapters } from '@/src/app/[lang]/models/actions' ;
14
14
import { useI18n } from '@/src/locales/client' ;
15
15
import { DialModel , DialModelType } from '@/src/models/dial/model' ;
16
16
import { RadioButtonModel } from '@/src/models/radio-button' ;
17
+ import InputWithReadonlyParts from '@/src/components/Common/Input/InputWithReadonlyParts' ;
18
+ import { splitEndpoint } from '@/src/components/ModelView/ModelProperties/utils' ;
19
+ import { DialAdapter } from '@/src/models/dial/adapter' ;
20
+ import { useNotification } from '@/src/context/NotificationContext' ;
21
+ import { getErrorNotification } from '@/src/utils/notification' ;
17
22
18
23
interface Props {
19
24
model : DialModel ;
@@ -22,12 +27,30 @@ interface Props {
22
27
23
28
const ModelTypeProperties : FC < Props > = ( { model, onChangeModel } ) => {
24
29
const t = useI18n ( ) ;
30
+ const { showNotification } = useNotification ( ) ;
31
+ const showNotificationRef = useRef ( showNotification ) ;
32
+
33
+ const [ adapters , setAdapters ] = useState < DialAdapter [ ] > ( [ ] ) ;
34
+
35
+ const [ prefixPart , postfixPart ] = useMemo ( ( ) => {
36
+ return splitEndpoint ( model , adapters ) ;
37
+ } , [ model , adapters ] ) ;
25
38
26
39
const modelTypeRadio : RadioButtonModel [ ] = [
27
40
{ id : DialModelType . Chat , name : t ( ModelViewI18nKey . Chat ) } ,
28
41
{ id : DialModelType . Embedding , name : t ( ModelViewI18nKey . Embedding ) } ,
29
42
] ;
30
43
44
+ useEffect ( ( ) => {
45
+ getModelsAdapters ( ) . then ( ( res ) => {
46
+ if ( res . success ) {
47
+ setAdapters ( ( res . response as DialAdapter [ ] ) || [ ] ) ;
48
+ } else {
49
+ showNotificationRef . current ( getErrorNotification ( res . errorHeader , res . errorMessage ) ) ;
50
+ }
51
+ } ) ;
52
+ } , [ setAdapters ] ) ;
53
+
31
54
const onChangeType = useCallback (
32
55
( type : string ) => {
33
56
onChangeModel ( { ...model , type : type as DialModelType } ) ;
@@ -49,47 +72,67 @@ const ModelTypeProperties: FC<Props> = ({ model, onChangeModel }) => {
49
72
[ model , onChangeModel ] ,
50
73
) ;
51
74
75
+ const onChangeEndpoint = useCallback (
76
+ ( value : string ) => {
77
+ onChangeModel ( { ...model , endpointDeploymentName : value } ) ;
78
+ } ,
79
+ [ model , onChangeModel ] ,
80
+ ) ;
81
+
52
82
return (
53
83
< div className = "w-full flex flex-col gap-5" >
54
- < RadioField
55
- radioButtons = { modelTypeRadio }
56
- activeRadioButton = { model . type as string }
57
- elementId = "type"
58
- fieldTitle = { t ( ModelViewI18nKey . Type ) }
59
- orientation = { RadioFieldOrientation . Row }
60
- onChange = { onChangeType }
61
- />
62
- < ReadonlyField value = { model . endpoint } title = { t ( EntitiesI18nKey . Endpoint ) } />
63
- < TextInputField
64
- elementId = "overrideName"
65
- fieldTitle = { t ( ModelViewI18nKey . OverrideName ) }
66
- placeholder = { t ( ModelViewI18nKey . OverrideNamePlaceholder ) }
67
- value = { model . overrideName }
68
- onChange = { onChangeOverrideName }
69
- optional = { true }
84
+ < div className = "w-full lg:w-[35%]" >
85
+ < RadioField
86
+ radioButtons = { modelTypeRadio }
87
+ activeRadioButton = { model . type as string }
88
+ elementId = "type"
89
+ fieldTitle = { t ( ModelViewI18nKey . Type ) }
90
+ orientation = { RadioFieldOrientation . Row }
91
+ onChange = { onChangeType }
92
+ />
93
+ </ div >
94
+
95
+ < InputWithReadonlyParts
96
+ inputId = "endpoint"
97
+ value = { model . endpointDeploymentName }
98
+ fullValue = { model . endpoint }
99
+ title = { t ( EntitiesI18nKey . Endpoint ) }
100
+ postfixPart = { postfixPart }
101
+ prefixPart = { prefixPart }
102
+ onChange = { onChangeEndpoint }
70
103
/>
71
- { model . type === DialModelType . Chat && (
72
- < >
73
- < EntityIcon
74
- fieldTitle = { t ( EntitiesI18nKey . Icon ) }
75
- elementId = "icon"
76
- entity = { model }
77
- onChangeEntity = { onChangeModel }
78
- />
79
- < Multiselect
80
- elementId = "topics"
81
- selectedItems = { model . topics }
82
- getItems = { getModelsTopics }
83
- allItems = { model . topics }
84
- onChangeItems = { onChangeItems }
85
- heading = { t ( TopicsI18nKey . Topics ) }
86
- title = { t ( TopicsI18nKey . Topics ) }
87
- addPlaceholder = { t ( TopicsI18nKey . AddTopicPlaceholder ) }
88
- addTitle = { t ( TopicsI18nKey . AddTopic ) }
89
- />
90
- < EntityAttachments entity = { model } onChangeEntity = { onChangeModel } />
91
- </ >
92
- ) }
104
+ < div className = "w-full flex flex-col gap-5 lg:w-[35%]" >
105
+ < TextInputField
106
+ elementId = "overrideName"
107
+ fieldTitle = { t ( ModelViewI18nKey . OverrideName ) }
108
+ placeholder = { t ( ModelViewI18nKey . OverrideNamePlaceholder ) }
109
+ value = { model . overrideName }
110
+ onChange = { onChangeOverrideName }
111
+ optional = { true }
112
+ />
113
+ { model . type === DialModelType . Chat && (
114
+ < >
115
+ < EntityIcon
116
+ fieldTitle = { t ( EntitiesI18nKey . Icon ) }
117
+ elementId = "icon"
118
+ entity = { model }
119
+ onChangeEntity = { onChangeModel }
120
+ />
121
+ < Multiselect
122
+ elementId = "topics"
123
+ selectedItems = { model . topics }
124
+ getItems = { getModelsTopics }
125
+ allItems = { model . topics }
126
+ onChangeItems = { onChangeItems }
127
+ heading = { t ( TopicsI18nKey . Topics ) }
128
+ title = { t ( TopicsI18nKey . Topics ) }
129
+ addPlaceholder = { t ( TopicsI18nKey . AddTopicPlaceholder ) }
130
+ addTitle = { t ( TopicsI18nKey . AddTopic ) }
131
+ />
132
+ < EntityAttachments entity = { model } onChangeEntity = { onChangeModel } />
133
+ </ >
134
+ ) }
135
+ </ div >
93
136
</ div >
94
137
) ;
95
138
} ;
0 commit comments