Skip to content

[FirebaseAI] Rename VertexAI to FirebaseAI #1243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ option(FIREBASE_INCLUDE_REMOTE_CONFIG
option(FIREBASE_INCLUDE_STORAGE
"Include the Cloud Storage for Firebase library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_VERTEXAI
"Include the Vertex AI in Firebase library."
option(FIREBASE_INCLUDE_FIREBASEAI
"Include the Firebase AI library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})

option(FIREBASE_INCLUDE_EDITOR_TOOL
Expand Down Expand Up @@ -345,8 +345,8 @@ if (FIREBASE_INCLUDE_STORAGE)
list(APPEND DOCUMENTATION_ONLY_LIB_NAMES "firebase_storage_swig")
list(APPEND PROJECT_LIST_HEADER " X(Storage)")
endif()
if (FIREBASE_INCLUDE_VERTEXAI)
add_subdirectory(vertexai)
if (FIREBASE_INCLUDE_FIREBASEAI)
add_subdirectory(firebaseai)
# Doesn't use swig, so don't need to update the other lists
endif()

Expand Down
2 changes: 1 addition & 1 deletion app/platform/Unity/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
[assembly: InternalsVisibleTo("Firebase.TaskExtension")]
[assembly: InternalsVisibleTo("Firebase.TestLab")]
[assembly: InternalsVisibleTo("Firebase.TestLab.GameLoop")]
[assembly: InternalsVisibleTo("Firebase.VertexAI")]
[assembly: InternalsVisibleTo("Firebase.FirebaseAI")]


// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Get Started with Vertex AI in Firebase
Get Started with Firebase AI
===========================================

Thank you for installing the Vertex AI in Firebase Unity SDK.
Thank you for installing the Firebase AI Unity SDK.

The Vertex AI Gemini API gives you access to the latest generative AI models from Google: the Gemini models. This SDK is built specifically for use with Unity and mobile developers, offering security options against unauthorized clients as well as integrations with other Firebase services.
The Firebase AI Gemini API gives you access to the latest generative AI models from Google: the Gemini models. This SDK is built specifically for use with Unity and mobile developers, offering security options against unauthorized clients as well as integrations with other Firebase services.

With this, you can add AI personalization to your app, build an AI chat experience, create AI-powered optimizations and automation, and much more!

Expand Down
14 changes: 7 additions & 7 deletions vertexai/CMakeLists.txt → firebaseai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# CMake file for the Vertex AI in Firebase library
# CMake file for the Firebase AI library

# Vertex AI in Firebase is different from the other Firebase libraries,
# Firebase AI is different from the other Firebase libraries,
# as instead of prebuilding, we provide it as a source library.

# Package every file under src, including subfolders, since we want them all.
unity_pack_folder(
"${FIREBASE_UNITY_DIR}/vertexai/src/"
PACK_PATH "Firebase/VertexAI"
"${FIREBASE_UNITY_DIR}/firebaseai/src/"
PACK_PATH "Firebase/FirebaseAI"
)

# For documentation, get only the C# files at the top level,
# which make up the public API.
file(GLOB firebase_vertexai_doc_src "src/*.cs")
unity_pack_documentation_sources(vertexai
file(GLOB firebase_firebaseai_doc_src "src/*.cs")
unity_pack_documentation_sources(firebaseai
DOCUMENTATION_SOURCES
${firebase_vertexai_src}
${firebase_firebaseai_src}
)
26 changes: 13 additions & 13 deletions vertexai/src/Candidate.cs → firebaseai/src/Candidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// Represents the reason why the model stopped generating content.
Expand Down Expand Up @@ -108,16 +108,16 @@ private Candidate(ModelContent content, List<SafetyRating> safetyRatings,

private static FinishReason ParseFinishReason(string str) {
return str switch {
"STOP" => Firebase.VertexAI.FinishReason.Stop,
"MAX_TOKENS" => Firebase.VertexAI.FinishReason.MaxTokens,
"SAFETY" => Firebase.VertexAI.FinishReason.Safety,
"RECITATION" => Firebase.VertexAI.FinishReason.Recitation,
"OTHER" => Firebase.VertexAI.FinishReason.Other,
"BLOCKLIST" => Firebase.VertexAI.FinishReason.Blocklist,
"PROHIBITED_CONTENT" => Firebase.VertexAI.FinishReason.ProhibitedContent,
"SPII" => Firebase.VertexAI.FinishReason.SPII,
"MALFORMED_FUNCTION_CALL" => Firebase.VertexAI.FinishReason.MalformedFunctionCall,
_ => Firebase.VertexAI.FinishReason.Unknown,
"STOP" => Firebase.FirebaseAI.FinishReason.Stop,
"MAX_TOKENS" => Firebase.FirebaseAI.FinishReason.MaxTokens,
"SAFETY" => Firebase.FirebaseAI.FinishReason.Safety,
"RECITATION" => Firebase.FirebaseAI.FinishReason.Recitation,
"OTHER" => Firebase.FirebaseAI.FinishReason.Other,
"BLOCKLIST" => Firebase.FirebaseAI.FinishReason.Blocklist,
"PROHIBITED_CONTENT" => Firebase.FirebaseAI.FinishReason.ProhibitedContent,
"SPII" => Firebase.FirebaseAI.FinishReason.SPII,
"MALFORMED_FUNCTION_CALL" => Firebase.FirebaseAI.FinishReason.MalformedFunctionCall,
_ => Firebase.FirebaseAI.FinishReason.Unknown,
};
}

Expand All @@ -132,7 +132,7 @@ internal static Candidate FromJson(Dictionary<string, object> jsonDict,
jsonDict.ParseObjectList("safetyRatings", SafetyRating.FromJson),
jsonDict.ParseNullableEnum("finishReason", ParseFinishReason),
jsonDict.ParseNullableObject("citationMetadata",
(d) => Firebase.VertexAI.CitationMetadata.FromJson(d, backend)));
(d) => Firebase.FirebaseAI.CitationMetadata.FromJson(d, backend)));
}
}

Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions vertexai/src/Chat.cs → firebaseai/src/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// An object that represents a back-and-forth chat with a model, capturing the history and saving
Expand Down Expand Up @@ -64,7 +64,7 @@ internal static Chat InternalCreateChat(GenerativeModel model, IEnumerable<Model
/// <param name="content">The input given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>The model's response if no error occurred.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public Task<GenerateContentResponse> SendMessageAsync(
ModelContent content, CancellationToken cancellationToken = default) {
return SendMessageAsync(new[] { content }, cancellationToken);
Expand All @@ -76,7 +76,7 @@ public Task<GenerateContentResponse> SendMessageAsync(
/// <param name="text">The text given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>The model's response if no error occurred.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public Task<GenerateContentResponse> SendMessageAsync(
string text, CancellationToken cancellationToken = default) {
return SendMessageAsync(new ModelContent[] { ModelContent.Text(text) }, cancellationToken);
Expand All @@ -88,7 +88,7 @@ public Task<GenerateContentResponse> SendMessageAsync(
/// <param name="content">The input given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>The model's response if no error occurred.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public Task<GenerateContentResponse> SendMessageAsync(
IEnumerable<ModelContent> content, CancellationToken cancellationToken = default) {
return SendMessageAsyncInternal(content, cancellationToken);
Expand All @@ -101,7 +101,7 @@ public Task<GenerateContentResponse> SendMessageAsync(
/// <param name="content">The input given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>A stream of generated content responses from the model.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
ModelContent content, CancellationToken cancellationToken = default) {
return SendMessageStreamAsync(new[] { content }, cancellationToken);
Expand All @@ -113,7 +113,7 @@ public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
/// <param name="text">The text given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>A stream of generated content responses from the model.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
string text, CancellationToken cancellationToken = default) {
return SendMessageStreamAsync(new ModelContent[] { ModelContent.Text(text) }, cancellationToken);
Expand All @@ -125,7 +125,7 @@ public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
/// <param name="content">The input given to the model as a prompt.</param>
/// <param name="cancellationToken">An optional token to cancel the operation.</param>
/// <returns>A stream of generated content responses from the model.</returns>
/// <exception cref="VertexAIException">Thrown when an error occurs during content generation.</exception>
/// <exception cref="FirebaseAIException">Thrown when an error occurs during content generation.</exception>
public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
IEnumerable<ModelContent> content, CancellationToken cancellationToken = default) {
return SendMessageStreamAsyncInternal(content, cancellationToken);
Expand All @@ -134,7 +134,7 @@ public IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsync(
private async Task<GenerateContentResponse> SendMessageAsyncInternal(
IEnumerable<ModelContent> requestContent, CancellationToken cancellationToken = default) {
// Make sure that the requests are set to to role "user".
List<ModelContent> fixedRequests = requestContent.Select(VertexAIExtensions.ConvertToUser).ToList();
List<ModelContent> fixedRequests = requestContent.Select(FirebaseAIExtensions.ConvertToUser).ToList();
// Set up the context to send in the request
List<ModelContent> fullRequest = new(chatHistory);
fullRequest.AddRange(fixedRequests);
Expand All @@ -159,7 +159,7 @@ private async IAsyncEnumerable<GenerateContentResponse> SendMessageStreamAsyncIn
IEnumerable<ModelContent> requestContent,
[EnumeratorCancellation] CancellationToken cancellationToken = default) {
// Make sure that the requests are set to to role "user".
List<ModelContent> fixedRequests = requestContent.Select(VertexAIExtensions.ConvertToUser).ToList();
List<ModelContent> fixedRequests = requestContent.Select(FirebaseAIExtensions.ConvertToUser).ToList();
// Set up the context to send in the request
List<ModelContent> fullRequest = new(chatHistory);
fullRequest.AddRange(fixedRequests);
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions vertexai/src/Citation.cs → firebaseai/src/Citation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// A collection of source attributions for a piece of content.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Google.MiniJSON;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// The model's response to a count tokens request.
Expand All @@ -33,7 +33,7 @@ public readonly struct CountTokensResponse {
/// The total number of billable characters in the text input given to the model as a prompt.
///
/// > Important: This does not include billable image, video or other non-text input. See
/// [Vertex AI pricing](https://firebase.google.com/docs/vertex-ai/pricing) for details.
/// [Firebase AI pricing](https://firebase.google.com/docs/vertex-ai/pricing) for details.
/// </summary>
public int? TotalBillableCharacters { get; }

Expand Down
4 changes: 2 additions & 2 deletions vertexai/src/FirebaseAI.cs → firebaseai/src/FirebaseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using System;
using System.Collections.Concurrent;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// The entry point for all Firebase AI SDK functionality.
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Backend GoogleAI() {
/// for a list of supported regions.</param>
public static Backend VertexAI(string location = "us-central1") {
if (string.IsNullOrWhiteSpace(location) || location.Contains("/")) {
throw new VertexAIInvalidLocationException(location);
throw new FirebaseAIInvalidLocationException(location);
}

return new Backend(InternalProvider.VertexAI, location);
Expand Down
File renamed without changes.
82 changes: 82 additions & 0 deletions firebaseai/src/FirebaseAIException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Linq;

namespace Firebase.FirebaseAI {

public class FirebaseAIException : Exception {
internal FirebaseAIException(string message) : base(message) { }

internal FirebaseAIException(string message, Exception exception) : base(message, exception) { }
}

public class FirebaseAISerializationException : FirebaseAIException {
internal FirebaseAISerializationException(string message) : base(message) { }

internal FirebaseAISerializationException(string message, Exception exception) : base(message, exception) { }
}

public class FirebaseAIServerException : FirebaseAIException {
internal FirebaseAIServerException(string message) : base(message) { }
}

public class FirebaseAIInvalidAPIKeyException : FirebaseAIException {
internal FirebaseAIInvalidAPIKeyException(string message) : base(message) { }
}

public class FirebaseAIPromptBlockedException : FirebaseAIException {
internal FirebaseAIPromptBlockedException(GenerateContentResponse response) :
base("Prompt was blocked:" +
$"{response.PromptFeedback?.BlockReason?.ToString() ?? "Unknown"}") { }
}

public class FirebaseAIUnsupportedUserLocationException : FirebaseAIException {
internal FirebaseAIUnsupportedUserLocationException() :
base("User location is not supported for the API use.") { }
}

public class FirebaseAIInvalidStateException : FirebaseAIException {
internal FirebaseAIInvalidStateException(string message) : base(message) { }
}

public class FirebaseAIResponseStoppedException : FirebaseAIException {
internal FirebaseAIResponseStoppedException(GenerateContentResponse response) :
base("Content generation stopped. Reason: " +
$"{response.Candidates.FirstOrDefault().FinishReason?.ToString() ?? "Unknown"}") { }
}

public class FirebaseAIRequestTimeoutException : FirebaseAIException {
internal FirebaseAIRequestTimeoutException(string message) : base(message) { }

internal FirebaseAIRequestTimeoutException(string message, Exception e) : base(message, e) { }
}

public class FirebaseAIInvalidLocationException : FirebaseAIException {
internal FirebaseAIInvalidLocationException(string location) :
base($"Invalid location \"{location}\"") { }
}

public class FirebaseAIServiceDisabledException : FirebaseAIException {
internal FirebaseAIServiceDisabledException(string message) : base(message) { }
}

public class FirebaseAIUnknownException : FirebaseAIException {
internal FirebaseAIUnknownException(string message) : base(message) { }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// Structured representation of a function declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
using System.Collections.ObjectModel;
using System.Linq;
using Google.MiniJSON;
using Firebase.VertexAI.Internal;
using Firebase.FirebaseAI.Internal;

namespace Firebase.VertexAI {
namespace Firebase.FirebaseAI {

/// <summary>
/// The model's response to a generate content request.
Expand Down Expand Up @@ -92,9 +92,9 @@ internal static GenerateContentResponse FromJson(Dictionary<string, object> json
return new GenerateContentResponse(
jsonDict.ParseObjectList("candidates", (d) => Candidate.FromJson(d, backend)),
jsonDict.ParseNullableObject("promptFeedback",
Firebase.VertexAI.PromptFeedback.FromJson),
Firebase.FirebaseAI.PromptFeedback.FromJson),
jsonDict.ParseNullableObject("usageMetadata",
Firebase.VertexAI.UsageMetadata.FromJson));
Firebase.FirebaseAI.UsageMetadata.FromJson));
}
}

Expand Down Expand Up @@ -154,11 +154,11 @@ private PromptFeedback(BlockReason? blockReason, string blockReasonMessage,

private static BlockReason ParseBlockReason(string str) {
return str switch {
"SAFETY" => Firebase.VertexAI.BlockReason.Safety,
"OTHER" => Firebase.VertexAI.BlockReason.Other,
"BLOCKLIST" => Firebase.VertexAI.BlockReason.Blocklist,
"PROHIBITED_CONTENT" => Firebase.VertexAI.BlockReason.ProhibitedContent,
_ => Firebase.VertexAI.BlockReason.Unknown,
"SAFETY" => Firebase.FirebaseAI.BlockReason.Safety,
"OTHER" => Firebase.FirebaseAI.BlockReason.Other,
"BLOCKLIST" => Firebase.FirebaseAI.BlockReason.Blocklist,
"PROHIBITED_CONTENT" => Firebase.FirebaseAI.BlockReason.ProhibitedContent,
_ => Firebase.FirebaseAI.BlockReason.Unknown,
};
}

Expand Down
Loading