mirror of
https://github.com/tcsenpai/ollama.git
synced 2025-06-08 12:15:22 +00:00
error handling
This commit is contained in:
parent
2a9feb0707
commit
a5181a8c51
@ -458,6 +458,7 @@ type GenerateResponse struct {
|
|||||||
|
|
||||||
type WhisperCompletion struct {
|
type WhisperCompletion struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModelDetails provides details about a model.
|
// ModelDetails provides details about a model.
|
||||||
|
@ -112,7 +112,7 @@ func (s *Server) scheduleRunner(ctx context.Context, name string, caps []Capabil
|
|||||||
func (s *Server) runWhisperServer(c *gin.Context, portCh chan int, modelPath string) {
|
func (s *Server) runWhisperServer(c *gin.Context, portCh chan int, modelPath string) {
|
||||||
s.sched.whisperMu.Lock()
|
s.sched.whisperMu.Lock()
|
||||||
if s.sched.whisperLoaded[modelPath] != nil {
|
if s.sched.whisperLoaded[modelPath] != nil {
|
||||||
slog.Info("whisper server already running %s on port %d", modelPath, *s.sched.whisperLoaded[modelPath])
|
slog.Info(fmt.Sprintf("whisper server already running %s on port %d", modelPath, *s.sched.whisperLoaded[modelPath]))
|
||||||
portCh <- *s.sched.whisperLoaded[modelPath]
|
portCh <- *s.sched.whisperLoaded[modelPath]
|
||||||
s.sched.whisperMu.Unlock()
|
s.sched.whisperMu.Unlock()
|
||||||
return
|
return
|
||||||
@ -239,17 +239,17 @@ func whisperInference(c *gin.Context, filePath string, port int) (*api.WhisperCo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode >= 400 {
|
|
||||||
slog.Error("error response from whisper server", "status", res.Status, "body", string(body))
|
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "error response from whisper server"})
|
|
||||||
}
|
|
||||||
|
|
||||||
var w api.WhisperCompletion
|
var w api.WhisperCompletion
|
||||||
if err := json.Unmarshal(body, &w); err != nil {
|
if err := json.Unmarshal(body, &w); err != nil {
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to unmarshal response"})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": "failed to unmarshal response"})
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if w.Error != "" {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": w.Error})
|
||||||
|
return nil, fmt.Errorf(w.Error)
|
||||||
|
}
|
||||||
|
|
||||||
return &w, nil
|
return &w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ func InitScheduler(ctx context.Context) *Scheduler {
|
|||||||
getGpuFn: gpu.GetGPUInfo,
|
getGpuFn: gpu.GetGPUInfo,
|
||||||
getCpuFn: gpu.GetCPUInfo,
|
getCpuFn: gpu.GetCPUInfo,
|
||||||
reschedDelay: 250 * time.Millisecond,
|
reschedDelay: 250 * time.Millisecond,
|
||||||
|
whisperLoaded: make(map[string]*int),
|
||||||
}
|
}
|
||||||
sched.loadFn = sched.load
|
sched.loadFn = sched.load
|
||||||
return sched
|
return sched
|
||||||
|
Loading…
x
Reference in New Issue
Block a user