Skip to content

Commit a3d97d8

Browse files
authored
Merge pull request #402 from firebase/mc/breaking
update vertexai preview to main
2 parents 4011a02 + 70d721b commit a3d97d8

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

vertexai/VertexAISnippets.xcodeproj/project.pbxproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
8D40F4122BD1CDC40020872A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D40F4112BD1CDC40020872A /* Assets.xcassets */; };
1313
8D40F4162BD1CDC40020872A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8D40F4152BD1CDC40020872A /* Preview Assets.xcassets */; };
1414
8D40F4262BD1CE1A0020872A /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 8D40F4252BD1CE1A0020872A /* FirebaseAppCheck */; };
15-
8D40F43B2BD1CE3E0020872A /* FirebaseVertexAI-Preview in Frameworks */ = {isa = PBXBuildFile; productRef = 8D40F43A2BD1CE3E0020872A /* FirebaseVertexAI-Preview */; };
1615
8D40F43D2BD1CE910020872A /* VertexAISnippets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D40F43C2BD1CE910020872A /* VertexAISnippets.swift */; };
16+
8D7B83012CD4127C0024A604 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 8D7B83002CD4127C0024A604 /* FirebaseAuth */; };
17+
8D7B83032CD4127C0024A604 /* FirebaseVertexAI in Frameworks */ = {isa = PBXBuildFile; productRef = 8D7B83022CD4127C0024A604 /* FirebaseVertexAI */; };
1718
/* End PBXBuildFile section */
1819

