Skip to content

Commit 2ccca17

Browse files
committed
Add support for request options
1 parent 71acb55 commit 2ccca17

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

FirebaseAI/Sources/FirebaseAI.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@ public final class FirebaseAI: Sendable {
151151
///
152152
/// - Parameters:
153153
/// - modelName: The name of the Livemodel to use, for example
154-
/// `"gemini-live-2.5-flash-preview"`;
154+
/// `"gemini-live-2.5-flash-preview"`;
155155
/// see [model versions](https://firebase.google.com/docs/ai-logic/live-api?api=dev#models-that-support-capability)
156156
/// for a list of supported Live models.
157157
/// - generationConfig: The content generation parameters your model should use.
158158
/// - tools: A list of ``Tool`` objects that the model may use to generate the next response.
159159
/// - toolConfig: Tool configuration for any ``Tool`` specified in the request.
160160
/// - systemInstruction: Instructions that direct the model to behave a certain way; currently
161161
/// only text content is supported.
162+
/// - requestOptions: Configuration parameters for sending requests to the backend.
162163
public func liveModel(modelName: String,
163164
generationConfig: LiveGenerationConfig? = nil,
164165
tools: [Tool]? = nil,
@@ -172,7 +173,8 @@ public final class FirebaseAI: Sendable {
172173
generationConfig: generationConfig,
173174
tools: tools,
174175
toolConfig: toolConfig,
175-
systemInstruction: systemInstruction
176+
systemInstruction: systemInstruction,
177+
requestOptions: requestOptions
176178
)
177179
}
178180

FirebaseAI/Sources/Types/Internal/Live/LiveSessionService.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ actor LiveSessionService {
4444
let urlSession: URLSession
4545
let apiConfig: APIConfig
4646
let firebaseInfo: FirebaseInfo
47+
let requestOptions: RequestOptions
4748
let tools: [Tool]?
4849
let toolConfig: ToolConfig?
4950
let systemInstruction: ModelContent?
@@ -73,7 +74,8 @@ actor LiveSessionService {
7374
firebaseInfo: FirebaseInfo,
7475
tools: [Tool]?,
7576
toolConfig: ToolConfig?,
76-
systemInstruction: ModelContent?) {
77+
systemInstruction: ModelContent?,
78+
requestOptions: RequestOptions) {
7779
(responses, responseContinuation) = AsyncThrowingStream.makeStream()
7880
(messageQueue, messageQueueContinuation) = AsyncStream.makeStream()
7981
self.modelResourceName = modelResourceName
@@ -84,6 +86,7 @@ actor LiveSessionService {
8486
self.tools = tools
8587
self.toolConfig = toolConfig
8688
self.systemInstruction = systemInstruction
89+
self.requestOptions = requestOptions
8790
setupTask = Task {}
8891
}
8992

@@ -301,6 +304,7 @@ actor LiveSessionService {
301304
)
302305
}
303306
var urlRequest = URLRequest(url: url)
307+
urlRequest.timeoutInterval = requestOptions.timeout
304308
urlRequest.setValue(firebaseInfo.apiKey, forHTTPHeaderField: "x-goog-api-key")
305309
urlRequest.setValue(
306310
"\(GenerativeAIService.languageTag) \(GenerativeAIService.firebaseVersionTag)",

FirebaseAI/Sources/Types/Public/Live/LiveGenerativeModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public final class LiveGenerativeModel {
2828
let toolConfig: ToolConfig?
2929
let systemInstruction: ModelContent?
3030
let urlSession: URLSession
31+
let requestOptions: RequestOptions
3132

3233
init(modelResourceName: String,
3334
firebaseInfo: FirebaseInfo,
@@ -36,7 +37,8 @@ public final class LiveGenerativeModel {
3637
tools: [Tool]? = nil,
3738
toolConfig: ToolConfig? = nil,
3839
systemInstruction: ModelContent? = nil,
39-
urlSession: URLSession = GenAIURLSession.default) {
40+
urlSession: URLSession = GenAIURLSession.default,
41+
requestOptions: RequestOptions) {
4042
self.modelResourceName = modelResourceName
4143
self.firebaseInfo = firebaseInfo
4244
self.apiConfig = apiConfig
@@ -45,6 +47,7 @@ public final class LiveGenerativeModel {
4547
self.toolConfig = toolConfig
4648
self.systemInstruction = systemInstruction
4749
self.urlSession = urlSession
50+
self.requestOptions = requestOptions
4851
}
4952

5053
/// Start a ``LiveSession`` with the server for bidirectional streaming.
@@ -60,6 +63,7 @@ public final class LiveGenerativeModel {
6063
tools: tools,
6164
toolConfig: toolConfig,
6265
systemInstruction: systemInstruction,
66+
requestOptions: requestOptions
6367
)
6468

6569
await service.connect()

0 commit comments

Comments
 (0)