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

Add apiVersion to RequestOptions #101

Merged
merged 1 commit into from
Feb 9, 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
2 changes: 1 addition & 1 deletion Sources/GoogleAI/CountTokensRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension CountTokensRequest: GenerativeAIRequest {
typealias Response = CountTokensResponse

var url: URL {
URL(string: "\(GenerativeAISwift.baseURL)/\(model):countTokens")!
URL(string: "\(GenerativeAISwift.baseURL)/\(options.apiVersion)/\(model):countTokens")!
}
}

Expand Down
5 changes: 3 additions & 2 deletions Sources/GoogleAI/GenerateContentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ extension GenerateContentRequest: GenerativeAIRequest {
typealias Response = GenerateContentResponse

var url: URL {
let modelURL = "\(GenerativeAISwift.baseURL)/\(options.apiVersion)/\(model)"
if isStreaming {
return URL(string: "\(GenerativeAISwift.baseURL)/\(model):streamGenerateContent?alt=sse")!
return URL(string: "\(modelURL):streamGenerateContent?alt=sse")!
} else {
return URL(string: "\(GenerativeAISwift.baseURL)/\(model):generateContent")!
return URL(string: "\(modelURL):generateContent")!
}
}
}
12 changes: 9 additions & 3 deletions Sources/GoogleAI/GenerativeAIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public struct RequestOptions {
/// `URLRequest`.
let timeout: TimeInterval?

/// The API version to use in requests to the backend.
let apiVersion: String

/// Initializes a request options object.
///
/// - Parameter timeout The request’s timeout interval in seconds; if not specified uses the
/// default value for a `URLRequest`.
public init(timeout: TimeInterval? = nil) {
/// - Parameters:
/// - timeout The request’s timeout interval in seconds; if not specified uses the default value
/// for a `URLRequest`.
/// - apiVersion The API version to use in requests to the backend; defaults to "v1".
public init(timeout: TimeInterval? = nil, apiVersion: String = "v1") {
self.timeout = timeout
self.apiVersion = apiVersion
}
}
2 changes: 1 addition & 1 deletion Sources/GoogleAI/GenerativeAISwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import Foundation
public enum GenerativeAISwift {
/// String value of the SDK version
public static let version = "0.4.7"
static let baseURL = "https://generativelanguage.googleapis.com/v1"
static let baseURL = "https://generativelanguage.googleapis.com"
}
Loading