File tree Expand file tree Collapse file tree
integrations/google_genai
src/haystack_integrations/components/generators/google_genai/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # To run this example, you will need to
2+ # 1) set `GOOGLE_API_KEY` environment variable
3+ # 2) install the google_genai_haystack integration: pip install google-genai-haystack
4+ # Note: if you change the model, update the model-specific inference parameters.
5+
6+
7+ from haystack .dataclasses import ChatMessage
8+
9+ from haystack_integrations .components .generators .google_genai import GoogleGenAIChatGenerator
10+
11+ generator = GoogleGenAIChatGenerator (
12+ model = "gemini-2.0-flash" ,
13+ # model-specific inference parameters
14+ generation_kwargs = {
15+ "temperature" : 0.7 ,
16+ },
17+ )
18+
19+ system_prompt = """
20+ You are a helpful assistant that helps users learn more about Google Cloud services.
21+ Your audience is engineers with a decent technical background.
22+ Be very concise and specific in your answers, keeping them short.
23+ You may use technical terms, jargon, and abbreviations that are common among practitioners.
24+ """
25+
26+ messages = [
27+ ChatMessage .from_system (system_prompt ),
28+ ChatMessage .from_user ("Which service should I use to train custom Machine Learning models?" ),
29+ ]
30+
31+ results = generator .run (messages )
32+ print (results ["replies" ][0 ].text )
Original file line number Diff line number Diff line change @@ -142,6 +142,8 @@ ban-relative-imports = "parents"
142142[tool .ruff .lint .per-file-ignores ]
143143# Tests can use magic values, assertions, and relative imports
144144"tests/**/*" = [" PLR2004" , " S101" , " TID252" ]
145+ # Examples can use print statements
146+ "examples/**/*" = [" T201" ]
145147
146148[tool .coverage .run ]
147149source = [" haystack_integrations" ]
Original file line number Diff line number Diff line change @@ -509,6 +509,10 @@ def run(
509509 if system_instruction :
510510 config_params ["system_instruction" ] = system_instruction
511511
512+ # Add safety settings if provided
513+ if safety_settings :
514+ config_params ["safety_settings" ] = safety_settings
515+
512516 # Add tools if provided
513517 if tools :
514518 config_params ["tools" ] = _convert_tools_to_google_genai_format (tools )
@@ -593,6 +597,10 @@ async def run_async(
593597 if system_instruction :
594598 config_params ["system_instruction" ] = system_instruction
595599
600+ # Add safety settings if provided
601+ if safety_settings :
602+ config_params ["safety_settings" ] = safety_settings
603+
596604 # Add tools if provided
597605 if tools :
598606 config_params ["tools" ] = _convert_tools_to_google_genai_format (tools )
You can’t perform that action at this time.
0 commit comments