Skip to content
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

Initial VertexAI API surface #1179

Merged
merged 3 commits into from
Feb 10, 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
3 changes: 3 additions & 0 deletions unity_packer/guids.json
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,9 @@
"Firebase/Editor/FirebaseMessaging_version-12.5.0_manifest.txt": "fdf5d2bb0f9d4f0ba42e38b1f5c6b102",
"Firebase/Editor/FirebaseRemoteConfig_version-12.5.0_manifest.txt": "2d1a5b051f1a452e9eb8afaa9799e48f",
"Firebase/Editor/FirebaseStorage_version-12.5.0_manifest.txt": "94536946ac944e639dd690b9828a5314",
"Firebase/Editor/FirebaseVertexAI_version-12.5.0_manifest.txt": "aff68d4dbbcf4a65892205825ae01dfa",
"Firebase/Plugins/Firebase.VertexAI.dll": "7c23ae13d705434895cb14976926117b",
"Firebase/Plugins/Firebase.VertexAI.pdb": "01edb10da18a4975af2cc8f7a6de5e5d",
"Firebase/Plugins/x86_64/FirebaseCppApp-12_5_0.bundle": "60898de491fb4a168588dfa7b0c24942",
"Firebase/Plugins/x86_64/FirebaseCppApp-12_5_0.dll": "f25775ec30db485e86377f6898623aca",
"Firebase/Plugins/x86_64/FirebaseCppApp-12_5_0.so": "ca2abf1d7ed145289e902d62c88972d4",
Expand Down
13 changes: 13 additions & 0 deletions vertexai/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@

# Vertex AI in Firebase CSharp files
set(firebase_vertexai_src
src/Candidate.cs
src/Chat.cs
src/Citation.cs
src/CountTokensResponse.cs
src/FunctionCalling.cs
src/GenerateContentResponse.cs
src/GenerationConfig.cs
src/GenerativeModel.cs
src/ModelContent.cs
src/RequestOptions.cs
src/Safety.cs
src/Schema.cs
src/VertexAI.cs
src/VertexAIException.cs
)

