@@ -1829,33 +1829,37 @@ func TestGeminiFinishReasonToOpenAI(t *testing.T) {
18291829 }
18301830}
18311831
1832- func TestExtractTextFromGeminiParts (t * testing.T ) {
1832+ func TestExtractTextAndThoughtSummaryFromGeminiParts (t * testing.T ) {
18331833 tests := []struct {
1834- name string
1835- parts []* genai.Part
1836- responseMode geminiResponseMode
1837- expected string
1834+ name string
1835+ parts []* genai.Part
1836+ responseMode geminiResponseMode
1837+ expectedThoughtSummary string
1838+ expectedText string
18381839 }{
18391840 {
1840- name : "nil parts" ,
1841- parts : nil ,
1842- responseMode : responseModeNone ,
1843- expected : "" ,
1841+ name : "nil parts" ,
1842+ parts : nil ,
1843+ responseMode : responseModeNone ,
1844+ expectedThoughtSummary : "" ,
1845+ expectedText : "" ,
18441846 },
18451847 {
1846- name : "empty parts" ,
1847- parts : []* genai.Part {},
1848- responseMode : responseModeNone ,
1849- expected : "" ,
1848+ name : "empty parts" ,
1849+ parts : []* genai.Part {},
1850+ responseMode : responseModeNone ,
1851+ expectedThoughtSummary : "" ,
1852+ expectedText : "" ,
18501853 },
18511854 {
18521855 name : "multiple text parts without regex mode" ,
18531856 parts : []* genai.Part {
18541857 {Text : "Hello, " },
18551858 {Text : "world!" },
18561859 },
1857- responseMode : responseModeJSON ,
1858- expected : "Hello, world!" ,
1860+ responseMode : responseModeJSON ,
1861+ expectedThoughtSummary : "" ,
1862+ expectedText : "Hello, world!" ,
18591863 },
18601864 {
18611865 name : "regex mode with mixed quoted and unquoted text" ,
@@ -1864,40 +1868,56 @@ func TestExtractTextFromGeminiParts(t *testing.T) {
18641868 {Text : `unquoted` },
18651869 {Text : `"negative"` },
18661870 },
1867- responseMode : responseModeRegex ,
1868- expected : "positiveunquotednegative" ,
1871+ responseMode : responseModeRegex ,
1872+ expectedThoughtSummary : "" ,
1873+ expectedText : "positiveunquotednegative" ,
18691874 },
18701875 {
18711876 name : "regex mode with only double-quoted first and last words" ,
18721877 parts : []* genai.Part {
18731878 {Text : "\" \" ERROR\" Unable to connect to database \" DatabaseModule\" \" " },
18741879 },
1875- responseMode : responseModeRegex ,
1876- expected : "\" ERROR\" Unable to connect to database \" DatabaseModule\" " ,
1880+ responseMode : responseModeRegex ,
1881+ expectedThoughtSummary : "" ,
1882+ expectedText : "\" ERROR\" Unable to connect to database \" DatabaseModule\" " ,
18771883 },
18781884 {
18791885 name : "non-regex mode with double-quoted text (should not remove quotes)" ,
18801886 parts : []* genai.Part {
18811887 {Text : `"positive"` },
18821888 },
1883- responseMode : responseModeJSON ,
1884- expected : `"positive"` ,
1889+ responseMode : responseModeJSON ,
1890+ expectedThoughtSummary : "" ,
1891+ expectedText : `"positive"` ,
18851892 },
18861893 {
18871894 name : "regex mode with text containing internal quotes" ,
18881895 parts : []* genai.Part {
18891896 {Text : `"He said \"hello\" to me"` },
18901897 },
1891- responseMode : responseModeRegex ,
1892- expected : `He said \"hello\" to me` ,
1898+ responseMode : responseModeRegex ,
1899+ expectedThoughtSummary : "" ,
1900+ expectedText : `He said \"hello\" to me` ,
1901+ },
1902+ {
1903+ name : "test thought summary" ,
1904+ parts : []* genai.Part {
1905+ {Text : "Let me think step by step" , Thought : true },
1906+ {Text : "Here is the conclusion" },
1907+ },
1908+ expectedThoughtSummary : "Let me think step by step" ,
1909+ expectedText : "Here is the conclusion" ,
18931910 },
18941911 }
18951912
18961913 for _ , tc := range tests {
18971914 t .Run (tc .name , func (t * testing.T ) {
1898- result := extractTextFromGeminiParts (tc .parts , tc .responseMode )
1899- if result != tc .expected {
1900- t .Errorf ("extractTextFromGeminiParts() = %q, want %q" , result , tc .expected )
1915+ thoughtSummary , text := extractTextAndThoughtSummaryFromGeminiParts (tc .parts , tc .responseMode )
1916+ if thoughtSummary != tc .expectedThoughtSummary {
1917+ t .Errorf ("thought summary result of extractTextAndThoughtSummaryFromGeminiParts() = %q, want %q" , thoughtSummary , tc .expectedText )
1918+ }
1919+ if text != tc .expectedText {
1920+ t .Errorf ("text result of extractTextAndThoughtSummaryFromGeminiParts() = %q, want %q" , text , tc .expectedText )
19011921 }
19021922 })
19031923 }
0 commit comments