Skip to content

Commit 424698e

Browse files
committed
Fix onboarding and backend asset startup
1 parent 3ac312d commit 424698e

7 files changed

Lines changed: 177 additions & 126 deletions

File tree

backend/internal/minilm/onnx_embeddings.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ func downloadFile(url, dst string, timeout time.Duration) error {
532532
}
533533

534534
func fileExists(p string) bool {
535-
_, err := os.Stat(p)
536-
return err == nil
535+
info, err := os.Stat(p)
536+
return err == nil && !info.IsDir() && info.Size() > 0
537537
}
538538

539539
// unzipOne extracts a specific file from a zip archive to dstDir
@@ -595,10 +595,11 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
595595
return err
596596
}
597597
base := filepath.Base(hdr.Name)
598-
if !set[base] || hdr.FileInfo().IsDir() {
598+
wanted, ok := selectedTarOutputName(hdr.Name, base, set)
599+
if !ok || hdr.FileInfo().IsDir() || hdr.Typeflag != tar.TypeReg {
599600
continue
600601
}
601-
out := filepath.Join(dstDir, base)
602+
out := filepath.Join(dstDir, wanted)
602603
of, err := os.Create(out)
603604
if err != nil {
604605
return err
@@ -611,7 +612,7 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
611612
if runtime.GOOS != "windows" {
612613
_ = os.Chmod(out, 0o755)
613614
}
614-
delete(set, base)
615+
delete(set, wanted)
615616
if len(set) == 0 {
616617
break
617618
}
@@ -622,6 +623,35 @@ func untarSelect(tgzPath, dstDir string, names []string) error {
622623
return nil
623624
}
624625

626+
func selectedTarOutputName(entryName, base string, set map[string]bool) (string, bool) {
627+
if set[base] {
628+
return base, true
629+
}
630+
631+
if strings.Contains(entryName, ".dSYM/") {
632+
return "", false
633+
}
634+
635+
for wanted := range set {
636+
if isVersionedSharedLibraryName(wanted, base) {
637+
return wanted, true
638+
}
639+
}
640+
return "", false
641+
}
642+
643+
func isVersionedSharedLibraryName(wanted, candidate string) bool {
644+
if strings.HasSuffix(wanted, ".dylib") {
645+
prefix := strings.TrimSuffix(wanted, ".dylib") + "."
646+
return strings.HasPrefix(candidate, prefix) && strings.HasSuffix(candidate, ".dylib")
647+
}
648+
if strings.HasSuffix(wanted, ".so") {
649+
prefix := wanted + "."
650+
return strings.HasPrefix(candidate, prefix)
651+
}
652+
return false
653+
}
654+
625655
func keys(m map[string]bool) []string {
626656
ks := make([]string, 0, len(m))
627657
for k := range m {
@@ -728,4 +758,4 @@ func (w *wordPiece) tokenizeWord(tok string) []int {
728758
tok = tok[len(cur):]
729759
}
730760
return out
731-
}
761+
}

backend/internal/models/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (m *Manager) Initialize(ctx context.Context) error {
4040
log.Println("Initializing STT service...")
4141
sttConfig := &whisper.Config{
4242
Language: "en",
43-
ModelPath: "models/whisper-base.bin",
43+
ModelPath: m.config.Models.Whisper.Path,
4444
SampleRate: 16000,
4545
VoiceThreshold: 0.02,
4646
}
@@ -57,7 +57,7 @@ func (m *Manager) Initialize(ctx context.Context) error {
5757
log.Println("Initializing TTS service...")
5858
ttsConfig := &piper.Config{
5959
PiperPath: "", // Let ensurePiper set the correct OS-specific path
60-
ModelPath: "models/piper",
60+
ModelPath: m.config.Models.Piper.Path,
6161
Voice: "en_US-amy-medium",
6262
Speed: 1.0,
6363
}

0 commit comments

Comments
 (0)