@@ -21,6 +21,7 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
2121
2222 const [ selectedModel , setSelectedModel ] = useState ( null ) ;
2323 const [ textareaValue , setTextareaValue ] = useState ( '' ) ;
24+ const [ modelkey , setModelKey ] = useState ( '' ) ;
2425
2526 const collection = useCollectionStore . getState ( ) . collections . find ( ( c ) => c . id === collectionId ) ;
2627
@@ -55,7 +56,21 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
5556 Use our AI to generate the flow
5657 </ Dialog . Title >
5758 < div className = 'mt-6' >
58- < Listbox value = { selectedModel } onChange = { setSelectedModel } >
59+ < Listbox
60+ value = { selectedModel }
61+ onChange = { ( m ) => {
62+ if ( GENAI_MODELS . openai ) {
63+ if (
64+ collection &&
65+ collection . dotEnvVariables &&
66+ Object . prototype . hasOwnProperty . call ( collection . dotEnvVariables , 'OPENAI_APIKEY' )
67+ ) {
68+ setModelKey ( collection . dotEnvVariables [ 'OPENAI_APIKEY' ] ) ;
69+ }
70+ }
71+ setSelectedModel ( m ) ;
72+ } }
73+ >
5974 < div className = 'relative flex w-full h-full' >
6075 < Listbox . Button className = 'flex items-center justify-between w-full gap-4 px-2 py-4 border rounded cursor-default border-neutral-300' >
6176 < div className = 'pl-2 text-left min-w-32' > { selectedModel ? selectedModel : 'Select model' } </ div >
@@ -109,16 +124,10 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
109124 type = 'text'
110125 className = 'nodrag nowheel block w-full p-2.5'
111126 name = 'keyName'
112- placeholder = 'Enter your Open AI key'
113- value = {
114- collection &&
115- collection . dotEnvVariables &&
116- Object . prototype . hasOwnProperty . call ( collection . dotEnvVariables , 'OPENAI_APIKEY' )
117- ? collection . dotEnvVariables [ 'OPENAI_APIKEY' ]
118- : 'Enter your OPENAI key: https://flowtestai.gitbook.io/flowtestai/generative-ai'
119- }
120- readOnly = 'readonly'
121- //onChange={(e) => setOpenAIKey(e.target.value)}
127+ placeholder = 'Enter your OPENAI api key'
128+ value = { modelkey . trim ( ) != '' ? modelkey : 'Enter your OPENAI api key' }
129+ //readOnly='readonly'
130+ onChange = { ( e ) => setModelKey ( e . target . value ) }
122131 />
123132 </ div >
124133 ) : (
@@ -129,6 +138,7 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
129138 id = 'gen-ai-text'
130139 className = 'block w-full p-4 text-sm text-gray-900 border border-gray-300 rounded min-h-80 bg-gray-50 outline-blue-300 focus:border-blue-100 focus:ring-blue-100'
131140 placeholder = 'Describe your flow step by step'
141+ value = { textareaValue }
132142 onChange = { ( event ) => setTextareaValue ( event . target . value ) }
133143 />
134144 </ div >
@@ -152,9 +162,14 @@ const GenerateFlowTestModal = ({ closeFn = () => null, open = false, collectionI
152162 toast . info ( 'Please describe your flow' ) ;
153163 } else if ( selectedModel === null ) {
154164 toast . info ( 'Please select a model' ) ;
165+ } else if ( modelkey . trim ( ) === '' ) {
166+ toast . info ( `Please enter ${ selectedModel } api key` ) ;
155167 } else {
156168 setShowLoader ( true ) ;
157- promiseWithTimeout ( generateFlowData ( textareaValue , selectedModel , collectionId ) , 30000 )
169+ promiseWithTimeout (
170+ generateFlowData ( textareaValue , selectedModel , modelkey , collectionId ) ,
171+ 30000 ,
172+ )
158173 . then ( ( flowData ) => {
159174 setShowLoader ( false ) ;
160175 if ( isEqual ( flowData . nodes , [ ] ) ) {
0 commit comments