Skip to content

Commit 1808ab0

Browse files
authored
Merge pull request #10 from elevenlabs/angelo/add_dynamic_variables
add support for dynamic variables
2 parents 6572735 + b9ee689 commit 1808ab0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Sources/ElevenLabsSwift/ElevenLabsSwift.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,34 @@ public class ElevenLabsSDK {
217217

218218
// MARK: - Connection
219219

220+
public enum DynamicVariableValue: Sendable {
221+
case string(String)
222+
case number(Double)
223+
case boolean(Bool)
224+
case int(Int)
225+
}
226+
220227
public struct SessionConfig: Sendable {
221228
public let signedUrl: String?
222229
public let agentId: String?
223230
public let overrides: ConversationConfigOverride?
224231
public let customLlmExtraBody: [String: LlmExtraBodyValue]?
232+
public let dynamicVariables: [String: DynamicVariableValue]?
225233

226-
public init(signedUrl: String, overrides: ConversationConfigOverride? = nil, customLlmExtraBody: [String: LlmExtraBodyValue]? = nil, clientTools _: ClientTools = ClientTools()) {
234+
public init(signedUrl: String, overrides: ConversationConfigOverride? = nil, customLlmExtraBody: [String: LlmExtraBodyValue]? = nil, clientTools _: ClientTools = ClientTools(), dynamicVariables: [String: DynamicVariableValue]? = nil) {
227235
self.signedUrl = signedUrl
228236
agentId = nil
229237
self.overrides = overrides
230238
self.customLlmExtraBody = customLlmExtraBody
239+
self.dynamicVariables = dynamicVariables
231240
}
232241

233-
public init(agentId: String, overrides: ConversationConfigOverride? = nil, customLlmExtraBody: [String: LlmExtraBodyValue]? = nil, clientTools _: ClientTools = ClientTools()) {
242+
public init(agentId: String, overrides: ConversationConfigOverride? = nil, customLlmExtraBody: [String: LlmExtraBodyValue]? = nil, clientTools _: ClientTools = ClientTools(), dynamicVariables: [String: DynamicVariableValue]? = nil) {
234243
self.agentId = agentId
235244
signedUrl = nil
236245
self.overrides = overrides
237246
self.customLlmExtraBody = customLlmExtraBody
247+
self.dynamicVariables = dynamicVariables
238248
}
239249
}
240250

@@ -285,6 +295,11 @@ public class ElevenLabsSDK {
285295
initEvent["custom_llm_extra_body"] = customBody.mapValues { $0.jsonValue }
286296
}
287297

298+
// add dynamic variables if present
299+
if let dynamicVars = config.dynamicVariables {
300+
initEvent["dynamic_variables"] = dynamicVars
301+
}
302+
288303
let jsonData = try JSONSerialization.data(withJSONObject: initEvent)
289304
let jsonString = String(data: jsonData, encoding: .utf8)!
290305
try await socket.send(.string(jsonString))

0 commit comments

Comments
 (0)