Skip to content

Commit 85a517f

Browse files
nateboschcynthiajoanrussellwheatley
authored
refactor(vertexai): Split into separate libraries (#12794)
* Split into separate libraries The current approach uses `part` files which cannot be imported separately. One drawback of this approach is that any members which need to be referenced by test code must be public to the library. Using `src/` libraries, as opposed to `src/` part files, allows making APIs that are "package private" by convention - they are public to the library, but only exported through the `src/` import. One potential downside (alternatively seen as a benefit) of using separate libraries is that private members are truly private to their library, and we cannot make a member of a class private to the package. The convention for package imports only allows top level declarations to be considered non-public implementation details. - Remove imports from the top level library. Replace `part` lines with `export` of the same files. - Add explicit `show` clauses to the exports. This is what allows an API to be public when imported from the `src/` library, but not exposed through the package public library. - Change some private `_toGoogleAI<TypeName>` methods to extension methods. Use the name `toGoogleAI` since the specific type names are clear from context. - Change some private `_fromGoogleAI<TypeName>` factory constructors to extension methods on the google AI SDk types. Name `toVertex()`. - Remove some unused private methods that were filled in for consistency. More extension members can be added as needed. - Add an extension to expose the private field `_gooleAiModel` from `GenerativeModel`. - Add a top level method to forward to the private `GenerativeModel` constructor. - Add TODO comments to stop exporting some methods that don't need to be public. These could have been private in the `part` pattern. For now they are exported for backwards compatibility, and we can remove them when we are ready for a major version bump. * Fix typo * Add (redundant) docs * dart format * Add missing auth argument forwarding * Bad merge? * More bad merge * Unnecessary change * Update packages/firebase_vertexai/firebase_vertexai/lib/src/vertex_api.dart Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com> --------- Co-authored-by: Cynthia J <cynthiajoan@users.noreply.github.com> Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
1 parent 76b4a54 commit 85a517f

File tree

7 files changed

+365
-297
lines changed

7 files changed

+365
-297
lines changed

packages/firebase_vertexai/firebase_vertexai/lib/firebase_vertexai.dart

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,58 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
library firebase_vertexai;
16-
17-
import 'dart:async';
18-
import 'dart:convert';
19-
import 'dart:typed_data';
20-
21-
import 'package:firebase_app_check/firebase_app_check.dart';
22-
import 'package:firebase_auth/firebase_auth.dart';
23-
import 'package:firebase_core/firebase_core.dart';
24-
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
25-
show FirebasePluginPlatform;
26-
import 'package:google_generative_ai/google_generative_ai.dart' as google_ai;
27-
// ignore: implementation_imports, tightly coupled packages
28-
import 'package:google_generative_ai/src/vertex_hooks.dart';
29-
30-
import 'src/vertex_version.dart';
31-
32-
part 'src/firebase_vertexai.dart';
33-
part 'src/vertex_api.dart';
34-
part 'src/vertex_chat.dart';
35-
part 'src/vertex_content.dart';
36-
part 'src/vertex_function_calling.dart';
37-
part 'src/vertex_model.dart';
15+
export 'src/firebase_vertexai.dart'
16+
show
17+
// TODO(next breaking): Remove defaultTimeout
18+
defaultTimeout,
19+
FirebaseVertexAI,
20+
RequestOptions;
21+
export 'src/vertex_api.dart'
22+
show
23+
BatchEmbedContentsResponse,
24+
BlockReason,
25+
Candidate,
26+
CitationMetadata,
27+
CitationSource,
28+
ContentEmbedding,
29+
CountTokensResponse,
30+
// TODO(next breaking): Remove CountTokensResponseFields
31+
CountTokensResponseFields,
32+
EmbedContentRequest,
33+
EmbedContentResponse,
34+
FinishReason,
35+
GenerateContentResponse,
36+
GenerationConfig,
37+
HarmBlockThreshold,
38+
HarmCategory,
39+
HarmProbability,
40+
PromptFeedback,
41+
SafetyRating,
42+
SafetySetting,
43+
TaskType,
44+
// TODO(next breaking): Remove parse* methods
45+
parseCountTokensResponse,
46+
parseEmbedContentResponse,
47+
parseGenerateContentResponse;
48+
export 'src/vertex_chat.dart' show ChatSession, StartChatExtension;
49+
export 'src/vertex_content.dart'
50+
show
51+
Content,
52+
DataPart,
53+
FileData,
54+
FunctionCall,
55+
FunctionResponse,
56+
Part,
57+
TextPart,
58+
// TODO(next breaking): Remove parseContent
59+
parseContent;
60+
export 'src/vertex_function_calling.dart'
61+
show
62+
FunctionCallingConfig,
63+
FunctionCallingMode,
64+
FunctionDeclaration,
65+
Schema,
66+
SchemaType,
67+
Tool,
68+
ToolConfig;
69+
export 'src/vertex_model.dart' show GenerativeModel;

packages/firebase_vertexai/firebase_vertexai/lib/src/firebase_vertexai.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
part of firebase_vertexai;
15+
import 'package:firebase_app_check/firebase_app_check.dart';
16+
import 'package:firebase_auth/firebase_auth.dart';
17+
import 'package:firebase_core/firebase_core.dart';
18+
import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'
19+
show FirebasePluginPlatform;
20+
21+
import 'vertex_api.dart';
22+
import 'vertex_content.dart';
23+
import 'vertex_function_calling.dart';
24+
import 'vertex_model.dart';
1625

1726
const _defaultLocation = 'us-central1';
1827

@@ -105,7 +114,7 @@ class FirebaseVertexAI extends FirebasePluginPlatform {
105114
Content? systemInstruction,
106115
List<Tool>? tools,
107116
ToolConfig? toolConfig}) {
108-
return GenerativeModel._(
117+
return createGenerativeModel(
109118
model: model,
110119
app: app,
111120
appCheck: appCheck,

0 commit comments

Comments
 (0)