summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2026-02-12 10:26:30 +0300
committerGrail Finder <wohilas@gmail.com>2026-02-12 10:26:30 +0300
commit8c3c2b9b23a5b41e207d5771bb365e2c391ed0ea (patch)
tree54bda61b46c4291054c46a08b2fd7f87d0ca5714 /server.go
parente42eb9637190a2e89cf7e37cb10ca986835d9d7a (diff)
Chore: server should live in separate branch
until a usecase for it is found
Diffstat (limited to 'server.go')
-rw-r--r--server.go74
1 files changed, 0 insertions, 74 deletions
diff --git a/server.go b/server.go
deleted file mode 100644
index 2f5638c..0000000
--- a/server.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package main
-
-import (
- "encoding/json"
- "fmt"
- "gf-lt/config"
- "net/http"
- "time"
-)
-
-type Server struct {
- // nolint
- config config.Config
-}
-
-func (srv *Server) ListenToRequests(port string) {
- // h := srv.actions
- mux := http.NewServeMux()
- server := &http.Server{
- Addr: "localhost:" + port,
- Handler: mux,
- ReadTimeout: time.Second * 5,
- WriteTimeout: time.Second * 5,
- }
- mux.HandleFunc("GET /ping", pingHandler)
- mux.HandleFunc("GET /model", modelHandler)
- mux.HandleFunc("POST /completion", completionHandler)
- fmt.Println("Listening", "addr", server.Addr)
- if err := server.ListenAndServe(); err != nil {
- panic(err)
- }
-}
-
-// create server
-// listen to the completion endpoint handler
-func pingHandler(w http.ResponseWriter, req *http.Request) {
- if _, err := w.Write([]byte("pong")); err != nil {
- logger.Error("server ping", "error", err)
- }
-}
-
-func completionHandler(w http.ResponseWriter, req *http.Request) {
- // post request
- body := req.Body
- // get body as io.reader
- // pass it to the /completion
- go sendMsgToLLM(body)
-out:
- for {
- select {
- case chunk := <-chunkChan:
- fmt.Print(chunk)
- if _, err := w.Write([]byte(chunk)); err != nil {
- logger.Warn("failed to write chunk", "value", chunk)
- continue
- }
- case <-streamDone:
- break out
- }
- }
-}
-
-func modelHandler(w http.ResponseWriter, req *http.Request) {
- llmModel := fetchLCPModelName()
- 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)
- }
-}