try to fixup tests, enable e2e (#53)

* try to fixup tests, enable e2e

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Generate JSON character data with tools

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Rework generation of character

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* Simplify text

Signed-off-by: mudler <mudler@localai.io>

* Relax some test constraints

Signed-off-by: mudler <mudler@localai.io>

* Fixups

* Properly fit schema generation

* Swap default model

* ci fixups

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Signed-off-by: mudler <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-03-18 23:28:02 +01:00
committed by GitHub
parent 31b5849d02
commit e32a569796
16 changed files with 733 additions and 144 deletions

65
pkg/client/chat.go Normal file
View File

@@ -0,0 +1,65 @@
package localagent
import (
"fmt"
"net/http"
"strings"
)
// Message represents a chat message
type Message struct {
Message string `json:"message"`
}
// ChatResponse represents a response from the agent
type ChatResponse struct {
Response string `json:"response"`
}
// SendMessage sends a message to an agent
func (c *Client) SendMessage(agentName, message string) error {
path := fmt.Sprintf("/chat/%s", agentName)
msg := Message{
Message: message,
}
resp, err := c.doRequest(http.MethodPost, path, msg)
if err != nil {
return err
}
defer resp.Body.Close()
// The response is HTML, so it's not easily parseable in this context
return nil
}
// Notify sends a notification to an agent
func (c *Client) Notify(agentName, message string) error {
path := fmt.Sprintf("/notify/%s", agentName)
// URL encoded form data
form := strings.NewReader(fmt.Sprintf("message=%s", message))
req, err := http.NewRequest(http.MethodGet, c.BaseURL+path, form)
if err != nil {
return fmt.Errorf("error creating request: %w", err)
}
if c.APIKey != "" {
req.Header.Set("Authorization", "Bearer "+c.APIKey)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := c.HTTPClient.Do(req)
if err != nil {
return fmt.Errorf("error making request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return fmt.Errorf("api error (status %d)", resp.StatusCode)
}
return nil
}