diff options
author | Grail Finder <wohilas@gmail.com> | 2025-02-11 09:21:46 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2025-02-11 09:21:46 +0300 |
commit | f0fb6a31370024f7bd4a711856f9af21e6e322c4 (patch) | |
tree | 33f1ff6a4c4bba6a5efc3b4ffb37baaf2c23b1d4 /server.go | |
parent | 54680539085d354ac9473fa451e284963e12000a (diff) |
Fix: /v1 chat endpoint; linter
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -9,6 +9,7 @@ import ( ) type Server struct { + // nolint config config.Config } @@ -25,13 +26,17 @@ func (srv *Server) ListenToRequests(port string) { mux.HandleFunc("GET /model", modelHandler) mux.HandleFunc("POST /completion", completionHandler) fmt.Println("Listening", "addr", server.Addr) - server.ListenAndServe() + if err := server.ListenAndServe(); err != nil { + panic(err) + } } // create server // listen to the completion endpoint handler func pingHandler(w http.ResponseWriter, req *http.Request) { - w.Write([]byte("pong")) + if _, err := w.Write([]byte("pong")); err != nil { + logger.Error("server ping", "error", err) + } } func completionHandler(w http.ResponseWriter, req *http.Request) { @@ -44,20 +49,26 @@ out: for { select { case chunk := <-chunkChan: - fmt.Println(chunk) - w.Write([]byte(chunk)) + fmt.Print(chunk) + if _, err := w.Write([]byte(chunk)); err != nil { + logger.Warn("failed to write chunk", "value", chunk) + continue + } case <-streamDone: break out } } - return } func modelHandler(w http.ResponseWriter, req *http.Request) { llmModel := fetchModelName() payload, err := json.Marshal(llmModel) if err != nil { + logger.Error("model handler", "error", err) // return err + return + } + if _, err := w.Write(payload); err != nil { + logger.Error("model handler", "error", err) } - w.Write(payload) } |