11import { useState , useEffect , useRef , useMemo } from 'react'
22import cn from 'classnames'
3+ import { useChatgpt } from '../chatbot-hooks'
34import styles from './EditPresetForm.module.scss'
45import dropdown_styles from '@ui/components/editor/common/Dropdown/Dropdown.module.scss'
56import { Preset } from '@shared/types/preset'
67import { CHATBOTS } from '@shared/constants/chatbots'
78import { Field } from '@ui/components/editor/panel/Field'
89import { Slider } from '@ui/components/editor/panel/Slider'
9- import { Checkbox } from '@ui/components/editor/common/Checkbox'
1010import { Input } from '@ui/components/editor/common/Input'
1111import { Textarea } from '@ui/components/editor/common/Textarea'
1212import { Dropdown } from '@ui/components/editor/common/Dropdown'
1313import { BackendMessage } from '@/views/panel/types/messages'
1414import { Scrollable } from '@ui/components/editor/panel/Scrollable'
15+ import { Options } from '../chatbot-overrides/options'
1516
1617type Props = {
1718 preset : Preset
@@ -78,8 +79,10 @@ export const EditPresetForm: React.FC<Props> = (props) => {
7879 }
7980 } , [ model_info ] )
8081
82+ useChatgpt ( { chatbot, new_url, set_options } )
83+
8184 const supports_temperature = chatbot_config ?. supports_custom_temperature
82- const supports_top_p = chatbot_config ?. supports_custom_top_p
85+ const supports_top_p = chatbot_config ?. default_top_p !== undefined
8386 const supports_thinking_budget = chatbot_config ?. supports_thinking_budget
8487 const supports_reasoning_effort =
8588 chatbot_config ?. supports_reasoning_effort ||
@@ -90,7 +93,6 @@ export const EditPresetForm: React.FC<Props> = (props) => {
9093 const supports_url_override = chatbot_config ?. supports_url_override
9194 const supports_user_provided_model =
9295 chatbot_config ?. supports_user_provided_model
93- const supported_options = chatbot_config ?. supported_options || { }
9496
9597 useEffect ( ( ) => {
9698 if ( chatbot ) {
@@ -100,7 +102,9 @@ export const EditPresetForm: React.FC<Props> = (props) => {
100102 ...( prompt_prefix ? { prompt_prefix } : { } ) ,
101103 ...( prompt_suffix ? { prompt_suffix } : { } ) ,
102104 ...( temperature !== undefined ? { temperature } : { } ) ,
103- ...( top_p !== CHATBOTS [ chatbot ] . default_top_p ? { top_p } : { } ) ,
105+ ...( ! supports_top_p || top_p !== chatbot_config . default_top_p
106+ ? { top_p }
107+ : { } ) ,
104108 ...( thinking_budget !== undefined ? { thinking_budget } : { } ) ,
105109 ...( reasoning_effort ? { reasoning_effort } : { } ) ,
106110 ...( model ? { model } : { } ) ,
@@ -134,16 +138,6 @@ export const EditPresetForm: React.FC<Props> = (props) => {
134138 options
135139 ] )
136140
137- let url_override_label = 'New URL'
138- let url_override_info = 'Enter link of a project, space, etc.'
139- if ( chatbot == 'ChatGPT' ) {
140- url_override_label = 'Project URL'
141- url_override_info = 'Enter link of a project'
142- } else if ( chatbot == 'Perplexity' ) {
143- url_override_label = 'Space URL'
144- url_override_info = 'Enter link of a space'
145- }
146-
147141 const handle_chatbot_change = ( new_chatbot : keyof typeof CHATBOTS ) => {
148142 set_chatbot ( new_chatbot )
149143 set_model ( Object . keys ( CHATBOTS [ new_chatbot ] . models ) [ 0 ] || undefined )
@@ -327,9 +321,8 @@ export const EditPresetForm: React.FC<Props> = (props) => {
327321
328322 { supports_url_override && (
329323 < Field
330- label = { url_override_label }
324+ label = { chatbot_config ?. url_override_label || 'URL override' }
331325 html_for = "new-url"
332- info = { url_override_info }
333326 >
334327 < Input
335328 id = "new-url"
@@ -358,25 +351,13 @@ export const EditPresetForm: React.FC<Props> = (props) => {
358351 </ Field >
359352 ) }
360353
361- { Object . keys ( supported_options ) . length > 0 && (
362- < Field label = "Options" >
363- < div className = { styles . options } >
364- { Object . entries ( supported_options ) . map ( ( [ key , label ] ) => {
365- const model_info = model ? ( models as any ) [ model ] : undefined
366- if ( model_info ?. disabled_options ?. includes ( key ) ) return null
367- return (
368- < label key = { key } className = { styles . options__item } >
369- < Checkbox
370- checked = { options . includes ( key ) }
371- on_change = { ( ) => handle_option_toggle ( key ) }
372- />
373- { label as any }
374- </ label >
375- )
376- } ) }
377- </ div >
378- </ Field >
379- ) }
354+ < Options
355+ chatbot = { chatbot }
356+ model = { model }
357+ options = { options }
358+ new_url = { new_url }
359+ on_option_toggle = { handle_option_toggle }
360+ />
380361
381362 { supports_temperature && (
382363 < Field
0 commit comments