Skip to content

Commit

Permalink
Make requestOptions non-optional in GenerativeModel (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard authored Jan 31, 2024
1 parent f029e13 commit ccf2c94
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/GoogleAI/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
struct CountTokensRequest {
let model: String
let contents: [ModelContent]
let options: RequestOptions?
let options: RequestOptions
}

extension CountTokensRequest: Encodable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct GenerateContentRequest {
let generationConfig: GenerationConfig?
let safetySettings: [SafetySetting]?
let isStreaming: Bool
let options: RequestOptions?
let options: RequestOptions
}

extension GenerateContentRequest: Encodable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol GenerativeAIRequest: Encodable {

var url: URL { get }

var options: RequestOptions? { get }
var options: RequestOptions { get }
}

/// Configuration parameters for sending requests to the backend.
Expand Down
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeAIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct GenerativeAIService {
encoder.keyEncodingStrategy = .convertToSnakeCase
urlRequest.httpBody = try encoder.encode(request)

if let timeoutInterval = request.options?.timeout {
if let timeoutInterval = request.options.timeout {
urlRequest.timeoutInterval = timeoutInterval
}

Expand Down
19 changes: 9 additions & 10 deletions Sources/GoogleAI/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@ public final class GenerativeModel {
let safetySettings: [SafetySetting]?

/// Configuration parameters for sending requests to the backend.
let requestOptions: RequestOptions?
let requestOptions: RequestOptions

/// Initializes a new remote model with the given parameters.
///
/// - Parameter name: The name of the model to be used, e.g., "gemini-pro" or "models/gemini-pro".
/// - Parameter apiKey: The API key for your project.
/// - Parameter generationConfig: A value containing the content generation parameters your model
/// should use.
/// - Parameter safetySettings: A value describing what types of harmful content your model
/// should allow.
/// - Parameter requestOptions Configuration parameters for sending requests to the backend.
/// - Parameters:
/// - name: The name of the model to be used, e.g., "gemini-pro" or "models/gemini-pro".
/// - apiKey: The API key for your project.
/// - generationConfig: The content generation parameters your model should use.
/// - safetySettings: A value describing what types of harmful content your model should allow.
/// - requestOptions Configuration parameters for sending requests to the backend.
public convenience init(name: String,
apiKey: String,
generationConfig: GenerationConfig? = nil,
safetySettings: [SafetySetting]? = nil,
requestOptions: RequestOptions? = nil) {
requestOptions: RequestOptions = RequestOptions()) {
self.init(
name: name,
apiKey: apiKey,
Expand All @@ -64,7 +63,7 @@ public final class GenerativeModel {
apiKey: String,
generationConfig: GenerationConfig? = nil,
safetySettings: [SafetySetting]? = nil,
requestOptions: RequestOptions? = nil,
requestOptions: RequestOptions = RequestOptions(),
urlSession: URLSession) {
modelResourceName = GenerativeModel.modelResourceName(name: name)
generativeAIService = GenerativeAIService(apiKey: apiKey, urlSession: urlSession)
Expand Down

0 comments on commit ccf2c94

Please sign in to comment.