From d25f85ede4c0255b6ca5647ebf92d8a80448b14a Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Tue, 2 Jul 2024 12:14:18 -0700 Subject: [PATCH] on disk copy --- api/client.go | 9 +++++++++ api/types.go | 5 +++++ server/routes.go | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/api/client.go b/api/client.go index 5a445a251..7bf6012a2 100644 --- a/api/client.go +++ b/api/client.go @@ -404,3 +404,12 @@ func Authorization(ctx context.Context, request *http.Request) (string, error) { key, sig, _ := strings.Cut(token, ":") return fmt.Sprintf("%s:%s:%s", key, base64.StdEncoding.EncodeToString(data), sig), nil } + +// EnvConfig returns the environment configuration for the server. +func (c *Client) ServerConfig(ctx context.Context) (*ServerConfig, error) { + var config ServerConfig + if err := c.do(ctx, http.MethodGet, "/api/config", nil, &config); err != nil { + return nil, err + } + return &config, nil +} diff --git a/api/types.go b/api/types.go index 87844c67c..1eddb7695 100644 --- a/api/types.go +++ b/api/types.go @@ -359,6 +359,11 @@ type ModelDetails struct { QuantizationLevel string `json:"quantization_level"` } +// EnvConfig is the configuration for the environment. +type ServerConfig struct { + ModelDir string `json:"model_dir"` +} + func (m *Metrics) Summary() { if m.TotalDuration > 0 { fmt.Fprintf(os.Stderr, "total duration: %v\n", m.TotalDuration) diff --git a/server/routes.go b/server/routes.go index 2ad851edc..0011f106d 100644 --- a/server/routes.go +++ b/server/routes.go @@ -966,6 +966,7 @@ func (s *Server) GenerateRoutes() http.Handler { r.POST("/api/blobs/:digest", s.CreateBlobHandler) r.HEAD("/api/blobs/:digest", s.HeadBlobHandler) r.GET("/api/ps", s.ProcessHandler) + r.GET("/api/config", s.ConfigHandler) // Compatibility endpoints r.POST("/v1/chat/completions", openai.ChatMiddleware(), s.ChatHandler) @@ -1287,3 +1288,7 @@ func handleScheduleError(c *gin.Context, name string, err error) { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) } } + +func (s *Server) ConfigHandler(c *gin.Context) { + c.JSON(http.StatusOK, api.ServerConfig{ModelDir: envconfig.ModelsDir}) +}