Skip to content

Commit 03f3e2a

Browse files
committed
fixup specifying event type
1 parent bbb9fbc commit 03f3e2a

File tree

2 files changed

+217
-113
lines changed

2 files changed

+217
-113
lines changed

core/http/endpoints/openai/realtime.go

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,7 @@ func registerRealtime(application *application.Application, model, intent string
229229

230230
sendEvent(c, types.SessionCreatedEvent{
231231
ServerEventBase: types.ServerEventBase{
232-
EventBase: types.EventBase{
233-
EventID: "event_TODO",
234-
Type: string(types.ServerEventTypeSessionCreated),
235-
},
232+
EventID: "event_TODO",
236233
},
237234
Session: session.ToServer(),
238235
})
@@ -302,10 +299,7 @@ func registerRealtime(application *application.Application, model, intent string
302299

303300
sendEvent(c, types.SessionUpdatedEvent{
304301
ServerEventBase: types.ServerEventBase{
305-
EventBase: types.EventBase{
306-
EventID: "event_TODO",
307-
Type: string(types.ServerEventTypeSessionUpdated),
308-
},
302+
EventID: "event_TODO",
309303
},
310304
Session: session.ToServer(),
311305
})
@@ -329,10 +323,7 @@ func registerRealtime(application *application.Application, model, intent string
329323

330324
sendEvent(c, types.SessionUpdatedEvent{
331325
ServerEventBase: types.ServerEventBase{
332-
EventBase: types.EventBase{
333-
EventID: "event_TODO",
334-
Type: string(types.ServerEventTypeSessionUpdated),
335-
},
326+
EventID: "event_TODO",
336327
},
337328
Session: session.ToServer(),
338329
})
@@ -421,10 +412,7 @@ func registerRealtime(application *application.Application, model, intent string
421412

422413
sendEvent(c, types.ConversationItemRetrievedEvent{
423414
ServerEventBase: types.ServerEventBase{
424-
EventBase: types.EventBase{
425-
Type: string(types.ServerEventTypeConversationItemRetrieved),
426-
EventID: "event_TODO",
427-
},
415+
EventID: "event_TODO",
428416
},
429417
Item: retrievedItem,
430418
})
@@ -473,10 +461,7 @@ func sendEvent(c *websocket.Conn, event types.ServerEvent) {
473461
func sendError(c *websocket.Conn, code, message, param, eventID string) {
474462
errorEvent := types.ErrorEvent{
475463
ServerEventBase: types.ServerEventBase{
476-
EventBase: types.EventBase{
477-
Type: string(types.ServerEventTypeError),
478-
EventID: eventID,
479-
},
464+
EventID: eventID,
480465
},
481466
Error: types.Error{
482467
Type: "invalid_request_error",
@@ -645,10 +630,7 @@ func handleVAD(cfg *config.ModelConfig, evaluator *templates.Evaluator, session
645630

646631
sendEvent(c, types.InputAudioBufferClearedEvent{
647632
ServerEventBase: types.ServerEventBase{
648-
EventBase: types.EventBase{
649-
EventID: "event_TODO",
650-
Type: string(types.ServerEventTypeInputAudioBufferCleared),
651-
},
633+
EventID: "event_TODO",
652634
},
653635
})
654636

@@ -660,10 +642,7 @@ func handleVAD(cfg *config.ModelConfig, evaluator *templates.Evaluator, session
660642
if !speechStarted {
661643
sendEvent(c, types.InputAudioBufferSpeechStartedEvent{
662644
ServerEventBase: types.ServerEventBase{
663-
EventBase: types.EventBase{
664-
EventID: "event_TODO",
665-
Type: string(types.ServerEventTypeInputAudioBufferSpeechStarted),
666-
},
645+
EventID: "event_TODO",
667646
},
668647
AudioStartMs: time.Since(startTime).Milliseconds(),
669648
})
@@ -684,21 +663,15 @@ func handleVAD(cfg *config.ModelConfig, evaluator *templates.Evaluator, session
684663

685664
sendEvent(c, types.InputAudioBufferSpeechStoppedEvent{
686665
ServerEventBase: types.ServerEventBase{
687-
EventBase: types.EventBase{
688-
EventID: "event_TODO",
689-
Type: string(types.ServerEventTypeInputAudioBufferSpeechStopped),
690-
},
666+
EventID: "event_TODO",
691667
},
692668
AudioEndMs: time.Since(startTime).Milliseconds(),
693669
})
694670
speechStarted = false
695671

696672
sendEvent(c, types.InputAudioBufferCommittedEvent{
697673
ServerEventBase: types.ServerEventBase{
698-
EventBase: types.EventBase{
699-
EventID: "event_TODO",
700-
Type: string(types.ServerEventTypeInputAudioBufferCommitted),
701-
},
674+
EventID: "event_TODO",
702675
},
703676
ItemID: generateItemID(),
704677
PreviousItemID: "TODO",
@@ -756,10 +729,7 @@ func commitUtterance(ctx context.Context, utt []byte, cfg *config.ModelConfig, e
756729
transcript = tr.GetText()
757730
sendEvent(c, types.ConversationItemInputAudioTranscriptionCompletedEvent{
758731
ServerEventBase: types.ServerEventBase{
759-
EventBase: types.EventBase{
760-
Type: string(types.ServerEventTypeConversationItemInputAudioTranscriptionCompleted),
761-
EventID: "event_TODO",
762-
},
732+
EventID: "event_TODO",
763733
},
764734

765735
ItemID: generateItemID(),
@@ -820,11 +790,6 @@ func generateResponse(config *config.ModelConfig, evaluator *templates.Evaluator
820790
conv.Lock.Unlock()
821791

822792
sendEvent(c, types.ConversationItemAddedEvent{
823-
ServerEventBase: types.ServerEventBase{
824-
EventBase: types.EventBase{
825-
Type: string(types.ServerEventTypeConversationItemAdded),
826-
},
827-
},
828793
Item: item,
829794
})
830795

@@ -888,11 +853,6 @@ func generateResponse(config *config.ModelConfig, evaluator *templates.Evaluator
888853
}
889854

890855
sendEvent(c, types.ConversationItemAddedEvent{
891-
ServerEventBase: types.ServerEventBase{
892-
EventBase: types.EventBase{
893-
Type: string(types.ServerEventTypeConversationItemAdded),
894-
},
895-
},
896856
Item: item,
897857
})
898858

@@ -973,35 +933,23 @@ func generateResponse(config *config.ModelConfig, evaluator *templates.Evaluator
973933
audioString := base64.StdEncoding.EncodeToString(audioBytes)
974934

975935
sendEvent(c, types.ResponseOutputAudioDeltaEvent{
976-
ServerEventBase: types.ServerEventBase{
977-
EventBase: types.EventBase{
978-
Type: string(types.ServerEventTypeResponseOutputAudioDelta),
979-
},
980-
},
981-
ItemID: item.Assistant.ID,
936+
ServerEventBase: types.ServerEventBase{},
937+
ItemID: item.Assistant.ID,
982938
// TODO: OutputIndex and ContentIndex
983939
Delta: audioString,
984940
})
985941
sendEvent(c, types.ResponseOutputAudioDoneEvent{
986-
ServerEventBase: types.ServerEventBase{
987-
EventBase: types.EventBase{
988-
Type: string(types.ServerEventTypeResponseOutputAudioDone),
989-
},
990-
},
991-
ItemID: item.Assistant.ID,
942+
ServerEventBase: types.ServerEventBase{},
943+
ItemID: item.Assistant.ID,
992944
// TODO: Indexs
993945
})
994946

995947
// OpenAI does not send the audio as part of the conversation.
996948
// It's sent as audio deltas or the user can request it with conversation.item.retrieve.
997949
conv.Lock.Lock()
998950
doneEvent := types.ConversationItemDoneEvent{
999-
ServerEventBase: types.ServerEventBase{
1000-
EventBase: types.EventBase{
1001-
Type: string(types.ServerEventTypeConversationItemDone),
1002-
},
1003-
},
1004-
Item: item,
951+
ServerEventBase: types.ServerEventBase{},
952+
Item: item,
1005953
}
1006954
item.Assistant.Content[0].Audio = audioString
1007955
conv.Lock.Unlock()

0 commit comments

Comments
 (0)