Skip to content

Commit f04fa90

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: Support include_server_side_tool_invocations for genai.
Adds ToolConfig.include_server_side_tool_invocations Adds ExecutableCode.id Adds CodeExecutionResult.id Adds ToolCall and ToolResponse PiperOrigin-RevId: 876445909
1 parent 150698e commit f04fa90

File tree

2 files changed

+640
-90
lines changed

2 files changed

+640
-90
lines changed

GeneratedFirebaseAI/Sources/Converters.swift

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,89 @@ public enum Converters {
15701570
}
15711571
}
15721572

1573+
public static func partToVertex(apiClient: APIClient, fromObject: Part) throws -> [String: Any] {
1574+
1575+
if fromObject.toolCall != nil {
1576+
throw NSError(
1577+
domain: "Vertex AI", code: -1,
1578+
userInfo: [NSLocalizedDescriptionKey: "toolCall parameter is not supported in Vertex AI."])
1579+
}
1580+
1581+
if fromObject.toolResponse != nil {
1582+
throw NSError(
1583+
domain: "Vertex AI", code: -1,
1584+
userInfo: [
1585+
NSLocalizedDescriptionKey: "toolResponse parameter is not supported in Vertex AI."
1586+
])
1587+
}
1588+
1589+
let encoder = JSONEncoder()
1590+
encoder.userInfo[.configuration] = apiClient
1591+
encoder.keyEncodingStrategy = .convertToSnakeCase
1592+
do {
1593+
let data = try encoder.encode(fromObject)
1594+
guard
1595+
let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
1596+
as? [String: Any]
1597+
else {
1598+
throw NSError(
1599+
domain: "SwiftSDK", code: -1,
1600+
userInfo: [
1601+
NSLocalizedDescriptionKey: "Failed to convert encoded data to dictionary for Part"
1602+
])
1603+
}
1604+
var toObject = dictionary
1605+
var urlParams: [String: Any] = [:]
1606+
var queryParams: [String: Any] = [:]
1607+
if !urlParams.isEmpty {
1608+
toObject["_url"] = urlParams
1609+
}
1610+
if !queryParams.isEmpty {
1611+
toObject["_query"] = queryParams
1612+
}
1613+
return toObject
1614+
} catch {
1615+
throw NSError(
1616+
domain: "SwiftSDK", code: -1,
1617+
userInfo: [NSLocalizedDescriptionKey: "Failed to encode Part: \(error)"])
1618+
}
1619+
}
1620+
1621+
public static func contentToVertex(apiClient: APIClient, fromObject: Content) throws -> [String:
1622+
Any]
1623+
{
1624+
let encoder = JSONEncoder()
1625+
encoder.userInfo[.configuration] = apiClient
1626+
encoder.keyEncodingStrategy = .convertToSnakeCase
1627+
do {
1628+
let data = try encoder.encode(fromObject)
1629+
guard
1630+
let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
1631+
as? [String: Any]
1632+
else {
1633+
throw NSError(
1634+
domain: "SwiftSDK", code: -1,
1635+
userInfo: [
1636+
NSLocalizedDescriptionKey: "Failed to convert encoded data to dictionary for Content"
1637+
])
1638+
}
1639+
var toObject = dictionary
1640+
var urlParams: [String: Any] = [:]
1641+
var queryParams: [String: Any] = [:]
1642+
if !urlParams.isEmpty {
1643+
toObject["_url"] = urlParams
1644+
}
1645+
if !queryParams.isEmpty {
1646+
toObject["_query"] = queryParams
1647+
}
1648+
return toObject
1649+
} catch {
1650+
throw NSError(
1651+
domain: "SwiftSDK", code: -1,
1652+
userInfo: [NSLocalizedDescriptionKey: "Failed to encode Content: \(error)"])
1653+
}
1654+
}
1655+
15731656
public static func functionDeclarationToVertex(
15741657
apiClient: APIClient, fromObject: FunctionDeclaration
15751658
) throws -> [String: Any] {
@@ -1661,6 +1744,51 @@ public enum Converters {
16611744
}
16621745
}
16631746

1747+
public static func toolConfigToVertex(apiClient: APIClient, fromObject: ToolConfig) throws
1748+
-> [String: Any]
1749+
{
1750+
1751+
if fromObject.includeServerSideToolInvocations != nil {
1752+
throw NSError(
1753+
domain: "Vertex AI", code: -1,
1754+
userInfo: [
1755+
NSLocalizedDescriptionKey:
1756+
"includeServerSideToolInvocations parameter is not supported in Vertex AI."
1757+
])
1758+
}
1759+
1760+
let encoder = JSONEncoder()
1761+
encoder.userInfo[.configuration] = apiClient
1762+
encoder.keyEncodingStrategy = .convertToSnakeCase
1763+
do {
1764+
let data = try encoder.encode(fromObject)
1765+
guard
1766+
let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
1767+
as? [String: Any]
1768+
else {
1769+
throw NSError(
1770+
domain: "SwiftSDK", code: -1,
1771+
userInfo: [
1772+
NSLocalizedDescriptionKey: "Failed to convert encoded data to dictionary for ToolConfig"
1773+
])
1774+
}
1775+
var toObject = dictionary
1776+
var urlParams: [String: Any] = [:]
1777+
var queryParams: [String: Any] = [:]
1778+
if !urlParams.isEmpty {
1779+
toObject["_url"] = urlParams
1780+
}
1781+
if !queryParams.isEmpty {
1782+
toObject["_query"] = queryParams
1783+
}
1784+
return toObject
1785+
} catch {
1786+
throw NSError(
1787+
domain: "SwiftSDK", code: -1,
1788+
userInfo: [NSLocalizedDescriptionKey: "Failed to encode ToolConfig: \(error)"])
1789+
}
1790+
}
1791+
16641792
public static func imageConfigToVertex(apiClient: APIClient, fromObject: ImageConfig) throws
16651793
-> [String: Any]
16661794
{
@@ -3577,6 +3705,30 @@ public enum Converters {
35773705
}
35783706
}
35793707

