Chore: server should live in separate branch
until a usecase for it is found
This commit is contained in:
9
Makefile
9
Makefile
@@ -1,5 +1,4 @@
|
|||||||
.PHONY: setconfig run lint setup-whisper build-whisper download-whisper-model docker-up docker-down docker-logs noextra-run noextra-server
|
.PHONY: setconfig run lint setup-whisper build-whisper download-whisper-model docker-up docker-down docker-logs noextra-run
|
||||||
|
|
||||||
|
|
||||||
run: setconfig
|
run: setconfig
|
||||||
go build -tags extra -o gf-lt && ./gf-lt
|
go build -tags extra -o gf-lt && ./gf-lt
|
||||||
@@ -10,15 +9,9 @@ build-debug:
|
|||||||
debug: build-debug
|
debug: build-debug
|
||||||
dlv exec --headless --accept-multiclient --listen=:2345 ./gf-lt
|
dlv exec --headless --accept-multiclient --listen=:2345 ./gf-lt
|
||||||
|
|
||||||
server: setconfig
|
|
||||||
go build -tags extra -o gf-lt && ./gf-lt -port 3333
|
|
||||||
|
|
||||||
noextra-run: setconfig
|
noextra-run: setconfig
|
||||||
go build -tags '!extra' -o gf-lt && ./gf-lt
|
go build -tags '!extra' -o gf-lt && ./gf-lt
|
||||||
|
|
||||||
noextra-server: setconfig
|
|
||||||
go build -tags '!extra' -o gf-lt && ./gf-lt -port 3333
|
|
||||||
|
|
||||||
setconfig:
|
setconfig:
|
||||||
find config.toml &>/dev/null || cp config.example.toml config.toml
|
find config.toml &>/dev/null || cp config.example.toml config.toml
|
||||||
|
|
||||||
|
|||||||
27
bot.go
27
bot.go
@@ -17,7 +17,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -343,32 +342,6 @@ func warmUpModel() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchLCPModelName() *models.LCPModels {
|
|
||||||
//nolint
|
|
||||||
resp, err := httpClient.Get(cfg.FetchModelNameAPI)
|
|
||||||
if err != nil {
|
|
||||||
chatBody.Model = "disconnected"
|
|
||||||
logger.Warn("failed to get model", "link", cfg.FetchModelNameAPI, "error", err)
|
|
||||||
if err := notifyUser("error", "request failed "+cfg.FetchModelNameAPI); err != nil {
|
|
||||||
logger.Debug("failed to notify user", "error", err, "fn", "fetchLCPModelName")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
llmModel := models.LCPModels{}
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&llmModel); err != nil {
|
|
||||||
logger.Warn("failed to decode resp", "link", cfg.FetchModelNameAPI, "error", err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
chatBody.Model = "disconnected"
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
chatBody.Model = path.Base(llmModel.Data[0].ID)
|
|
||||||
cfg.CurrentModel = chatBody.Model
|
|
||||||
return &llmModel
|
|
||||||
}
|
|
||||||
|
|
||||||
// nolint
|
// nolint
|
||||||
func fetchDSBalance() *models.DSBalance {
|
func fetchDSBalance() *models.DSBalance {
|
||||||
url := "https://api.deepseek.com/user/balance"
|
url := "https://api.deepseek.com/user/balance"
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -1,9 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,13 +17,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
apiPort := flag.Int("port", 0, "port to host api")
|
|
||||||
flag.Parse()
|
|
||||||
if apiPort != nil && *apiPort > 3000 {
|
|
||||||
srv := Server{}
|
|
||||||
srv.ListenToRequests(strconv.Itoa(*apiPort))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
pages.AddPage("main", flex, true, true)
|
pages.AddPage("main", flex, true, true)
|
||||||
if err := app.SetRoot(pages,
|
if err := app.SetRoot(pages,
|
||||||
true).EnableMouse(cfg.EnableMouse).EnablePaste(true).Run(); err != nil {
|
true).EnableMouse(cfg.EnableMouse).EnablePaste(true).Run(); err != nil {
|
||||||
|
|||||||
74
server.go
74
server.go
@@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user