@@ -9,13 +9,22 @@ import {
99} from "../../services/firebaseAIService" ;
1010import {
1111 ModelParams ,
12+ GenerationConfig ,
1213 HarmCategory ,
1314 HarmBlockThreshold ,
1415 FunctionCallingMode ,
1516 UsageMetadata ,
1617 ResponseModality ,
1718} from "firebase/ai" ;
1819
20+ export interface ExtendedGenerationConfig extends GenerationConfig {
21+ responseModalities ?: ResponseModality [ ] ;
22+ }
23+
24+ export interface ExtendedModelParams extends ModelParams {
25+ generationConfig ?: ExtendedGenerationConfig ;
26+ }
27+
1928interface RightSidebarProps {
2029 usageMetadata : UsageMetadata | null ;
2130 activeMode : AppMode ;
@@ -49,6 +58,20 @@ const RightSidebar: React.FC<RightSidebarProps> = ({
4958 setNanoBananaParams ( ( prevState ) => updateFn ( prevState ) ) ;
5059 } ;
5160
61+ const handleModalityChange = ( modality : ResponseModality , checked : boolean ) => {
62+ handleNanoBananaModelParamsUpdate ( ( prev ) => {
63+ const currentModalities = ( prev . generationConfig as ExtendedGenerationConfig ) ?. responseModalities || [ ResponseModality . TEXT ] ;
64+ let newModalities = [ ...currentModalities ] ;
65+ if ( checked ) {
66+ if ( ! newModalities . includes ( modality ) ) newModalities . push ( modality ) ;
67+ } else {
68+ newModalities = newModalities . filter ( ( m ) => m !== modality ) ;
69+ }
70+ if ( newModalities . length === 0 ) return prev ;
71+ return { ...prev , generationConfig : { ...prev . generationConfig , responseModalities : newModalities } } ;
72+ } ) ;
73+ } ;
74+
5275 const getThresholdForCategory = (
5376 category : HarmCategory ,
5477 ) : HarmBlockThreshold => {
@@ -419,40 +442,16 @@ const RightSidebar: React.FC<RightSidebarProps> = ({
419442 < label style = { { display : 'flex' , alignItems : 'center' , gap : '5px' } } >
420443 < input
421444 type = "checkbox"
422- checked = { ( ( nanoBananaParams . generationConfig as any ) ?. responseModalities || [ ResponseModality . TEXT ] ) . includes ( ResponseModality . TEXT ) }
423- onChange = { ( e ) => {
424- handleNanoBananaModelParamsUpdate ( ( prev ) => {
425- const currentModalities = ( prev . generationConfig as any ) ?. responseModalities || [ ResponseModality . TEXT ] ;
426- let newModalities = [ ...currentModalities ] ;
427- if ( e . target . checked ) {
428- if ( ! newModalities . includes ( ResponseModality . TEXT ) ) newModalities . push ( ResponseModality . TEXT ) ;
429- } else {
430- newModalities = newModalities . filter ( ( m ) => m !== ResponseModality . TEXT ) ;
431- }
432- if ( newModalities . length === 0 ) return prev ;
433- return { ...prev , generationConfig : { ...prev . generationConfig , responseModalities : newModalities } } ;
434- } ) ;
435- } }
445+ checked = { ( ( nanoBananaParams . generationConfig as ExtendedGenerationConfig ) ?. responseModalities || [ ResponseModality . TEXT ] ) . includes ( ResponseModality . TEXT ) }
446+ onChange = { ( e ) => handleModalityChange ( ResponseModality . TEXT , e . target . checked ) }
436447 />
437448 Text
438449 </ label >
439450 < label style = { { display : 'flex' , alignItems : 'center' , gap : '5px' } } >
440451 < input
441452 type = "checkbox"
442- checked = { ( ( nanoBananaParams . generationConfig as any ) ?. responseModalities || [ ] ) . includes ( ResponseModality . IMAGE ) }
443- onChange = { ( e ) => {
444- handleNanoBananaModelParamsUpdate ( ( prev ) => {
445- const currentModalities = ( prev . generationConfig as any ) ?. responseModalities || [ ResponseModality . TEXT ] ;
446- let newModalities = [ ...currentModalities ] ;
447- if ( e . target . checked ) {
448- if ( ! newModalities . includes ( ResponseModality . IMAGE ) ) newModalities . push ( ResponseModality . IMAGE ) ;
449- } else {
450- newModalities = newModalities . filter ( ( m ) => m !== ResponseModality . IMAGE ) ;
451- }
452- if ( newModalities . length === 0 ) return prev ;
453- return { ...prev , generationConfig : { ...prev . generationConfig , responseModalities : newModalities } } ;
454- } ) ;
455- } }
453+ checked = { ( ( nanoBananaParams . generationConfig as ExtendedGenerationConfig ) ?. responseModalities || [ ] ) . includes ( ResponseModality . IMAGE ) }
454+ onChange = { ( e ) => handleModalityChange ( ResponseModality . IMAGE , e . target . checked ) }
456455 />
457456 Image
458457 </ label >
0 commit comments