3708+
public static func partFromVertex(apiClient: APIClient, fromObject: Data) throws -> Part? {
3709+
do {
3710+
let decoder = JSONDecoder()
3711+
decoder.userInfo[.configuration] = apiClient
3712+
let instance = try decoder.decode(Part.self, from: fromObject)
3713+
return instance
3714+
} catch {
3715+
print("Failed to decode Part: \(error)")
3716+
return nil
3717+
}
3718+
}
3719+
3720+
public static func contentFromVertex(apiClient: APIClient, fromObject: Data) throws -> Content? {
3721+
do {
3722+
let decoder = JSONDecoder()
3723+
decoder.userInfo[.configuration] = apiClient
3724+
let instance = try decoder.decode(Content.self, from: fromObject)
3725+
return instance
3726+
} catch {
3727+
print("Failed to decode Content: \(error)")
3728+
return nil
3729+
}
3730+
}
3731+
35803732
public static func urlMetadataFromVertex(apiClient: APIClient, fromObject: Data) throws
35813733
-> UrlMetadata?
35823734
{
@@ -4761,6 +4913,104 @@ public enum Converters {
47614913
}
47624914
}
47634915

4916+
public static func datasetStatsFromVertex(apiClient: APIClient, fromObject: Data) throws
4917+
-> DatasetStats?
4918+
{
4919+
do {
4920+
let decoder = JSONDecoder()
4921+
decoder.userInfo[.configuration] = apiClient
4922+
let instance = try decoder.decode(DatasetStats.self, from: fromObject)
4923+
return instance
4924+
} catch {
4925+
print("Failed to decode DatasetStats: \(error)")
4926+
return nil
4927+
}
4928+
}
4929+
4930+
public static func distillationDataStatsFromVertex(apiClient: APIClient, fromObject: Data) throws
4931+
-> DistillationDataStats?
4932+
{
4933+
do {
4934+
let decoder = JSONDecoder()
4935+
decoder.userInfo[.configuration] = apiClient
4936+
let instance = try decoder.decode(DistillationDataStats.self, from: fromObject)
4937+
return instance
4938+
} catch {
4939+
print("Failed to decode DistillationDataStats: \(error)")
4940+
return nil
4941+
}
4942+
}
4943+
4944+
public static func geminiPreferenceExampleCompletionFromVertex(
4945+
apiClient: APIClient, fromObject: Data
4946+
) throws -> GeminiPreferenceExampleCompletion? {
4947+
do {
4948+
let decoder = JSONDecoder()
4949+
decoder.userInfo[.configuration] = apiClient
4950+
let instance = try decoder.decode(GeminiPreferenceExampleCompletion.self, from: fromObject)
4951+
return instance
4952+
} catch {
4953+
print("Failed to decode GeminiPreferenceExampleCompletion: \(error)")
4954+
return nil
4955+
}
4956+
}
4957+
4958+
public static func geminiPreferenceExampleFromVertex(apiClient: APIClient, fromObject: Data)
4959+
throws -> GeminiPreferenceExample?
4960+
{
4961+
do {
4962+
let decoder = JSONDecoder()
4963+
decoder.userInfo[.configuration] = apiClient
4964+
let instance = try decoder.decode(GeminiPreferenceExample.self, from: fromObject)
4965+
return instance
4966+
} catch {
4967+
print("Failed to decode GeminiPreferenceExample: \(error)")
4968+
return nil
4969+
}
4970+
}
4971+
4972+
public static func preferenceOptimizationDataStatsFromVertex(
4973+
apiClient: APIClient, fromObject: Data
4974+
) throws -> PreferenceOptimizationDataStats? {
4975+
do {
4976+
let decoder = JSONDecoder()
4977+
decoder.userInfo[.configuration] = apiClient
4978+
let instance = try decoder.decode(PreferenceOptimizationDataStats.self, from: fromObject)
4979+
return instance
4980+
} catch {
4981+
print("Failed to decode PreferenceOptimizationDataStats: \(error)")
4982+
return nil
4983+
}
4984+
}
4985+
4986+
public static func supervisedTuningDataStatsFromVertex(apiClient: APIClient, fromObject: Data)
4987+
throws -> SupervisedTuningDataStats?
4988+
{
4989+
do {
4990+
let decoder = JSONDecoder()
4991+
decoder.userInfo[.configuration] = apiClient
4992+
let instance = try decoder.decode(SupervisedTuningDataStats.self, from: fromObject)
4993+
return instance
4994+
} catch {
4995+
print("Failed to decode SupervisedTuningDataStats: \(error)")
4996+
return nil
4997+
}
4998+
}
4999+
5000+
public static func tuningDataStatsFromVertex(apiClient: APIClient, fromObject: Data) throws
5001+
-> TuningDataStats?
5002+
{
5003+
do {
5004+
let decoder = JSONDecoder()
5005+
decoder.userInfo[.configuration] = apiClient
5006+
let instance = try decoder.decode(TuningDataStats.self, from: fromObject)
5007+
return instance
5008+
} catch {
5009+
print("Failed to decode TuningDataStats: \(error)")
5010+
return nil
5011+
}
5012+
}
5013+
47645014
public static func generationConfigFromVertex(apiClient: APIClient, fromObject: Data) throws
47655015
-> GenerationConfig?
47665016
{

0 commit comments

Comments
 (0)