feat: config, OpenAI-compatible streaming provider and safe tools
This commit is contained in:
commit
c1c7b0e005
13 changed files with 1031 additions and 0 deletions
41
internal/tools/timetool.go
Normal file
41
internal/tools/timetool.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/crypto/openclaw/internal/llm"
|
||||
)
|
||||
|
||||
// TimeNow returns the current time, optionally in an IANA time zone.
|
||||
type TimeNow struct{ Now func() time.Time }
|
||||
|
||||
func (TimeNow) Spec() llm.ToolSpec {
|
||||
return llm.ToolSpec{
|
||||
Name: "time_now",
|
||||
Description: "Get the current date and time. Optional IANA time zone, e.g. Europe/Berlin.",
|
||||
Parameters: obj(map[string]any{"timezone": map[string]any{"type": "string"}}),
|
||||
}
|
||||
}
|
||||
|
||||
func (t TimeNow) Call(_ context.Context, raw json.RawMessage) (string, error) {
|
||||
var a struct{ Timezone string `json:"timezone"` }
|
||||
if err := json.Unmarshal(raw, &a); err != nil {
|
||||
return "", err
|
||||
}
|
||||
now := time.Now
|
||||
if t.Now != nil {
|
||||
now = t.Now
|
||||
}
|
||||
n := now()
|
||||
if a.Timezone != "" {
|
||||
loc, err := time.LoadLocation(a.Timezone)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unknown timezone %q", a.Timezone)
|
||||
}
|
||||
n = n.In(loc)
|
||||
}
|
||||
return n.Format("2006-01-02T15:04:05 MST (Monday)"), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue