From 6efa8b61ecfedb4a66650ad73e1292c3f4f29830 Mon Sep 17 00:00:00 2001 From: Vaibhav Singh <0vaibhavsingh0@gmail.com> Date: Tue, 3 Sep 2024 08:41:46 -0300 Subject: [PATCH] chore: remove html templates --- ReadMe.md | 12 +- app/internal/config/config.go | 52 +++--- app/internal/server/server.go | 1 - app/templates/chat.html | 305 ------------------------------- app/templates/chat_messages.html | 25 --- app/templates/error.html | 69 ------- app/templates/index.html | 125 ------------- 7 files changed, 29 insertions(+), 560 deletions(-) delete mode 100644 app/templates/chat.html delete mode 100644 app/templates/chat_messages.html delete mode 100644 app/templates/error.html delete mode 100644 app/templates/index.html diff --git a/ReadMe.md b/ReadMe.md index fdfcc3d..239a616 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -58,7 +58,6 @@ Nous consists of two main services: │ ├── internal │ ├── nous.db │ ├── static -│ └── templates ├── docker-compose.yml ├── docs │ ├── crag-architecture.png @@ -192,7 +191,6 @@ The Golang server configuration manages various aspects of the web server, inclu ```go type Config struct { StaticPath string - TemplatesPath string ServerAddr string DatabasePath string LLMBaseURL string @@ -203,7 +201,6 @@ type Config struct { #### Configuration Options - `StaticPath`: Path to static files (default: `"../static"` relative to the executable) -- `TemplatesPath`: Path to HTML templates (default: `"../templates/*"` relative to the executable) - `ServerAddr`: Address and port for the HTTP server (default: `:8080`) - `DatabasePath`: Path to the SQLite database file (default: `"./nous.db"`) - `LLMBaseURL`: URL of the LLM service (default: `"http://localhost:5000"`) @@ -214,11 +211,10 @@ type Config struct { You can customize these settings using environment variables: 1. `STATIC_PATH`: Set the path to static files -2. `TEMPLATES_PATH`: Set the path to HTML templates -3. `SERVER_ADDR`: Set the server address and port -4. `DATABASE_PATH`: Set the path to the SQLite database file -5. `LLM_BASE_URL`: Set the URL of the LLM service -6. `REDIS_ADDR`: Set the address of the Redis server +2. `SERVER_ADDR`: Set the server address and port +3. `DATABASE_PATH`: Set the path to the SQLite database file +4. `LLM_BASE_URL`: Set the URL of the LLM service +5. `REDIS_ADDR`: Set the address of the Redis server Example: ```bash diff --git a/app/internal/config/config.go b/app/internal/config/config.go index 32a215a..92dbcd9 100644 --- a/app/internal/config/config.go +++ b/app/internal/config/config.go @@ -7,45 +7,43 @@ import ( // Config holds all configuration for the application type Config struct { - StaticPath string - TemplatesPath string - ServerAddr string - DatabasePath string - LLMBaseURL string - RedisAddr string + StaticPath string + ServerAddr string + DatabasePath string + LLMBaseURL string + RedisAddr string } // Load returns a new Config struct populated with values from environment variables or defaults func Load() (*Config, error) { - exPath, err := getExecutablePath() - if err != nil { - return nil, err - } + exPath, err := getExecutablePath() + if err != nil { + return nil, err + } - return &Config{ - StaticPath: getEnv("STATIC_PATH", filepath.Join(exPath, "..", "static")), - TemplatesPath: getEnv("TEMPLATES_PATH", filepath.Join(exPath, "..", "templates", "*")), - ServerAddr: getEnv("SERVER_ADDR", ":8080"), - DatabasePath: getEnv("DATABASE_PATH", "./nous.db"), - LLMBaseURL: getEnv("LLM_BASE_URL", "http://localhost:5000"), - RedisAddr: getEnv("REDIS_ADDR", "localhost:6379"), - }, nil + return &Config{ + StaticPath: getEnv("STATIC_PATH", filepath.Join(exPath, "..", "static")), + ServerAddr: getEnv("SERVER_ADDR", ":8080"), + DatabasePath: getEnv("DATABASE_PATH", "./nous.db"), + LLMBaseURL: getEnv("LLM_BASE_URL", "http://localhost:5000"), + RedisAddr: getEnv("REDIS_ADDR", "localhost:6379"), + }, nil } // getExecutablePath returns the directory of the current executable func getExecutablePath() (string, error) { - ex, err := os.Executable() - if err != nil { - return "", err - } - return filepath.Dir(ex), nil + ex, err := os.Executable() + if err != nil { + return "", err + } + return filepath.Dir(ex), nil } // getEnv retrieves the value of the environment variable named by the key // If the variable is not present, it returns the fallback value func getEnv(key, fallback string) string { - if value, exists := os.LookupEnv(key); exists { - return value - } - return fallback + if value, exists := os.LookupEnv(key); exists { + return value + } + return fallback } diff --git a/app/internal/server/server.go b/app/internal/server/server.go index 8cb1479..fa84c76 100644 --- a/app/internal/server/server.go +++ b/app/internal/server/server.go @@ -42,7 +42,6 @@ func (s *DefaultServer) SetupRoutes() { s.router.Use(s.globalErrorHandler()) s.router.Static("/static", s.config.StaticPath) - s.router.LoadHTMLGlob(s.config.TemplatesPath) chatStore := store.NewChatStore(s.db.GetDB()) chatAPIHandler := handlers.NewChatAPIHandler(chatStore, s.llmClient) diff --git a/app/templates/chat.html b/app/templates/chat.html deleted file mode 100644 index b6992f6..0000000 --- a/app/templates/chat.html +++ /dev/null @@ -1,305 +0,0 @@ - - - - - - Nous - Chat - - - - - - -
-
-

- Nous Chat -

-
-
- -
-
- {{range .chats}} {{if eq .Type "user"}} -
-
-

{{.Text}}

-
-
- {{else}} -
-
-

{{.Text}}

- -
-
- {{end}} {{end}} -
- - - -
-
- - - -
-
-
- - - - - - diff --git a/app/templates/chat_messages.html b/app/templates/chat_messages.html deleted file mode 100644 index 53049ea..0000000 --- a/app/templates/chat_messages.html +++ /dev/null @@ -1,25 +0,0 @@ -{{if .userMessage}} - -
-
-

{{.userMessage}}

-
-
-{{end}} - -{{if .botResponse}} - -
-
-

{{.botResponse}}

- -
-
-{{end}} \ No newline at end of file diff --git a/app/templates/error.html b/app/templates/error.html deleted file mode 100644 index bbb3f1d..0000000 --- a/app/templates/error.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - Nous - Error - - - - - - -
-
-

- Nous Chat -

-
-
- -
-
- - - -

Oops! An error occurred

-

{{.error}}

- - Return to Home - -
-
- - - - - - \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html deleted file mode 100644 index 3c4d55c..0000000 --- a/app/templates/index.html +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - Nous - Personal Knowledge Assistant - - - - - -
-
-

- Nous -

-

- Your Personal Knowledge Assistant -

-
-
-
-
-
- - -
-
-
- - - - - -