@@ -12,8 +12,9 @@ import type {
1212 IgcMessageAttachment ,
1313} from '../src/components/chat/types.js' ;
1414
15+ const googleGenAIKey = import . meta. env . VITE_GOOGLE_GEN_AI_KEY ;
1516const ai = new GoogleGenAI ( {
16- apiKey : ' googleGenAIKey' ,
17+ apiKey : googleGenAIKey ,
1718} ) ;
1819
1920defineComponents ( IgcChatComponent ) ;
@@ -379,7 +380,35 @@ async function handleAIMessageSend(e: CustomEvent) {
379380 } ;
380381 chat . messages = [ ...chat . messages ] ;
381382 }
382- chat . options = { ...ai_chat_options , suggestions : [ 'Thank you!' ] } ;
383+
384+ const messagesForSuggestions = [
385+ ...chat . messages ,
386+ `Based on all my previous prompts give me 3 strings that would act like a suggestions for my next prompt. Don't repeat my previous prompts, I want just the suggestions in the format "suggestion1: '...', suggestion2: '...', suggestion3: '...'` ,
387+ ] ;
388+ const responseWithSuggestions = await ai . models . generateContent ( {
389+ model : 'gemini-2.0-flash' ,
390+ contents : messagesForSuggestions ,
391+ config : {
392+ responseModalities : [ Modality . TEXT ] ,
393+ } ,
394+ } ) ;
395+ response = responseWithSuggestions ?. candidates ?. [ 0 ] ?. content ?. parts ;
396+ if ( response && response . length === 1 ) {
397+ const responseText = response [ 0 ] ?. text ?? '' ;
398+ const regex : RegExp = / ' ( .* ?) ' / g;
399+
400+ // Use String.prototype.matchAll() to get an iterator of all matches, including captured groups.
401+ const matches : IterableIterator < RegExpMatchArray > =
402+ responseText . matchAll ( regex ) ;
403+
404+ // Map the matches to an array, extracting the first capturing group (the content).
405+ const suggestions : string [ ] = Array . from (
406+ matches ,
407+ ( match : RegExpMatchArray ) => match [ 1 ]
408+ ) ;
409+
410+ chat . options = { ...ai_chat_options , suggestions : suggestions } ;
411+ }
383412 }
384413 } , 2000 ) ;
385414}
@@ -438,7 +467,7 @@ export const Chat_Templates: Story = {
438467 < igc-icon-button variant ="flat "> 🎤</ igc-icon-button >
439468 < div style ="margin-inline-start: auto; ">
440469 < igc-button @click =${ handleCustomSendClick } > Ask</ igc-button >
441- < igc-button variant ="flat "> ...</ igc-button >
470+ < igc-icon- button variant ="flat "> ...</ igc-icon -button >
442471 </ div >
443472 ` ;
444473 options = {
@@ -473,7 +502,7 @@ export const Chat_Templates: Story = {
473502 variant ="flat "
474503 name ="search "
475504 > </ igc-icon-button >
476- < div slot ="suggestions-header "> Suggestions </ div >
505+ < div slot ="suggestions-header "> Get Inspired </ div >
477506 </ igc-chat >
478507 ` ;
479508 } ,
0 commit comments