unity_pack_documentation_sources(vertexai
Expand Down
42 changes: 42 additions & 0 deletions vertexai/src/Candidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.Collections.Generic;

namespace Firebase.VertexAI {

public enum FinishReason {
Unknown,
Stop,
MaxTokens,
Safety,
Recitation,
Other,
Blocklist,
ProhibitedContent,
SPII,
MalformedFunctionCall,
}

public readonly struct Candidate {
public ModelContent Content { get; }
public IEnumerable<SafetyRating> SafetyRatings { get; }
public FinishReason? FinishReason { get; }
public CitationMetadata? CitationMetadata { get; }
}

}
76 changes: 76 additions & 0 deletions vertexai/src/Chat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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.Collections.Generic;
using System.Threading.Tasks;

namespace Firebase.VertexAI {

public class Chat {

public IEnumerable<ModelContent> History { get; }

// Note: The generation functions are the same as the ones in GenerativeModel

public Task<GenerateContentResponse> GenerateContentAsync(
params ModelContent[] content) {
throw new NotImplementedException();
}
public Task<GenerateContentResponse> GenerateContentAsync(
string text) {
throw new NotImplementedException();
}
public Task<GenerateContentResponse> GenerateContentAsync(
IEnumerable<ModelContent> content) {
throw new NotImplementedException();
}

// The build logic isn't able to resolve IAsyncEnumerable for some reason, even
// though it is usable in Unity 2021.3. Will need to investigate further.
/*
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(
params ModelContent[] content) {
throw new NotImplementedException();
}
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(
string text) {
throw new NotImplementedException();
}
public IAsyncEnumerable<GenerateContentResponse> GenerateContentStreamAsync(
IEnumerable<ModelContent> content) {
throw new NotImplementedException();
}
*/

public Task<CountTokensResponse> CountTokensAsync(
params ModelContent[] content) {
throw new NotImplementedException();
}
public Task<CountTokensResponse> CountTokensAsync(
string text) {
throw new NotImplementedException();
}
public Task<CountTokensResponse> CountTokensAsync(
IEnumerable<ModelContent> content) {
throw new NotImplementedException();
}

// Note: No public constructor, get one through GenerativeModel.StartChat

}

}
38 changes: 38 additions & 0 deletions vertexai/src/Citation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.Collections.Generic;

namespace Firebase.VertexAI {

public readonly struct CitationMetadata {
public IEnumerable<Citation> Citations { get; }

// Hidden constructor, users don't need to make this
}

public readonly struct Citation {
public int StartIndex { get; }
public int EndIndex { get; }
public System.Uri Uri { get; }
public string Title { get; }
public string License { get; }
public System.DateTime? PublicationDate { get; }

// Hidden constructor, users don't need to make this
}

}
26 changes: 26 additions & 0 deletions vertexai/src/CountTokensResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/

namespace Firebase.VertexAI {

public readonly struct CountTokensResponse {
public int TotalTokens { get; }
public int? TotalBillableCharacters { get; }

// Hidden constructor, users don't need to make this
}

}
70 changes: 70 additions & 0 deletions vertexai/src/FunctionCalling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.Collections.Generic;

namespace Firebase.VertexAI {

public readonly struct FunctionDeclaration {
// No public properties, on purpose since it is meant for user input only

public FunctionDeclaration(string name, string description,
IDictionary<string, Schema> parameters,
IEnumerable<string> optionalParameters = null) {
throw new NotImplementedException();
}
}

public readonly struct Tool {
// No public properties, on purpose since it is meant for user input only

public Tool(params FunctionDeclaration[] functionDeclarations) {
throw new NotImplementedException();
}
public Tool(IEnumerable<FunctionDeclaration> functionDeclarations) {
throw new NotImplementedException();
}
}

public readonly struct ToolConfig {
// No public properties, on purpose since it is meant for user input only

public ToolConfig(FunctionCallingConfig? functionCallingConfig = null) {
throw new NotImplementedException();
}
}

public readonly struct FunctionCallingConfig {
// No public properties, on purpose since it is meant for user input only

public static FunctionCallingConfig Auto() {
throw new NotImplementedException();
}

public static FunctionCallingConfig Any(params string[] allowedFunctionNames) {
throw new NotImplementedException();
}
public static FunctionCallingConfig Any(IEnumerable<string> allowedFunctionNames) {
throw new NotImplementedException();
}

public static FunctionCallingConfig None() {
throw new NotImplementedException();
}
}

}
58 changes: 58 additions & 0 deletions vertexai/src/GenerateContentResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.Collections.Generic;

namespace Firebase.VertexAI {

public readonly struct GenerateContentResponse {
public IEnumerable<Candidate> Candidates { get; }
public PromptFeedback? PromptFeedback { get; }
public UsageMetadata? UsageMetadata { get; }

// Helper properties
// The response's content as text, if it exists
public string Text { get; }

// Returns function calls found in any Parts of the first candidate of the response, if any.
public IEnumerable<ModelContent.FunctionCallPart> FunctionCalls { get; }
}

public enum BlockReason {
Unknown,
Safety,
Other,
Blocklist,
ProhibitedContent,
}

public readonly struct PromptFeedback {
public BlockReason? BlockReason { get; }
public string BlockReasonMessage { get; }
public IEnumerable<SafetyRating> SafetyRatings { get; }

// Hidden constructor, users don't need to make this
}

public readonly struct UsageMetadata {
public int PromptTokenCount { get; }
public int CandidatesTokenCount { get; }
public int TotalTokenCount { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking, maybe consider to add related modality token info similar to this PR as well? firebase/flutterfire#17065

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll need to reorganize what my plans are for some of those based on the recent changes, but I'll wait until I'm doing the implementation of these parts, just to let the other platforms settle in on something for sure.


// Hidden constructor, users don't need to make this
}

}
36 changes: 36 additions & 0 deletions vertexai/src/GenerationConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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;

namespace Firebase.VertexAI {

public readonly struct GenerationConfig {

public GenerationConfig(
float? temperature = null,
float? topP = null,
float? topK = null,
int? candidateCount = null,
int? maxOutputTokens = null,
float? prescencePenalty = null,
float? frequencyPenalty = null,
string[] stopSequences = null,
string responseMimeType = null,
Schema responseSchema = null) { throw new NotImplementedException(); }
}

}
Loading
Loading