home-assistant.io/source/_integrations/google_generative_ai_conversation.markdown

3.9 KiB

title, description, ha_category, ha_release, ha_iot_class, ha_config_flow, ha_codeowners, ha_domain, ha_integration_type
title description ha_category ha_release ha_iot_class ha_config_flow ha_codeowners ha_domain ha_integration_type
Google Generative AI Conversation Instructions on how to integrate Google Generative AI as a conversation agent
Voice
2023.6 Cloud Polling true
@tronikos
google_generative_ai_conversation service

The Google Generative AI integration adds a conversation agent powered by Google Generative AI in Home Assistant.

This conversation agent is unable to control your house. The Google Generative AI conversation agent can be used in automations, but not as a sentence trigger. It can only query information that has been provided by Home Assistant. To be able to answer questions about your house, Home Assistant will need to provide Google Generative AI with the details of your house, which include areas, devices and their states.

This integration requires an API key to use, which you can generate here.

{% include integrations/config_flow.md %}

Generate an API Key

The Google Generative AI API key is used to authenticate requests to the Google Generative AI API. To generate an API key take the following steps:

  • Visit the API Keys page to retrieve the API key you'll use to configure the integration.

{% include integrations/option_flow.md %} {% configuration_basic %} Prompt Template: description: The starting text for the AI language model to generate new text from. This text can include information about your Home Assistant instance, devices, and areas and is written using Home Assistant Templating.

Model: description: Model used to generate response.

Temperature: description: Creativity allowed in the responses. Higher values produce a more random and varied response. A temperature of zero will be deterministic.

Top P: description: Probability threshold for top-p sampling.

Top K: description: Number of top-scored tokens to consider during generation.

Maximum Tokens to Return in Response: description: The maximum number of words or "tokens" that the AI model should generate.

{% endconfiguration_basic %}

Services

Service google_generative_ai_conversation.generate_content

Allows you to ask Gemini Pro or Gemini Pro Vision to generate content from a prompt consisting of text and optionally images. This service populates response data with the generated content.

Service data attribute Optional Description Example
prompt no The prompt for generating the content. Describe this image
image_filename yes File names for images to include in the prompt. /tmp/image.jpg

{% raw %}

service: google_generative_ai_conversation.generate_content
data:
  prompt: >-
    Very briefly describe what you see in this image from my doorbell camera.
    Your message needs to be short to fit in a phone notification. Don't
    describe stationary objects or buildings.
  image_filename: /tmp/doorbell_snapshot.jpg
response_variable: generated_content

{% endraw %}

The response data field text will contain the generated content.

Another example with multiple images:

{% raw %}

service: google_generative_ai_conversation.generate_content
data:
  prompt: >-
    Briefly describe what happened in the following sequence of images
    from my driveway camera.
  image_filename:
    - /tmp/driveway_snapshot1.jpg
    - /tmp/driveway_snapshot2.jpg
    - /tmp/driveway_snapshot3.jpg
    - /tmp/driveway_snapshot4.jpg
response_variable: generated_content

{% endraw %}