@@ -25,26 +25,35 @@ public class VertexAI: NSObject {
25
25
26
26
/// The default `VertexAI` instance.
27
27
///
28
+ /// - Parameter region: The region identifier, e.g., `us-central1`; see
29
+ /// [Vertex AI
30
+ /// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
31
+ /// for a list of supported regions.
28
32
/// - Returns: An instance of `VertexAI`, configured with the default `FirebaseApp`.
29
- public static func vertexAI( ) -> VertexAI {
33
+ public static func vertexAI( region : String ) -> VertexAI {
30
34
guard let app = FirebaseApp . app ( ) else {
31
35
fatalError ( " No instance of the default Firebase app was found. " )
32
36
}
33
37
34
- return vertexAI ( app: app)
38
+ return vertexAI ( app: app, region : region )
35
39
}
36
40
37
41
/// Creates an instance of `VertexAI` configured with a custom `FirebaseApp`.
38
42
///
39
- /// - Parameter app: The custom `FirebaseApp` used for initialization.
43
+ /// - Parameters:
44
+ /// - app: The custom `FirebaseApp` used for initialization.
45
+ /// - region: The region identifier, e.g., `us-central1`; see
46
+ /// [Vertex AI
47
+ /// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
48
+ /// for a list of supported regions.
40
49
/// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`.
41
- public static func vertexAI( app: FirebaseApp ) -> VertexAI {
50
+ public static func vertexAI( app: FirebaseApp , region : String ) -> VertexAI {
42
51
guard let provider = ComponentType< VertexAIProvider> . instance( for: VertexAIProvider . self,
43
52
in: app. container) else {
44
53
fatalError ( " No \( VertexAIProvider . self) instance found for Firebase app: \( app. name) " )
45
54
}
46
55
47
- return provider. vertexAI ( )
56
+ return provider. vertexAI ( region )
48
57
}
49
58
50
59
/// Initializes a generative model with the given parameters.
@@ -54,19 +63,15 @@ public class VertexAI: NSObject {
54
63
/// [Gemini
55
64
/// models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#gemini-models)
56
65
/// for a list of supported model names.
57
- /// - location: The location identifier, e.g., `us-central1`; see
58
- /// [Vertex AI
59
- /// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
60
- /// for a list of supported locations.
61
66
/// - generationConfig: The content generation parameters your model should use.
62
67
/// - safetySettings: A value describing what types of harmful content your model should allow.
63
68
/// - requestOptions: Configuration parameters for sending requests to the backend.
64
- public func generativeModel( modelName: String , location : String ,
69
+ public func generativeModel( modelName: String ,
65
70
generationConfig: GenerationConfig ? = nil ,
66
71
safetySettings: [ SafetySetting ] ? = nil ,
67
72
requestOptions: RequestOptions = RequestOptions ( ) )
68
73
-> GenerativeModel {
69
- let modelResourceName = modelResourceName ( modelName: modelName, location : location )
74
+ let modelResourceName = modelResourceName ( modelName: modelName, region : region )
70
75
71
76
guard let apiKey = app. options. apiKey else {
72
77
fatalError ( " The Firebase app named \" \( app. name) \" has no API key in its configuration. " )
@@ -89,26 +94,29 @@ public class VertexAI: NSObject {
89
94
90
95
private let appCheck : AppCheckInterop ?
91
96
92
- init ( app: FirebaseApp ) {
97
+ private let region : String
98
+
99
+ init ( app: FirebaseApp , region: String ) {
93
100
self . app = app
101
+ self . region = region
94
102
appCheck = ComponentType< AppCheckInterop> . instance( for: AppCheckInterop . self, in: app. container)
95
103
}
96
104
97
- private func modelResourceName( modelName: String , location : String ) -> String {
105
+ private func modelResourceName( modelName: String , region : String ) -> String {
98
106
if modelName. contains ( " / " ) {
99
107
return modelName
100
108
}
101
109
guard let projectID = app. options. projectID else {
102
110
fatalError ( " The Firebase app named \" \( app. name) \" has no project ID in its configuration. " )
103
111
}
104
- guard !location . isEmpty else {
112
+ guard !region . isEmpty else {
105
113
fatalError ( """
106
- No location specified; see
114
+ No region specified; see
107
115
https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for a
108
116
list of available regions.
109
117
""" )
110
118
}
111
119
112
- return " projects/ \( projectID) /locations/ \( location ) /publishers/google/models/ \( modelName) "
120
+ return " projects/ \( projectID) /locations/ \( region ) /publishers/google/models/ \( modelName) "
113
121
}
114
122
}
0 commit comments