Skip to content

Commit 076acab

Browse files
google-genai-botcopybara-github
authored andcommitted
feat: Add inference_generation_config to EvaluationConfig for Tuning
PiperOrigin-RevId: 879306544
1 parent fe2b838 commit 076acab

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

GeneratedFirebaseAI/Sources/Converters.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4761,6 +4761,20 @@ public enum Converters {
47614761
}
47624762
}
47634763

4764+
public static func generationConfigFromVertex(apiClient: APIClient, fromObject: Data) throws
4765+
-> GenerationConfig?
4766+
{
4767+
do {
4768+
let decoder = JSONDecoder()
4769+
decoder.userInfo[.configuration] = apiClient
4770+
let instance = try decoder.decode(GenerationConfig.self, from: fromObject)
4771+
return instance
4772+
} catch {
4773+
print("Failed to decode GenerationConfig: \(error)")
4774+
return nil
4775+
}
4776+
}
4777+
47644778
public static func evaluationConfigFromVertex(apiClient: APIClient, fromObject: Data) throws
47654779
-> EvaluationConfig?
47664780
{

GeneratedFirebaseAI/Sources/Types.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21411,24 +21411,47 @@ extension PartnerModelTuningSpec: Codable {
2141121411
/// Evaluation config for tuning.
2141221412
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
2141321413
public struct EvaluationConfig: Sendable {
21414+
/// Generation config for inference.
21415+
public let inferenceGenerationConfig: GenerationConfig?
2141421416

2141521417
/// Default initializer.
21416-
public init() {
21417-
21418+
public init(
21419+
inferenceGenerationConfig: GenerationConfig? = nil
21420+
) {
21421+
self.inferenceGenerationConfig = inferenceGenerationConfig
2141821422
}
2141921423
}
2142021424

2142121425
@available(iOS 15.0, macOS 13.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
2142221426
extension EvaluationConfig: Codable {
2142321427

2142421428
// MARK: - Codable
21429+
public enum VertexKeys: String, CodingKey {
21430+
case inferenceGenerationConfig = "inferenceGenerationConfig"
21431+
}
2142521432

2142621433
public init(from decoder: any Decoder) throws {
2142721434
let configuration: APIClient = try decoder.userInfoOrThrow(.configuration)
21435+
21436+
let VertexKeysContainer = try decoder.container(keyedBy: VertexKeys.self)
21437+
inferenceGenerationConfig = try VertexKeysContainer.decodeIfPresent(
21438+
GenerationConfig.self,
21439+
forKey: .inferenceGenerationConfig
21440+
)
2142821441
}
2142921442

2143021443
public func encode(to encoder: any Encoder) throws {
2143121444
let configuration: APIClient = try encoder.userInfoOrThrow(.configuration)
21445+
21446+
if configuration.isVertexAI() {
21447+
21448+
var VertexKeysContainer = encoder.container(keyedBy: VertexKeys.self)
21449+
try VertexKeysContainer.encodeIfPresent(
21450+
inferenceGenerationConfig,
21451+
forKey: .inferenceGenerationConfig
21452+
)
21453+
21454+
}
2143221455
}
2143321456
}
2143421457

0 commit comments

Comments
 (0)