summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/server.go b/server.go
index 2e25559..79aeb2f 100644
--- a/server.go
+++ b/server.go
@@ -1,14 +1,40 @@
package main
import (
+ "elefant/config"
+ "encoding/json"
"fmt"
"net/http"
+ "time"
)
+type Server struct {
+ 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)
+ server.ListenAndServe()
+}
+
// create server
// listen to the completion endpoint handler
+func pingHandler(w http.ResponseWriter, req *http.Request) {
+ w.Write([]byte("pong"))
+}
-func completion(w http.ResponseWriter, req *http.Request) {
+func completionHandler(w http.ResponseWriter, req *http.Request) {
// post request
body := req.Body
// get body as io.reader
@@ -19,9 +45,19 @@ out:
select {
case chunk := <-chunkChan:
fmt.Println(chunk)
+ w.Write([]byte(chunk))
case <-streamDone:
break out
}
}
return
}
+
+func modelHandler(w http.ResponseWriter, req *http.Request) {
+ llmModel := fetchModelName()
+ payload, err := json.Marshal(llmModel)
+ if err != nil {
+ // return err
+ }
+ w.Write(payload)
+}