diff options
| author | Grail Finder <wohilas@gmail.com> | 2025-12-18 14:39:06 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2025-12-18 14:39:06 +0300 |
| commit | 8cdec5e54455c3dfb74c2e8016f17f806f86fa54 (patch) | |
| tree | 350b3ba67110de1a32b8d85528fd56298a2a32ab /agent | |
| parent | a06cfd995f05782854844e51a71a656f70274f64 (diff) | |
Feat: http request for agent
Diffstat (limited to 'agent')
| -rw-r--r-- | agent/request.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/agent/request.go b/agent/request.go new file mode 100644 index 0000000..3b8d083 --- /dev/null +++ b/agent/request.go @@ -0,0 +1,42 @@ +package agent + +import ( + "gf-lt/config" + "io" + "log/slog" + "net/http" +) + +var httpClient = &http.Client{} + +type AgentClient struct { + cfg *config.Config + getToken func() string + log slog.Logger +} + +func NewAgentClient(cfg *config.Config, log slog.Logger, gt func() string) *AgentClient { + return &AgentClient{ + cfg: cfg, + getToken: gt, + log: log, + } +} + +func (ag *AgentClient) LLMRequest(body io.Reader) ([]byte, error) { + req, err := http.NewRequest("POST", ag.cfg.CurrentAPI, body) + if err != nil { + return nil, err + } + req.Header.Add("Accept", "application/json") + req.Header.Add("Content-Type", "application/json") + req.Header.Add("Authorization", "Bearer "+ag.getToken()) + req.Header.Set("Accept-Encoding", "gzip") + resp, err := httpClient.Do(req) + if err != nil { + ag.log.Error("llamacpp api", "error", err) + return nil, err + } + defer resp.Body.Close() + return io.ReadAll(resp.Body) +} |
