@@ -9,14 +9,14 @@ import { useMutation } from "@tanstack/react-query";
99import { useFetchExamples } from '../../api/api' ;
1010import TooltipIcon from '../../components/TooltipIcon' ;
1111import PCModalContent from './PCModalContent' ;
12- import { File , QuestionSolution , WorkflowType } from './types' ;
12+ import { ExampleType , File , QuestionSolution , WorkflowType } from './types' ;
1313import FileSelectorButton from './FileSelectorButton' ;
1414
15- import { fetchFileContent } from './hooks' ;
15+ import { fetchFileContent , getExampleType , useGetExamplesByUseCase } from './hooks' ;
1616import { useState } from 'react' ;
1717import FreeFormExampleTable from './FreeFormExampleTable' ;
1818
19- const { Title } = Typography ;
19+ const { Title, Text } = Typography ;
2020const Container = styled . div `
2121 padding-bottom: 10px
2222`
@@ -48,10 +48,7 @@ const StyledContainer = styled.div`
4848
4949const MAX_EXAMPLES = 5 ;
5050
51- enum ExampleType {
52- FREE_FORM = 'freeform' ,
53- PROMPT_COMPLETION = 'promptcompletion'
54- }
51+
5552
5653const Examples : React . FC = ( ) => {
5754 const form = Form . useFormInstance ( ) ;
@@ -90,13 +87,13 @@ const Examples: React.FC = () => {
9087 title : 'Prompts' ,
9188 dataIndex : 'question' ,
9289 ellipsis : true ,
93- render : ( _text : QuestionSolution , record : QuestionSolution ) => < > { record . question } </ >
90+ render : ( _text : QuestionSolution , record : QuestionSolution ) => < Text > { record . question } </ Text >
9491 } ,
9592 {
9693 title : 'Completions' ,
9794 dataIndex : 'solution' ,
9895 ellipsis : true ,
99- render : ( _text : QuestionSolution , record : QuestionSolution ) => < > { record . solution } </ >
96+ render : ( _text : QuestionSolution , record : QuestionSolution ) => < Text > { record . solution } </ Text >
10097 } ,
10198 {
10299 title : 'Actions' ,
@@ -178,13 +175,24 @@ const Examples: React.FC = () => {
178175 />
179176 </ Flex >
180177 )
181- } } ,
178+ }
179+ } ,
182180 ] ;
183181 const dataSource = Form . useWatch ( 'examples' , form ) ;
184- const { data : examples , loading : examplesLoading } = useFetchExamples ( form . getFieldValue ( 'use_case' ) ) ;
182+ const { examples, exmpleFormat, isLoading : examplesLoading } =
183+ useGetExamplesByUseCase ( form . getFieldValue ( 'use_case' ) ) ;
184+
185+ // update examples
185186 if ( ! dataSource && examples ) {
186- form . setFieldValue ( 'examples' , examples . examples )
187+ form . setFieldValue ( 'examples' , examples )
187188 }
189+ useEffect ( ( ) => {
190+ if ( ! isEmpty ( examples ) && ! isEmpty ( exmpleFormat ) ) {
191+ setExampleType ( exmpleFormat as ExampleType ) ;
192+ form . setFieldValue ( 'examples' , examples || [ ] ) ;
193+ }
194+ } , [ examples , exmpleFormat ] ) ;
195+
188196 const rowLimitReached = form . getFieldValue ( 'examples' ) ?. length === MAX_EXAMPLES ;
189197 const workflowType = form . getFieldValue ( 'workflow_type' ) ;
190198
@@ -299,6 +307,8 @@ const Examples: React.FC = () => {
299307 </ Header >
300308 { exampleType === ExampleType . FREE_FORM && ! isEmpty ( mutation . data ) &&
301309 < FreeFormExampleTable data = { mutation . data } /> }
310+ { exampleType === ExampleType . FREE_FORM && form . getFieldValue ( 'use_case' ) === 'lending_data' &&
311+ < FreeFormExampleTable data = { form . getFieldValue ( 'examples' ) } /> }
302312 { exampleType === ExampleType . FREE_FORM && isEmpty ( mutation . data ) && ! isEmpty ( values . examples ) &&
303313 < FreeFormExampleTable data = { values . examples } /> }
304314 { exampleType === ExampleType . FREE_FORM && isEmpty ( mutation . data ) && isEmpty ( values . examples ) &&
0 commit comments