From 60a88ff609a5ed0e8b0d6bcc1127db0361b0b9ca Mon Sep 17 00:00:00 2001 From: David Miguel Lozano Date: Mon, 1 Apr 2024 22:45:33 +0200 Subject: [PATCH] feat: Support updating API key in Google AI client (#357) --- packages/googleai_dart/lib/src/client.dart | 6 ++++++ .../chat_models/google_ai/chat_google_generative_ai.dart | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/googleai_dart/lib/src/client.dart b/packages/googleai_dart/lib/src/client.dart index 605aec83..c6abc41a 100644 --- a/packages/googleai_dart/lib/src/client.dart +++ b/packages/googleai_dart/lib/src/client.dart @@ -43,6 +43,12 @@ class GoogleAIClient extends g.GoogleAIClient { client: client ?? createDefaultHttpClient(), ); + /// Set or replace the API key. + set apiKey(final String value) => queryParams['key'] = value; + + /// Get the API key. + String get apiKey => queryParams['key']; + // ------------------------------------------ // METHOD: streamGenerateContent // ------------------------------------------ diff --git a/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart b/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart index 83a8d91b..ec8b5f57 100644 --- a/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart +++ b/packages/langchain_google/lib/src/chat_models/google_ai/chat_google_generative_ai.dart @@ -167,6 +167,12 @@ class ChatGoogleGenerativeAI /// A UUID generator. late final Uuid _uuid = const Uuid(); + /// Set or replace the API key. + set apiKey(final String value) => _client.apiKey = value; + + /// Get the API key. + String get apiKey => _client.apiKey; + @override String get modelType => 'chat-google-generative-ai';