chore(tests): extend timeout for client
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
@@ -17,12 +17,15 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new LocalAgent client
|
// NewClient creates a new LocalAgent client
|
||||||
func NewClient(baseURL string, apiKey string) *Client {
|
func NewClient(baseURL string, apiKey string, timeout time.Duration) *Client {
|
||||||
|
if timeout == 0 {
|
||||||
|
timeout = time.Second * 30
|
||||||
|
}
|
||||||
return &Client{
|
return &Client{
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
APIKey: apiKey,
|
APIKey: apiKey,
|
||||||
HTTPClient: &http.Client{
|
HTTPClient: &http.Client{
|
||||||
Timeout: time.Second * 30,
|
Timeout: timeout,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import (
|
|||||||
// RequestBody represents the message request to the AI model
|
// RequestBody represents the message request to the AI model
|
||||||
type RequestBody struct {
|
type RequestBody struct {
|
||||||
Model string `json:"model"`
|
Model string `json:"model"`
|
||||||
Input string `json:"input"`
|
Input any `json:"input"`
|
||||||
InputMessages []InputMessage `json:"input_messages,omitempty"`
|
|
||||||
Temperature *float64 `json:"temperature,omitempty"`
|
Temperature *float64 `json:"temperature,omitempty"`
|
||||||
MaxTokens *int `json:"max_output_tokens,omitempty"`
|
MaxTokens *int `json:"max_output_tokens,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -18,7 +17,7 @@ type RequestBody struct {
|
|||||||
// InputMessage represents a user input message
|
// InputMessage represents a user input message
|
||||||
type InputMessage struct {
|
type InputMessage struct {
|
||||||
Role string `json:"role"`
|
Role string `json:"role"`
|
||||||
Content []ContentItem `json:"content"`
|
Content any `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentItem represents an item in a content array
|
// ContentItem represents an item in a content array
|
||||||
@@ -32,7 +31,7 @@ type ContentItem struct {
|
|||||||
type ResponseBody struct {
|
type ResponseBody struct {
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Error interface{} `json:"error,omitempty"`
|
Error any `json:"error,omitempty"`
|
||||||
Output []ResponseMessage `json:"output"`
|
Output []ResponseMessage `json:"output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +103,7 @@ func (c *Client) ChatAIResponse(agentName string, messages []InputMessage) (stri
|
|||||||
temperature := 0.7
|
temperature := 0.7
|
||||||
request := &RequestBody{
|
request := &RequestBody{
|
||||||
Model: agentName,
|
Model: agentName,
|
||||||
InputMessages: messages,
|
Input: messages,
|
||||||
Temperature: &temperature,
|
Temperature: &temperature,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package e2e_test
|
package e2e_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
localagent "github.com/mudler/LocalAgent/pkg/client"
|
localagent "github.com/mudler/LocalAgent/pkg/client"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
@@ -8,9 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Agent test", func() {
|
var _ = Describe("Agent test", func() {
|
||||||
Context("Creates an agent and it answer", func() {
|
Context("Creates an agent and it answers", func() {
|
||||||
It("create agent", func() {
|
It("create agent", func() {
|
||||||
client := localagent.NewClient(localagentURL, "")
|
client := localagent.NewClient(localagentURL, "", 5*time.Minute)
|
||||||
|
|
||||||
err := client.CreateAgent(&localagent.AgentConfig{
|
err := client.CreateAgent(&localagent.AgentConfig{
|
||||||
Name: "testagent",
|
Name: "testagent",
|
||||||
|
|||||||
Reference in New Issue
Block a user