Skip to content
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: 2 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- [feature] The Vertex AI Sample App now includes an image generation example.
- [changed] The Vertex AI Sample App is now part of the
[quickstart-ios repo](https://github.com/firebase/quickstart-ios/tree/main/vertexai).
- [changed] The `role` in system instructions is now ignored; no code changes
are required. (#14558)

# 11.9.0
- [feature] **Public Preview**: Added support for generating images using the
Expand Down
8 changes: 7 additions & 1 deletion FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public final class GenerativeModel: Sendable {
self.safetySettings = safetySettings
self.tools = tools
self.toolConfig = toolConfig
self.systemInstruction = systemInstruction
self.systemInstruction = systemInstruction.map {
// The `role` defaults to "user" but is ignored in system instructions. However, it is
// erroneously counted towards the prompt and total token count in `countTokens` when using
// the Developer API backend; set to `nil` to avoid token count discrepancies between
// `countTokens` and `generateContent`.
ModelContent(role: nil, parts: $0.parts)
}
self.requestOptions = requestOptions

if VertexLog.additionalLoggingEnabled() {
Expand Down
6 changes: 4 additions & 2 deletions FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,15 @@ class VertexComponentTests: XCTestCase {
let app = try XCTUnwrap(VertexComponentTests.app)
let vertex = VertexAI.vertexAI(app: app, location: location)
let modelResourceName = vertex.modelResourceName(modelName: modelName)
let expectedSystemInstruction = ModelContent(role: nil, parts: systemInstruction.parts)

let generativeModel = vertex.generativeModel(
modelName: modelName,
systemInstruction: systemInstruction
)

XCTAssertEqual(generativeModel.modelResourceName, modelResourceName)
XCTAssertEqual(generativeModel.systemInstruction, systemInstruction)
XCTAssertEqual(generativeModel.systemInstruction, expectedSystemInstruction)
XCTAssertEqual(generativeModel.apiConfig, VertexAI.defaultVertexAIAPIConfig)
}

Expand All @@ -237,14 +238,15 @@ class VertexComponentTests: XCTestCase {
)
let vertex = VertexAI.vertexAI(app: app, location: nil, apiConfig: apiConfig)
let modelResourceName = vertex.modelResourceName(modelName: modelName)
let expectedSystemInstruction = ModelContent(role: nil, parts: systemInstruction.parts)

let generativeModel = vertex.generativeModel(
modelName: modelName,
systemInstruction: systemInstruction
)

XCTAssertEqual(generativeModel.modelResourceName, modelResourceName)
XCTAssertEqual(generativeModel.systemInstruction, systemInstruction)
XCTAssertEqual(generativeModel.systemInstruction, expectedSystemInstruction)
XCTAssertEqual(generativeModel.apiConfig, apiConfig)
}
}
Loading