1
1
import { useState , useMemo , useEffect } from 'react' ;
2
2
import TextareaAutosize from 'react-textarea-autosize' ;
3
- import type { TPreset } from 'librechat-data-provider' ;
3
+ import type { Assistant , TPreset } from 'librechat-data-provider' ;
4
4
import type { TModelSelectProps , Option } from '~/common' ;
5
5
import { Label , HoverCard , SelectDropDown , HoverCardTrigger } from '~/components/ui' ;
6
6
import { cn , defaultTextProps , removeFocusOutlines , mapAssistants } from '~/utils' ;
@@ -20,15 +20,19 @@ export default function Settings({ conversation, setOption, models, readonly }:
20
20
const { model, endpoint, assistant_id, endpointType, promptPrefix, instructions } =
21
21
conversation ?? { } ;
22
22
23
+ const currentList = useMemo (
24
+ ( ) => Object . values ( assistantListMap ?. [ endpoint ?? '' ] ?? { } ) as Assistant [ ] ,
25
+ [ assistantListMap , endpoint ] ,
26
+ ) ;
27
+
23
28
const assistants = useMemo ( ( ) => {
24
- return [
25
- defaultOption ,
26
- ...( assistantListMap [ endpoint ?? '' ] ?? [ ] ) . map ( ( { id, name } ) => ( {
27
- label : name ,
28
- value : id ,
29
- } ) ) ,
30
- ] . filter ( Boolean ) ;
31
- } , [ assistantListMap , endpoint , defaultOption ] ) ;
29
+ const currentAssistants = ( currentList ?? [ ] ) . map ( ( { id, name } ) => ( {
30
+ label : name ,
31
+ value : id ,
32
+ } ) ) ;
33
+
34
+ return [ defaultOption , ...currentAssistants ] . filter ( Boolean ) ;
35
+ } , [ currentList , defaultOption ] ) ;
32
36
33
37
const [ onPromptPrefixChange , promptPrefixValue ] = useDebouncedInput ( {
34
38
setOption,
@@ -96,6 +100,9 @@ export default function Settings({ conversation, setOption, models, readonly }:
96
100
value : assistant . id ?? '' ,
97
101
} ) ;
98
102
setOption ( 'assistant_id' ) ( assistant . id ) ;
103
+ if ( assistant . model ) {
104
+ setModel ( assistant . model ) ;
105
+ }
99
106
} ;
100
107
101
108
const optionEndpoint = endpointType ?? endpoint ;
@@ -141,7 +148,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
141
148
< TextareaAutosize
142
149
id = "promptPrefix"
143
150
disabled = { readonly }
144
- value = { promptPrefixValue as string | undefined }
151
+ value = { ( promptPrefixValue as string | null | undefined ) ?? '' }
145
152
onChange = { onPromptPrefixChange }
146
153
placeholder = { localize ( 'com_endpoint_prompt_prefix_assistants_placeholder' ) }
147
154
className = { cn (
@@ -158,7 +165,7 @@ export default function Settings({ conversation, setOption, models, readonly }:
158
165
< TextareaAutosize
159
166
id = "instructions"
160
167
disabled = { readonly }
161
- value = { instructionsValue as string | undefined }
168
+ value = { ( instructionsValue as string | null | undefined ) ?? '' }
162
169
onChange = { onInstructionsChange }
163
170
placeholder = { localize ( 'com_endpoint_instructions_assistants_placeholder' ) }
164
171
className = { cn (
0 commit comments