1920
/* Begin PBXFileReference section */
@@ -31,7 +32,8 @@
3132
isa = PBXFrameworksBuildPhase;
3233
buildActionMask = 2147483647;
3334
files = (
34-
8D40F43B2BD1CE3E0020872A /* FirebaseVertexAI-Preview in Frameworks */,
35+
8D7B83032CD4127C0024A604 /* FirebaseVertexAI in Frameworks */,
36+
8D7B83012CD4127C0024A604 /* FirebaseAuth in Frameworks */,
3537
8D40F4262BD1CE1A0020872A /* FirebaseAppCheck in Frameworks */,
3638
);
3739
runOnlyForDeploymentPostprocessing = 0;
@@ -102,7 +104,8 @@
102104
name = VertexAISnippets;
103105
packageProductDependencies = (
104106
8D40F4252BD1CE1A0020872A /* FirebaseAppCheck */,
105-
8D40F43A2BD1CE3E0020872A /* FirebaseVertexAI-Preview */,
107+
8D7B83002CD4127C0024A604 /* FirebaseAuth */,
108+
8D7B83022CD4127C0024A604 /* FirebaseVertexAI */,
106109
);
107110
productName = VertexAISnippets;
108111
productReference = 8D40F40A2BD1CDC30020872A /* VertexAISnippets.app */;
@@ -116,7 +119,7 @@
116119
attributes = {
117120
BuildIndependentTargetsInParallel = 1;
118121
LastSwiftUpdateCheck = 1520;
119-
LastUpgradeCheck = 1520;
122+
LastUpgradeCheck = 1530;
120123
TargetAttributes = {
121124
8D40F4092BD1CDC30020872A = {
122125
CreatedOnToolsVersion = 15.2;
@@ -204,6 +207,7 @@
204207
CLANG_WARN_UNREACHABLE_CODE = YES;
205208
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
206209
COPY_PHASE_STRIP = NO;
210+
DEAD_CODE_STRIPPING = YES;
207211
DEBUG_INFORMATION_FORMAT = dwarf;
208212
ENABLE_STRICT_OBJC_MSGSEND = YES;
209213
ENABLE_TESTABILITY = YES;
@@ -265,6 +269,7 @@
265269
CLANG_WARN_UNREACHABLE_CODE = YES;
266270
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
267271
COPY_PHASE_STRIP = NO;
272+
DEAD_CODE_STRIPPING = YES;
268273
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
269274
ENABLE_NS_ASSERTIONS = NO;
270275
ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -292,6 +297,7 @@
292297
CODE_SIGN_ENTITLEMENTS = VertexAISnippets/VertexAISnippets.entitlements;
293298
CODE_SIGN_STYLE = Automatic;
294299
CURRENT_PROJECT_VERSION = 1;
300+
DEAD_CODE_STRIPPING = YES;
295301
DEVELOPMENT_ASSET_PATHS = "\"VertexAISnippets/Preview Content\"";
296302
ENABLE_PREVIEWS = YES;
297303
GENERATE_INFOPLIST_FILE = YES;
@@ -328,6 +334,7 @@
328334
CODE_SIGN_ENTITLEMENTS = VertexAISnippets/VertexAISnippets.entitlements;
329335
CODE_SIGN_STYLE = Automatic;
330336
CURRENT_PROJECT_VERSION = 1;
337+
DEAD_CODE_STRIPPING = YES;
331338
DEVELOPMENT_ASSET_PATHS = "\"VertexAISnippets/Preview Content\"";
332339
ENABLE_PREVIEWS = YES;
333340
GENERATE_INFOPLIST_FILE = YES;
@@ -396,10 +403,15 @@
396403
package = 8D40F41C2BD1CE1A0020872A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
397404
productName = FirebaseAppCheck;
398405
};
399-
8D40F43A2BD1CE3E0020872A /* FirebaseVertexAI-Preview */ = {
406+
8D7B83002CD4127C0024A604 /* FirebaseAuth */ = {
400407
isa = XCSwiftPackageProductDependency;
401408
package = 8D40F41C2BD1CE1A0020872A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
402-
productName = "FirebaseVertexAI-Preview";
409+
productName = FirebaseAuth;
410+
};
411+
8D7B83022CD4127C0024A604 /* FirebaseVertexAI */ = {
412+
isa = XCSwiftPackageProductDependency;
413+
package = 8D40F41C2BD1CE1A0020872A /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
414+
productName = FirebaseVertexAI;
403415
};
404416
/* End XCSwiftPackageProductDependency section */
405417
};

vertexai/VertexAISnippets/VertexAISnippets.swift

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import AppKit
2020

2121
// [START import_vertexai]
2222
import FirebaseVertexAI
23+
import FirebaseCore
2324
// [END import_vertexai]
2425

2526
class Snippets {
@@ -91,7 +92,7 @@ class Snippets {
9192
let prompt = "Write a story about a magic backpack."
9293

9394
// To stream generated text output, call generateContentStream with the text input
94-
let contentStream = model.generateContentStream(prompt)
95+
let contentStream = try model.generateContentStream(prompt)
9596
for try await chunk in contentStream {
9697
if let text = chunk.text {
9798
print(text)
@@ -125,7 +126,7 @@ class Snippets {
125126
let prompt = "What's in this picture?"
126127

127128
// To stream generated text output, call generateContentStream and pass in the prompt
128-
let contentStream = model.generateContentStream(image, prompt)
129+
let contentStream = try model.generateContentStream(image, prompt)
129130
for try await chunk in contentStream {
130131
if let text = chunk.text {
131132
print(text)
@@ -167,7 +168,7 @@ class Snippets {
167168
let prompt = "What's different between these pictures?"
168169

169170
// To stream generated text output, call generateContentStream and pass in the prompt
170-
let contentStream = model.generateContentStream(image1, image2, prompt)
171+
let contentStream = try model.generateContentStream(image1, image2, prompt)
171172
for try await chunk in contentStream {
172173
if let text = chunk.text {
173174
print(text)
@@ -203,7 +204,7 @@ class Snippets {
203204
withExtension: "mp4") else { fatalError() }
204205
let video = try Data(contentsOf: fileURL)
205206
let prompt = "What's in this video?"
206-
let videoContent = ModelContent.Part.data(mimetype: "video/mp4", video)
207+
let videoContent = InlineDataPart(data: video, mimeType: "video/mp4")
207208

208209
// To generate text output, call generateContent and pass in the prompt
209210
let response = try await model.generateContent(videoContent, prompt)
@@ -219,10 +220,10 @@ class Snippets {
219220
withExtension: "mp4") else { fatalError() }
220221
let video = try Data(contentsOf: fileURL)
221222
let prompt = "What's in this video?"
222-
let videoContent = ModelContent.Part.data(mimetype: "video/mp4", video)
223+
let videoContent = InlineDataPart(data: video, mimeType: "video/mp4")
223224

224225
// To stream generated text output, call generateContentStream and pass in the prompt
225-
let contentStream = model.generateContentStream(videoContent, prompt)
226+
let contentStream = try model.generateContentStream(videoContent, prompt)
226227
for try await chunk in contentStream {
227228
if let text = chunk.text {
228229
print(text)
@@ -243,7 +244,7 @@ class Snippets {
243244
let chat = model.startChat(history: history)
244245

245246
// To stream generated text output, call sendMessageStream and pass in the message
246-
let contentStream = chat.sendMessageStream("How many paws are in my house?")
247+
let contentStream = try chat.sendMessageStream("How many paws are in my house?")
247248
for try await chunk in contentStream {
248249
if let text = chunk.text {
249250
print(text)
@@ -275,7 +276,7 @@ class Snippets {
275276
// [START count_tokens_text]
276277
let response = try await model.countTokens("Why is the sky blue?")
277278
print("Total Tokens: \(response.totalTokens)")
278-
print("Total Billable Characters: \(response.totalBillableCharacters)")
279+
print("Total Billable Characters: \(response.totalBillableCharacters ?? 0)")
279280
// [END count_tokens_text]
280281
}
281282

@@ -288,7 +289,7 @@ class Snippets {
288289
// [START count_tokens_text_image]
289290
let response = try await model.countTokens(image, "What's in this picture?")
290291
print("Total Tokens: \(response.totalTokens)")
291-
print("Total Billable Characters: \(response.totalBillableCharacters)")
292+
print("Total Billable Characters: \(response.totalBillableCharacters ?? 0)")
292293
// [END count_tokens_text_image]
293294
}
294295

@@ -303,19 +304,19 @@ class Snippets {
303304
// [START count_tokens_multi_image]
304305
let response = try await model.countTokens(image1, image2, "What's in this picture?")
305306
print("Total Tokens: \(response.totalTokens)")
306-
print("Total Billable Characters: \(response.totalBillableCharacters)")
307+
print("Total Billable Characters: \(response.totalBillableCharacters ?? 0)")
307308
// [END count_tokens_multi_image]
308309
}
309310

310311
func countTokensChat() async throws {
311312
// [START count_tokens_chat]
312313
let chat = model.startChat()
313314
let history = chat.history
314-
let message = try ModelContent(role: "user", "Why is the sky blue?")
315+
let message = ModelContent(role: "user", parts: "Why is the sky blue?")
315316
let contents = history + [message]
316317
let response = try await model.countTokens(contents)
317318
print("Total Tokens: \(response.totalTokens)")
318-
print("Total Billable Characters: \(response.totalBillableCharacters)")
319+
print("Total Billable Characters: \(response.totalBillableCharacters ?? 0)")
319320
// [END count_tokens_chat]
320321
}
321322

@@ -361,16 +362,13 @@ class Snippets {
361362
name: "getExchangeRate",
362363
description: "Get the exchange rate for currencies between countries",
363364
parameters: [
364-
"currencyFrom": Schema(
365-
type: .string,
365+
"currencyFrom": Schema.string(
366366
description: "The currency to convert from."
367367
),
368-
"currencyTo": Schema(
369-
type: .string,
368+
"currencyTo": Schema.string(
370369
description: "The currency to convert to."
371370
),
372-
],
373-
requiredParameters: ["currencyFrom", "currencyTo"]
371+
]
374372
)
375373
// [END create_function_metadata]
376374

@@ -383,7 +381,7 @@ class Snippets {
383381
let model = vertex.generativeModel(
384382
modelName: "gemini-1.5-flash",
385383
// Specify the function declaration.
386-
tools: [Tool(functionDeclarations: [getExchangeRate])]
384+
tools: [Tool.functionDeclarations([getExchangeRate])]
387385
)
388386
// [END initialize_model_function]
389387

@@ -418,10 +416,7 @@ class Snippets {
418416
// displayed to the user.
419417
let response = try await chat.sendMessage([ModelContent(
420418
role: "function",
421-
parts: [.functionResponse(FunctionResponse(
422-
name: functionCall.name,
423-
response: apiResponse
424-
))]
419+
parts: [FunctionResponsePart(name: functionCall.name, response: apiResponse)]
425420
)])
426421

427422
// Log the text response.
@@ -436,20 +431,18 @@ class Snippets {
436431
let getExchangeRate = FunctionDeclaration(
437432
name: "getExchangeRate",
438433
description: "Get the exchange rate for currencies between countries",
439-
parameters: nil,
440-
requiredParameters: nil
434+
parameters: [:]
441435
)
442436

443437
// [START function_modes]
444438
let model = VertexAI.vertexAI().generativeModel(
445439
// Setting a function calling mode is only available in Gemini 1.5 Pro
446440
modelName: "gemini-1.5-pro",
447441
// Pass the function declaration
448-
tools: [Tool(functionDeclarations: [getExchangeRate])],
442+
tools: [Tool.functionDeclarations([getExchangeRate])],
449443
toolConfig: ToolConfig(
450-
functionCallingConfig: FunctionCallingConfig(
451-
// Only call functions (model won't generate text)
452-
mode: FunctionCallingConfig.Mode.any,
444+
// Only call functions (model won't generate text)
445+
functionCallingConfig: FunctionCallingConfig.any(
453446
// This should only be set when the Mode is .any.
454447
allowedFunctionNames: ["getExchangeRate"]
455448
)

0 commit comments

Comments
 (0)