You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/oss/python/integrations/chat/google_generative_ai.mdx
+93-31Lines changed: 93 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -101,6 +101,20 @@ print(ai_msg.content)
101
101
J'adore la programmation.
102
102
```
103
103
104
+
<Note>
105
+
Gemini 3 series models will always return a list of content blocks to capture [thought signatures](#thought-signatures). Use the `.text` property to recover string content.
106
+
107
+
```python
108
+
from langchain_google_genai import ChatGoogleGenerativeAI
Gemini models can accept multimodal inputs (text, images, audio, video) and, for some models, generate multimodal outputs.
@@ -390,49 +404,73 @@ Usage Metadata:
390
404
391
405
## Built-in tools
392
406
393
-
Google Gemini supports a variety of built-in tools ([google search](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions), [code execution](https://ai.google.dev/gemini-api/docs/code-execution?lang=python)), which can be bound to the model in the usual way.
407
+
Google Gemini supports a variety of built-in tools, which can be bound to the model in the usual way.
408
+
409
+
### Google search
410
+
411
+
See [Gemini docs](https://ai.google.dev/gemini-api/docs/grounding/search-suggestions) for detail.
394
412
395
413
```python
396
-
fromgoogle.ai.generativelanguage_v1beta.typesimportTool as GenAITool
response = model_with_search.invoke("When is the next total solar eclipse in US?")
405
420
421
+
response.content_blocks
422
+
```
406
423
```output
407
-
The next total solar eclipse visible in the United States will occur on August 23, 2044. However, the path of totality will only pass through Montana, North Dakota, and South Dakota.
408
-
409
-
For a total solar eclipse that crosses a significant portion of the continental U.S., you'll have to wait until August 12, 2045. This eclipse will start in California and end in Florida.
424
+
[{'type': 'text',
425
+
'text': 'The next total solar eclipse visible in the contiguous United States will occur on...',
426
+
'annotations': [{'type': 'citation',
427
+
'id': 'abc123',
428
+
'url': '<url for source 1>',
429
+
'title': '<source 1 title>',
430
+
'start_index': 0,
431
+
'end_index': 99,
432
+
'cited_text': 'The next total solar eclipse...',
433
+
'extras': {'google_ai_metadata': {'web_search_queries': ['next total solar eclipse in US'],
434
+
'grounding_chunk_index': 0,
435
+
'confidence_scores': []}}},
436
+
{'type': 'citation',
437
+
'id': 'abc234',
438
+
'url': '<url for source 2>',
439
+
'title': '<source 2 title>',
440
+
'start_index': 0,
441
+
'end_index': 99,
442
+
'cited_text': 'The next total solar eclipse...',
443
+
'extras': {'google_ai_metadata': {'web_search_queries': ['next total solar eclipse in US'],
444
+
'grounding_chunk_index': 1,
445
+
'confidence_scores': []}}}]}]
410
446
```
411
447
412
-
```python
413
-
from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
448
+
### Code execution
414
449
415
-
resp = llm.invoke(
416
-
"What is 2*2, use python",
417
-
tools=[GenAITool(code_execution={})],
418
-
)
450
+
See [Gemini docs](https://ai.google.dev/gemini-api/docs/code-execution?lang=python) for detail.
[Thought signatures](https://ai.google.dev/gemini-api/docs/thought-signatures) are encrypted representations of the model's reasoning processes. Gemini 2.5 and 3 series models may return thought signatures in their responses.
499
+
500
+
<Note>
501
+
Gemini 3 may raise 4xx errors if thought signatures are not passed back with tool call responses. Upgrade to `langchain-google-genai >= 3.1.0` to ensure this is handled correctly.
502
+
</Note>
503
+
504
+
```python
505
+
from langchain_google_genai import ChatGoogleGenerativeAI
506
+
507
+
llm = ChatGoogleGenerativeAI(
508
+
model="models/gemini-3-pro-preview",
509
+
thinking_budget=1024,
510
+
include_thoughts=True,
511
+
)
512
+
513
+
response = llm.invoke("How many O's are in Google? How did you verify your answer?")
Gemini models have default safety settings that can be overridden. If you are receiving lots of "Safety Warnings" from your models, you can try tweaking the `safety_settings` attribute of the model. For example, to turn off safety blocking for dangerous content, you can construct your LLM as follows:
0 commit comments