Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ToolConfig and FunctionCallingConfig optional #125

Merged
merged 1 commit into from
Apr 3, 2024
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
5 changes: 4 additions & 1 deletion Examples/GenerativeAICLI/Sources/GenerateContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ struct GenerateContent: AsyncParsableCommand {
requiredParameters: ["currency_from", "currency_to"]
),
])],
toolConfig: ToolConfig(mode: .any),
toolConfig: .init(functionCallingConfig: .init(
mode: .any,
allowedFunctionNames: ["get_exchange_rate"]
)),
requestOptions: RequestOptions(apiVersion: "v1beta")
)

Expand Down
15 changes: 11 additions & 4 deletions Sources/GoogleAI/FunctionCalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,23 @@ public enum Mode: String, Encodable {
}

public struct FunctionCallingConfig: Encodable {
let mode: Mode
let mode: Mode?

let allowedFunctionNames: [String]?

public init(mode: Mode? = nil, allowedFunctionNames: [String]? = nil) {
self.mode = mode
self.allowedFunctionNames = allowedFunctionNames
}
}

/// Tool configuration for any `Tool` specified in the request.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
public struct ToolConfig: Encodable {
let functionCallingConfig: FunctionCallingConfig
let functionCallingConfig: FunctionCallingConfig?

public init(mode: Mode = .auto) {
functionCallingConfig = FunctionCallingConfig(mode: mode)
public init(functionCallingConfig: FunctionCallingConfig? = nil) {
self.functionCallingConfig = functionCallingConfig
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct GenerateContentRequest {
let generationConfig: GenerationConfig?
let safetySettings: [SafetySetting]?
let tools: [Tool]?
let toolConfig: ToolConfig
let toolConfig: ToolConfig?
let isStreaming: Bool
let options: RequestOptions
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class GenerativeModel {
let tools: [Tool]?

// Tool configuration for any `Tool` specified in the request.
let toolConfig: ToolConfig
let toolConfig: ToolConfig?

/// Configuration parameters for sending requests to the backend.
let requestOptions: RequestOptions
Expand All @@ -58,7 +58,7 @@ public final class GenerativeModel {
generationConfig: GenerationConfig? = nil,
safetySettings: [SafetySetting]? = nil,
tools: [Tool]? = nil,
toolConfig: ToolConfig = ToolConfig(mode: Mode.auto),
toolConfig: ToolConfig? = nil,
requestOptions: RequestOptions = RequestOptions()) {
self.init(
name: name,
Expand All @@ -78,7 +78,7 @@ public final class GenerativeModel {
generationConfig: GenerationConfig? = nil,
safetySettings: [SafetySetting]? = nil,
tools: [Tool]? = nil,
toolConfig: ToolConfig = ToolConfig(mode: Mode.auto),
toolConfig: ToolConfig? = nil,
requestOptions: RequestOptions = RequestOptions(),
urlSession: URLSession) {
modelResourceName = GenerativeModel.modelResourceName(name: name)
Expand Down
Loading