diff --git a/.github/chat.png b/.github/chat.png index b54685c..c8fc49e 100644 Binary files a/.github/chat.png and b/.github/chat.png differ diff --git a/chat.go b/chat.go index 4e2c71a..1af4191 100644 --- a/chat.go +++ b/chat.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "net/http" - "os" "github.com/revrost/go-openrouter" ) @@ -122,8 +121,7 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { request.Stream = true // DEBUG - b, _ := json.MarshalIndent(request, "", "\t") - os.WriteFile("debug.json", b, 0755) + dump(request) ctx := r.Context() @@ -165,6 +163,9 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { choice := chunk.Choices[0] + // DEBUG + debug(choice) + if choice.FinishReason == openrouter.FinishReasonContentFilter { response.Send(ErrorChunk(errors.New("stopped due to content_filter"))) diff --git a/debug.go b/debug.go new file mode 100644 index 0000000..fe206f5 --- /dev/null +++ b/debug.go @@ -0,0 +1,23 @@ +package main + +import ( + "encoding/json" + "os" +) + +func dump(v any) { + if !Debug { + return + } + + b, _ := json.MarshalIndent(v, "", "\t") + os.WriteFile("debug.json", b, 0644) +} + +func debug(v any) { + if !Debug { + return + } + + log.Debugf("%#v\n", v) +} diff --git a/env.go b/env.go index ebc8fb8..a2898eb 100644 --- a/env.go +++ b/env.go @@ -7,12 +7,21 @@ import ( "github.com/joho/godotenv" ) -var OpenRouterToken string +var ( + Debug bool + OpenRouterToken string +) func init() { log.MustPanic(godotenv.Load()) + Debug = os.Getenv("DEBUG") == "true" + if OpenRouterToken = os.Getenv("OPENROUTER_TOKEN"); OpenRouterToken == "" { log.Panic(errors.New("missing openrouter token")) } + + if Debug { + log.Debug("Debug mode enabled") + } } diff --git a/static/css/chat.css b/static/css/chat.css index f05e921..0505456 100644 --- a/static/css/chat.css +++ b/static/css/chat.css @@ -119,7 +119,7 @@ body { .message { position: relative; max-width: 700px; - min-width: 200px; + min-width: 280px; width: max-content; padding-top: 28px; background: #363a4f;