Replace all fmt.Errorf and errors.New in production code with
coreerr.E("caller.Method", "message", err) from go-log. Replace
all os.ReadFile/os.WriteFile/os.MkdirAll/os.Remove with coreio.Local
equivalents from go-io. Test files are intentionally untouched.
Co-Authored-By: Virgil <virgil@lethean.io>
90 lines
2.6 KiB
Go
90 lines
2.6 KiB
Go
package loop
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
|
|
coreerr "forge.lthn.ai/core/go-log"
|
|
)
|
|
|
|
var eaasClient = &http.Client{Timeout: 30 * time.Second}
|
|
|
|
// EaaSTools returns the three EaaS tool wrappers: score, imprint, and atlas similar.
|
|
func EaaSTools(baseURL string) []Tool {
|
|
return []Tool{
|
|
{
|
|
Name: "eaas_score",
|
|
Description: "Score text for AI-generated content, sycophancy, and compliance markers. Returns verdict, LEK score, heuristic breakdown, and detected flags.",
|
|
Parameters: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"text": map[string]any{"type": "string", "description": "Text to analyse"},
|
|
},
|
|
"required": []any{"text"},
|
|
},
|
|
Handler: eaasPostHandler(baseURL, "/v1/score/content"),
|
|
},
|
|
{
|
|
Name: "eaas_imprint",
|
|
Description: "Analyse the linguistic imprint of text. Returns stylistic fingerprint metrics.",
|
|
Parameters: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"text": map[string]any{"type": "string", "description": "Text to analyse"},
|
|
},
|
|
"required": []any{"text"},
|
|
},
|
|
Handler: eaasPostHandler(baseURL, "/v1/score/imprint"),
|
|
},
|
|
{
|
|
Name: "eaas_similar",
|
|
Description: "Find similar previously scored content via atlas vector search.",
|
|
Parameters: map[string]any{
|
|
"type": "object",
|
|
"properties": map[string]any{
|
|
"id": map[string]any{"type": "string", "description": "Scoring ID to search from"},
|
|
"limit": map[string]any{"type": "integer", "description": "Max results (default 5)"},
|
|
},
|
|
"required": []any{"id"},
|
|
},
|
|
Handler: eaasPostHandler(baseURL, "/v1/atlas/similar"),
|
|
},
|
|
}
|
|
}
|
|
|
|
func eaasPostHandler(baseURL, path string) func(context.Context, map[string]any) (string, error) {
|
|
return func(ctx context.Context, args map[string]any) (string, error) {
|
|
body, err := json.Marshal(args)
|
|
if err != nil {
|
|
return "", coreerr.E("eaas.handler", "marshal args", err)
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, "POST", baseURL+path, bytes.NewReader(body))
|
|
if err != nil {
|
|
return "", coreerr.E("eaas.handler", "create request", err)
|
|
}
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
resp, err := eaasClient.Do(req)
|
|
if err != nil {
|
|
return "", coreerr.E("eaas.handler", "eaas request", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
result, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return "", coreerr.E("eaas.handler", "read response", err)
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return "", coreerr.E("eaas.handler", fmt.Sprintf("eaas returned %d: %s", resp.StatusCode, string(result)), nil)
|
|
}
|
|
|
|
return string(result), nil
|
|
}
|
|
}
|