summaryrefslogtreecommitdiff
path: root/bot.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2025-12-18 15:22:03 +0300
committerGrail Finder <wohilas@gmail.com>2025-12-18 15:22:03 +0300
commit5f852418d8d12868df83a9591b15e0846971fff9 (patch)
tree9fbc62821ec4a6796194c994dc6118d3e70ce362 /bot.go
parent8cdec5e54455c3dfb74c2e8016f17f806f86fa54 (diff)
Chore: request cleanup
Diffstat (limited to 'bot.go')
-rw-r--r--bot.go62
1 files changed, 11 insertions, 51 deletions
diff --git a/bot.go b/bot.go
index d6418ff..f2683bb 100644
--- a/bot.go
+++ b/bot.go
@@ -330,59 +330,19 @@ func fetchLCPModels() ([]string, error) {
// sendMsgToLLM expects streaming resp
func sendMsgToLLM(body io.Reader) {
choseChunkParser()
- var req *http.Request
- var err error
- // Capture and log the request body for debugging
- if _, ok := body.(*io.LimitedReader); ok {
- // If it's a LimitedReader, we need to handle it differently
- logger.Debug("request body type is LimitedReader", "parser", chunkParser, "link", cfg.CurrentAPI)
- req, err = http.NewRequest("POST", cfg.CurrentAPI, body)
- if err != nil {
- logger.Error("newreq error", "error", err)
- if err := notifyUser("error", "apicall failed:"+err.Error()); err != nil {
- logger.Error("failed to notify", "error", err)
- }
- streamDone <- true
- return
- }
- req.Header.Add("Accept", "application/json")
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+chunkParser.GetToken())
- req.Header.Set("Accept-Encoding", "gzip")
- } else {
- // For other reader types, capture and log the body content
- bodyBytes, err := io.ReadAll(body)
- if err != nil {
- logger.Error("failed to read request body for logging", "error", err)
- // Create request with original body if reading fails
- req, err = http.NewRequest("POST", cfg.CurrentAPI, bytes.NewReader(bodyBytes))
- if err != nil {
- logger.Error("newreq error", "error", err)
- if err := notifyUser("error", "apicall failed:"+err.Error()); err != nil {
- logger.Error("failed to notify", "error", err)
- }
- streamDone <- true
- return
- }
- } else {
- // Log the request body for debugging
- logger.Debug("sending request to API", "api", cfg.CurrentAPI, "body", string(bodyBytes))
- // Create request with the captured body
- req, err = http.NewRequest("POST", cfg.CurrentAPI, bytes.NewReader(bodyBytes))
- if err != nil {
- logger.Error("newreq error", "error", err)
- if err := notifyUser("error", "apicall failed:"+err.Error()); err != nil {
- logger.Error("failed to notify", "error", err)
- }
- streamDone <- true
- return
- }
+ req, err := http.NewRequest("POST", cfg.CurrentAPI, body)
+ if err != nil {
+ logger.Error("newreq error", "error", err)
+ if err := notifyUser("error", "apicall failed:"+err.Error()); err != nil {
+ logger.Error("failed to notify", "error", err)
}
- req.Header.Add("Accept", "application/json")
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("Authorization", "Bearer "+chunkParser.GetToken())
- req.Header.Set("Accept-Encoding", "gzip")
+ streamDone <- true
+ return
}
+ req.Header.Add("Accept", "application/json")
+ req.Header.Add("Content-Type", "application/json")
+ req.Header.Add("Authorization", "Bearer "+chunkParser.GetToken())
+ req.Header.Set("Accept-Encoding", "gzip")
// nolint
resp, err := httpClient.Do(req)
if err != nil {