From 33d179806da785e43257b7506c84347d5e171f33 Mon Sep 17 00:00:00 2001
From: Giorgi Jibladze <19912-jibla@users.noreply.drupalcode.org>
Date: Fri, 14 Feb 2025 17:05:18 +0000
Subject: [PATCH] Add gemini as an optional provider for Drupal CMS AI recipe.

---
 recipes/drupal_cms_ai/composer.json |  1 +
 recipes/drupal_cms_ai/recipe.yml    | 31 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/recipes/drupal_cms_ai/composer.json b/recipes/drupal_cms_ai/composer.json
index 3198b3b68..12fe403cc 100644
--- a/recipes/drupal_cms_ai/composer.json
+++ b/recipes/drupal_cms_ai/composer.json
@@ -11,6 +11,7 @@
     "drupal/ai_provider_anthropic": "^1",
     "drupal/ai_provider_openai": "^1",
     "drupal/drupal_cms_privacy_basic": "^1",
+    "drupal/gemini_provider": "^1.0@beta",
     "league/commonmark": "^2.4"
   },
   "conflict": {
diff --git a/recipes/drupal_cms_ai/recipe.yml b/recipes/drupal_cms_ai/recipe.yml
index 487a85395..9976bd99b 100644
--- a/recipes/drupal_cms_ai/recipe.yml
+++ b/recipes/drupal_cms_ai/recipe.yml
@@ -13,6 +13,7 @@ install:
   - ai_chatbot
   - ai_agents
   - menu_link_content
+  - gemini_provider
 recipes:
   - core/recipes/content_editor_role
   - drupal_cms_privacy_basic
@@ -32,6 +33,7 @@ input:
       '#options':
         openai: OpenAI
         anthropic: Anthropic
+        gemini: Gemini
   openai_api_key:
     data_type: string
     description: The OpenAI API key, if you want to use OpenAI.
@@ -55,6 +57,29 @@ input:
     default:
       source: value
       value: ''
+  gemini_api_key:
+    data_type: string
+    description: The Gemini API key, if you want to use Google Gemini.
+    prompt:
+      method: ask
+      arguments:
+        question: 'If you want to use Google Gemini, enter your Gemini API key. Otherwise, you can leave this empty:'
+    form:
+      '#type': 'textfield'
+      '#description': 'Your Gemini API key.'
+      '#title': 'API Key'
+      '#required': false
+      '#maxlength': 256
+      '#attributes':
+        autocomplete: off
+      # Only show this field if Gemini is the selected provider.
+      '#states':
+        visible:
+          'input[name*="drupal_cms_ai"][name$="[provider]"]':
+            value: gemini
+    default:
+      source: value
+      value: ''
   anthropic_api_key:
     data_type: string
     description: The Anthropic API key, if you want to use Anthropic.
@@ -107,6 +132,12 @@ config:
         provider: openai
       simpleConfigUpdate:
         moderation: true
+    gemini_provider.settings:
+      setupAiProvider:
+        key_value: ${gemini_api_key}
+        key_name: gemini_api_key
+        key_label: 'Gemini API Key'
+        provider: gemini
     ai_provider_anthropic.settings:
       setupAiProvider:
         key_value: ${anthropic_api_key}
-- 
GitLab