Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions firebaseai/src/Citation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ internal static CitationMetadata FromJson(Dictionary<string, object> jsonDict,
{
FirebaseAI.Backend.InternalProvider.GoogleAI => "citationSources",
FirebaseAI.Backend.InternalProvider.VertexAI => "citations",
FirebaseAI.Backend.InternalProvider.AgentPlatform => "citations",
_ => throw new ArgumentOutOfRangeException(nameof(backend), backend,
"Unsupported or unhandled backend provider encountered.")
};
Expand Down
26 changes: 21 additions & 5 deletions firebaseai/src/FirebaseAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public readonly struct Backend
internal enum InternalProvider
{
GoogleAI,
VertexAI
VertexAI,
AgentPlatform,
Comment thread
a-maurice marked this conversation as resolved.
}

/// <summary>
Expand All @@ -47,7 +48,7 @@ internal enum InternalProvider
internal InternalProvider Provider { get; }
/// <summary>
/// Intended for internal use only.
/// The region identifier used by the Vertex AI backend.
/// The region identifier used by the Vertex AI and Agent Platform backends.
/// </summary>
internal string Location { get; }

Expand All @@ -68,9 +69,9 @@ public static Backend GoogleAI()
/// <summary>
/// The Vertex AI backend service configuration.
/// </summary>
/// <param name="location">The region identifier, defaulting to `us-central1`; see [Vertex AI
/// regions](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
/// for a list of supported regions.</param>
/// <param name="location">The region identifier, defaulting to `us-central1`</param>
/// @deprecated Use AgentPlatform instead. Note that the default location changes to 'global'
Comment thread
a-maurice marked this conversation as resolved.
Outdated
[Obsolete("Use AgentPlatform instead. Note that the default location changes to 'global'")]
public static Backend VertexAI(string location = "us-central1")
{
if (string.IsNullOrWhiteSpace(location) || location.Contains("/"))
Expand All @@ -82,6 +83,21 @@ public static Backend VertexAI(string location = "us-central1")
return new Backend(InternalProvider.VertexAI, location);
}

/// <summary>
/// The Agent Platform backend service configuration.
/// </summary>
/// <param name="location">The region identifier, defaulting to `global`</param>
public static Backend AgentPlatform(string location = "global")
{
if (string.IsNullOrWhiteSpace(location) || location.Contains("/"))
{
throw new ArgumentException(
$"The location argument must be non-empty, and not contain special characters like '/'");
}

return new Backend(InternalProvider.AgentPlatform, location);
}

public override readonly string ToString()
{
return $"FirebaseAIBackend|{Provider}|{Location}";
Expand Down
1 change: 1 addition & 0 deletions firebaseai/src/GenerativeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ private string MakeCountTokensRequest(IEnumerable<ModelContent> contents)
$"models/{_modelName}";
break;
case FirebaseAI.Backend.InternalProvider.VertexAI:
case FirebaseAI.Backend.InternalProvider.AgentPlatform:
jsonDict = new()
{
// Convert the Contents into a list of Json dictionaries
Expand Down
6 changes: 4 additions & 2 deletions firebaseai/src/Internal/HttpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ internal static class HttpHelpers
internal static string GetURL(FirebaseApp firebaseApp,
FirebaseAI.Backend backend, string modelName)
{
if (backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI)
if (backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI ||
backend.Provider == FirebaseAI.Backend.InternalProvider.AgentPlatform)
{
return "https://firebasevertexai.googleapis.com/v1beta" +
"/projects/" + firebaseApp.Options.ProjectId +
Expand All @@ -54,7 +55,8 @@ internal static string GetTemplateURL(FirebaseApp firebaseApp,
{
var projectUrl = "https://firebasevertexai.googleapis.com/v1beta" +
$"/projects/{firebaseApp.Options.ProjectId}";
if (backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI)
if (backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI ||
backend.Provider == FirebaseAI.Backend.InternalProvider.AgentPlatform)
{
return $"{projectUrl}/locations/{backend.Location}/templates/{templateId}";
}
Expand Down
6 changes: 4 additions & 2 deletions firebaseai/src/LiveGenerativeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ internal LiveGenerativeModel(FirebaseApp firebaseApp,

private string GetURL()
{
if (_backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI)
if (_backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI ||
_backend.Provider == FirebaseAI.Backend.InternalProvider.AgentPlatform)
{
return "wss://firebasevertexai.googleapis.com/ws" +
"/google.firebase.vertexai.v1beta.LlmBidiService/BidiGenerateContent" +
Expand All @@ -97,7 +98,8 @@ private string GetURL()

private string GetModelName()
{
if (_backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI)
if (_backend.Provider == FirebaseAI.Backend.InternalProvider.VertexAI ||
_backend.Provider == FirebaseAI.Backend.InternalProvider.AgentPlatform)
{
return $"projects/{_firebaseApp.Options.ProjectId}/locations/{_backend.Location}" +
$"/publishers/google/models/{_modelName}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class UIHandler : MonoBehaviour {

private string appCheckDebugToken = "REPLACE_WITH_APP_CHECK_TOKEN";

protected void InitializeAppCheck() {
protected virtual void InitializeAppCheck() {
DebugLog("Initializing App Check directly in manual UIHandler");
DebugAppCheckProviderFactory.Instance.SetDebugToken(appCheckDebugToken);
FirebaseAppCheck.SetAppCheckProviderFactory(DebugAppCheckProviderFactory.Instance);
Expand Down Expand Up @@ -76,11 +76,11 @@ protected void InitializeFirebase() {
public string ModelName = "gemini-3.1-flash-lite";

private int backendSelection = 0;
private string[] backendChoices = new string[] { "Google AI Backend", "Vertex AI Backend" };
private string[] backendChoices = new string[] { "Google AI Backend", "Agent Platform Backend" };
private GenerativeModel GetModel() {
var backend = backendSelection == 0
? FirebaseAI.Backend.GoogleAI()
: FirebaseAI.Backend.VertexAI();
: FirebaseAI.Backend.AgentPlatform();

return FirebaseAI.GetInstance(backend, useLimitedUseAppCheckTokens: true).GetGenerativeModel(ModelName);
}
Expand Down
Loading