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

chore(vertexai): fork vertexai sdk away from generative ai sdk. #13298

Merged
merged 8 commits into from
Sep 10, 2024
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ Packages with other changes:

#### `firebase_vertexai` - `v0.1.0`

- Initial release of the Vertex AI for Firebase SDK (public preview). Learn how to [get started](https://firebase.google.com/docs/vertex-ai/get-started) with the SDK in your app.
- Initial release of the Vertex AI in Firebase SDK (public preview). Learn how to [get started](https://firebase.google.com/docs/vertex-ai/get-started) with the SDK in your app.


## 2024-05-07
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_vertexai/firebase_vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@

## 0.1.0

- Initial release of the Vertex AI for Firebase SDK (public preview). Learn how to [get started](https://firebase.google.com/docs/vertex-ai/get-started) with the SDK in your app.
- Initial release of the Vertex AI in Firebase SDK (public preview). Learn how to [get started](https://firebase.google.com/docs/vertex-ai/get-started) with the SDK in your app.
6 changes: 3 additions & 3 deletions packages/firebase_vertexai/firebase_vertexai/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Vertex AI for Firebase Flutter
# Vertex AI in Firebase Flutter
[![pub package](https://img.shields.io/pub/v/firebase_vertexai.svg)](https://pub.dev/packages/firebase_vertexai)

A Flutter plugin to use the [Vertex AI](https://firebase.google.com/docs/vertex-ai/).

To learn more about Vertex AI, please visit the [website](https://cloud.google.com/vertex-ai)

**Preview**: Vertex AI for Firebase is in Public Preview, which means that the product is not subject to any SLA or deprecation policy and could change in backwards-incompatible ways.
**Preview**: Vertex AI in Firebase is in Public Preview, which means that the product is not subject to any SLA or deprecation policy and could change in backwards-incompatible ways.

## Getting Started

To get started with Vertex AI for Firebase Flutter, please [see the documentation](https://firebase.google.com/docs/vertex-ai/get-started?platform=flutter).
To get started with Vertex AI in Firebase Flutter, please [see the documentation](https://firebase.google.com/docs/vertex-ai/get-started?platform=flutter).

## Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# firebase_vertexai_example

Sample app to show how to use Vertex AI for Firebase.
Sample app to show how to use Vertex AI in Firebase.

## Getting Started

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

export 'src/firebase_vertexai.dart'
show
// TODO(next breaking): Remove defaultTimeout
defaultTimeout,
FirebaseVertexAI,
RequestOptions;
export 'src/firebase_vertexai.dart' show FirebaseVertexAI, RequestOptions;
export 'src/vertex_api.dart'
show
BatchEmbedContentsResponse,
Expand All @@ -27,8 +22,6 @@ export 'src/vertex_api.dart'
CitationSource,
ContentEmbedding,
CountTokensResponse,
// TODO(next breaking): Remove CountTokensResponseFields
CountTokensResponseFields,
EmbedContentRequest,
EmbedContentResponse,
FinishReason,
Expand All @@ -40,11 +33,7 @@ export 'src/vertex_api.dart'
PromptFeedback,
SafetyRating,
SafetySetting,
TaskType,
// TODO(next breaking): Remove parse* methods
parseCountTokensResponse,
parseEmbedContentResponse,
parseGenerateContentResponse;
TaskType;
export 'src/vertex_chat.dart' show ChatSession, StartChatExtension;
export 'src/vertex_content.dart'
show
Expand All @@ -54,9 +43,14 @@ export 'src/vertex_content.dart'
FunctionCall,
FunctionResponse,
Part,
TextPart,
// TODO(next breaking): Remove parseContent
parseContent;
TextPart;
export 'src/vertex_error.dart'
show
VertexAIException,
VertexAISdkException,
InvalidApiKey,
ServerException,
UnsupportedUserLocation;
export 'src/vertex_function_calling.dart'
show
FunctionCallingConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2024 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.

import 'dart:async';
import 'dart:collection' show Queue;

/// Simple object to restrict simultaneous accesses to a resource.
///
/// Cooperating code should acquire a lock on the mutex using [acquire],
/// and only use a guarded resource while they have that lock (from the
/// returned future completing with a [Lock] to calling [Lock.release]
/// on that lock.)
///
/// At most one active [Lock] object can exist for each [Mutex] at any time.
class Mutex {
/// Queue of pending lock acquisitions, and the current active lock.
///
/// The already completed completer of the currently active lock
/// is retained at the head of the queue, and is removed when the
/// lock is released.
final Queue<Completer<Lock>> _pending = Queue();

/// Acquire a lock on the mutex.
///
/// The future will complete with an active [Lock] object
/// after all prior calls to `acquire` have completed with an acquired lock,
/// and [Lock.release] has been called on each of those locks.
Future<Lock> acquire() {
final completer = Completer<Lock>();
_pending.add(completer);
if (_pending.length == 1) {
// Is next in line to acquire lock.
completer.complete(Lock._(this));
}
return completer.future;
}

void _release() {
assert(_pending.isNotEmpty);
assert(_pending.first.isCompleted);
_pending.removeFirst();
if (_pending.isNotEmpty) {
_pending.first.complete(Lock._(this));
}
}
}

/// A lock acquired against a [Mutex].
///
/// Can be released *once*.
class Lock {
Lock._(this._mutex);
Mutex? _mutex;

/// Release the lock on the mutex.
///
/// The lock object no longer holds a lock on the mutex.
void release() {
final mutex = _mutex;
if (mutex == null) throw StateError('Already released');
_mutex = null;
mutex._release();
}
}
Loading
Loading