Skip to content

Added Google Search support #218

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion Sources/GoogleAI/FunctionCalling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public struct Tool {
/// Enables the model to execute code as part of generation.
let codeExecution: CodeExecution?

/// Enables the Google Search
let googleSearch: GoogleSearch?

/// Constructs a new `Tool`.
///
/// - Parameters:
Expand All @@ -176,10 +179,13 @@ public struct Tool {
/// ``FunctionResponse`` in ``ModelContent/Part/functionResponse(_:)`` with the
/// ``ModelContent/role`` "function", providing generation context for the next model turn.
/// - codeExecution: Enables the model to execute code as part of generation, if provided.
/// - googleSearch: Enables the Google Search.
public init(functionDeclarations: [FunctionDeclaration]? = nil,
codeExecution: CodeExecution? = nil) {
codeExecution: CodeExecution? = nil,
googleSearch: GoogleSearch? = nil) {
self.functionDeclarations = functionDeclarations
self.codeExecution = codeExecution
self.googleSearch = googleSearch
}
}

Expand Down Expand Up @@ -259,6 +265,12 @@ public struct CodeExecution {
public init() {}
}

/// Tool for grounding with Google Search
public struct GoogleSearch {
/// Constructs a new `GoogleSearch` tool.
public init() {}
}

/// Code generated by the model that is meant to be executed, and the result returned to the model.
///
/// Only generated when using the ``CodeExecution`` tool, in which case the code will automatically
Expand Down Expand Up @@ -351,6 +363,8 @@ extension FunctionResponse: Encodable {}

extension CodeExecution: Encodable {}

extension GoogleSearch: Encodable {}

extension ExecutableCode: Codable {}

@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
Expand Down