feat: models test and fixes
This commit is contained in:
@@ -36,6 +36,7 @@ type DeepgramAdapter struct {
|
||||
|
||||
// finalization signaling
|
||||
finalizeDone chan struct{}
|
||||
finalizing bool // true when Finalize() has been called
|
||||
}
|
||||
|
||||
// deepgramCloseStream message to signal end of audio
|
||||
@@ -235,7 +236,8 @@ func (a *DeepgramAdapter) buildURL() (string, error) {
|
||||
q.Set("language", lang)
|
||||
}
|
||||
|
||||
if len(a.keywords) > 0 {
|
||||
// nova-3 uses "keyterm" (singular), others use "keywords" (plural)
|
||||
if len(a.keywords) > 0 && !strings.HasPrefix(a.model, "nova-3") && !strings.HasPrefix(a.model, "flux") {
|
||||
q.Set("keywords", strings.Join(a.keywords, ","))
|
||||
}
|
||||
|
||||
@@ -277,6 +279,20 @@ func (a *DeepgramAdapter) readLoop() {
|
||||
default:
|
||||
}
|
||||
|
||||
// check if we're finalizing - normal close after finalize is expected
|
||||
a.mu.Lock()
|
||||
finalizing := a.finalizing
|
||||
a.mu.Unlock()
|
||||
|
||||
if finalizing {
|
||||
// expected close after finalization, signal done and exit gracefully
|
||||
select {
|
||||
case a.finalizeDone <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// attempt reconnection
|
||||
log.Printf("deepgram: read error: %v, attempting reconnection", err)
|
||||
if !a.reconnect() {
|
||||
@@ -411,6 +427,11 @@ func (a *DeepgramAdapter) Finalize(ctx context.Context) error {
|
||||
default:
|
||||
}
|
||||
|
||||
// mark as finalizing to prevent reconnection attempts on normal close
|
||||
a.mu.Lock()
|
||||
a.finalizing = true
|
||||
a.mu.Unlock()
|
||||
|
||||
// send CloseStream message
|
||||
msg := deepgramCloseStream{Type: "CloseStream"}
|
||||
|
||||
@@ -447,6 +468,9 @@ func (a *DeepgramAdapter) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// mark as finalizing to prevent reconnection attempts
|
||||
a.finalizing = true
|
||||
|
||||
// cancel context first to signal reader to stop
|
||||
if a.cancel != nil {
|
||||
a.cancel()
|
||||
|
||||
Reference in New Issue
Block a user