Skip to content

Commit

Permalink
adding some models (#20)
Browse files Browse the repository at this point in the history
* more models

* more models

* nit
abizzaar authored Nov 8, 2024
1 parent 0ab095f commit ee89eeb
Showing 7 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Examples/SwiftUICallView.swift
Original file line number Diff line number Diff line change
@@ -39,6 +39,14 @@ class CallManager: ObservableObject {
print(event)
case .transcript:
print(event)
case .statusUpdate:
print(event)
case .modelOutput:
print(event)
case .userInterrupted:
print(event)
case .voiceInput:
print(event)
case .error(let error):
print("Error: \(error)")
}
4 changes: 4 additions & 0 deletions Sources/Models/AppMessage.swift
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ struct AppMessage: Codable {
case speechUpdate = "speech-update"
case metadata
case conversationUpdate = "conversation-update"
case modelOutput = "model-output"
case statusUpdate = "status-update"
case voiceInput = "voice-input"
case userInterrupted = "user-interrupted"
}

let type: MessageType
5 changes: 5 additions & 0 deletions Sources/Models/ModelOutput.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public struct ModelOutput: Codable {
public let output: String
}
5 changes: 5 additions & 0 deletions Sources/Models/StatusUpdate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public struct StatusUpdate: Codable {
public let status: String
}
10 changes: 10 additions & 0 deletions Sources/Models/UserInterrupted.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// UserInterrupted.swift
// Vapi
//
// Created by Abizar Bagasrawala on 11/1/24.
//

import Foundation

public struct UserInterrupted: Codable {}
12 changes: 12 additions & 0 deletions Sources/Models/VoiceInput.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// VoiceInput.swift
// Vapi
//
// Created by Abizar Bagasrawala on 11/1/24.
//

import Foundation

public struct VoiceInput: Codable {
public let input: String
}
16 changes: 16 additions & 0 deletions Sources/Vapi.swift
Original file line number Diff line number Diff line change
@@ -45,6 +45,10 @@ public final class Vapi: CallClientDelegate {
case speechUpdate(SpeechUpdate)
case metadata(Metadata)
case conversationUpdate(ConversationUpdate)
case statusUpdate(StatusUpdate)
case modelOutput(ModelOutput)
case userInterrupted(UserInterrupted)
case voiceInput(VoiceInput)
case hang
case error(Swift.Error)
}
@@ -475,6 +479,18 @@ public final class Vapi: CallClientDelegate {
case .conversationUpdate:
let conv = try decoder.decode(ConversationUpdate.self, from: unescapedData)
event = Event.conversationUpdate(conv)
case .statusUpdate:
let statusUpdate = try decoder.decode(StatusUpdate.self, from: unescapedData)
event = Event.statusUpdate(statusUpdate)
case .modelOutput:
let modelOutput = try decoder.decode(ModelOutput.self, from: unescapedData)
event = Event.modelOutput(modelOutput)
case .userInterrupted:
let userInterrupted = UserInterrupted()
event = Event.userInterrupted(userInterrupted)
case .voiceInput:
let voiceInput = try decoder.decode(VoiceInput.self, from: unescapedData)
event = Event.voiceInput(voiceInput)
}
eventSubject.send(event)
} catch {

0 comments on commit ee89eeb

Please sign in to comment.