feat: finishing description agent infrastructure on backend

This commit is contained in:
2025-07-24 14:12:41 +01:00
parent 59bf884f5d
commit 37f966e508
3 changed files with 23 additions and 19 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"os"
@@ -101,7 +102,7 @@ func CreateAgentClient(options CreateAgentClientOptions) AgentClient {
return AgentClient{
apiKey: apiKey,
url: "https://api.openai.com/v1/chat/completions",
url: "https://router.requesty.ai/v1/chat/completions",
Do: func(req *http.Request) (*http.Response, error) {
client := &http.Client{}
return client.Do(req)
@@ -132,29 +133,29 @@ func (client AgentClient) getRequest(body []byte) (*http.Request, error) {
func (client AgentClient) Request(req *AgentRequestBody) (AgentResponse, error) {
jsonAiRequest, err := json.Marshal(req)
if err != nil {
return AgentResponse{}, err
return AgentResponse{}, fmt.Errorf("Could not format JSON", err)
}
httpRequest, err := client.getRequest(jsonAiRequest)
if err != nil {
return AgentResponse{}, err
return AgentResponse{}, fmt.Errorf("Could not get request", err)
}
resp, err := client.Do(httpRequest)
if err != nil {
return AgentResponse{}, err
return AgentResponse{}, fmt.Errorf("Could not send request", err)
}
response, err := io.ReadAll(resp.Body)
if err != nil {
return AgentResponse{}, err
return AgentResponse{}, fmt.Errorf("Could not read body", err)
}
agentResponse := AgentResponse{}
err = json.Unmarshal(response, &agentResponse)
if err != nil {
return AgentResponse{}, err
return AgentResponse{}, fmt.Errorf("Could not unmarshal response, response: %s", string(response), err)
}
if len(agentResponse.Choices) != 1 {
@@ -245,7 +246,7 @@ func (client *AgentClient) RunAgent(userId uuid.UUID, imageId uuid.UUID, imageNa
request := AgentRequestBody{
Tools: &tools,
ToolChoice: &toolChoice,
Model: "gpt-4.1-mini",
Model: "google/gemini-2.5-flash",
RandomSeed: &seed,
Temperature: 0.3,
EndToolCall: client.Options.EndToolCall,