File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,39 @@ func ExampleChatSession() {
178
178
printResponse (res )
179
179
}
180
180
181
+ // This example shows how to set the History field on ChatSession explicitly.
182
+ func ExampleChatSession_history () {
183
+ ctx := context .Background ()
184
+ client , err := genai .NewClient (ctx , option .WithAPIKey (os .Getenv ("GEMINI_API_KEY" )))
185
+ if err != nil {
186
+ log .Fatal (err )
187
+ }
188
+ defer client .Close ()
189
+ model := client .GenerativeModel ("gemini-1.0-pro" )
190
+ cs := model .StartChat ()
191
+
192
+ cs .History = []* genai.Content {
193
+ & genai.Content {
194
+ Parts : []genai.Part {
195
+ genai .Text ("Hello, I have 2 dogs in my house." ),
196
+ },
197
+ Role : "user" ,
198
+ },
199
+ & genai.Content {
200
+ Parts : []genai.Part {
201
+ genai .Text ("Great to meet you. What would you like to know?" ),
202
+ },
203
+ Role : "model" ,
204
+ },
205
+ }
206
+
207
+ res , err := cs .SendMessage (ctx , genai .Text ("How many paws are in my house?" ))
208
+ if err != nil {
209
+ log .Fatal (err )
210
+ }
211
+ printResponse (res )
212
+ }
213
+
181
214
func ExampleEmbeddingModel_EmbedContent () {
182
215
ctx := context .Background ()
183
216
client , err := genai .NewClient (ctx , option .WithAPIKey (os .Getenv ("GEMINI_API_KEY" )))
You can’t perform that action at this time.
0 commit comments