improved compacting algo and token visibility
This commit is contained in:
@@ -727,7 +727,7 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any)
|
||||
if cfg.Stream { p["stream_options"] = map[string]any{"include_usage": true} }
|
||||
for k, v := range cfg.Raw {
|
||||
switch k {
|
||||
case "endpoint", "api_key", "timeout", "shell_timeout", "max_al_iterations", "color", "context_window":
|
||||
case "endpoint", "model", "temperature", "stream", "api_key", "timeout", "shell_timeout", "max_al_iterations", "color", "context_window":
|
||||
continue
|
||||
default:
|
||||
var jv any
|
||||
@@ -1409,9 +1409,10 @@ func main() {
|
||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
var usg Usage
|
||||
msgs, usg, err = AL(sigCtx, &cfg, msgs, sp, 0)
|
||||
interrupted := sigCtx.Err() != nil
|
||||
cancel()
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil {
|
||||
if interrupted || errors.Is(err, context.Canceled) {
|
||||
fmt.Println(c("\n[interrupted]", 33))
|
||||
} else {
|
||||
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
||||
@@ -1481,9 +1482,10 @@ func main() {
|
||||
fmt.Println(c("[compacting conversation...]", 33))
|
||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
||||
interrupted := sigCtx.Err() != nil
|
||||
cancel()
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil {
|
||||
if interrupted || errors.Is(err, context.Canceled) {
|
||||
fmt.Println(c("\n[interrupted]", 33))
|
||||
} else {
|
||||
fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
|
||||
@@ -1542,9 +1544,10 @@ func main() {
|
||||
turnMsgs = append(turnMsgs, Message{Role: "user", Content: strp(u)})
|
||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
resMsgs, usg, err := AL(sigCtx, &cfg, turnMsgs, sp, 0)
|
||||
interrupted := sigCtx.Err() != nil
|
||||
cancel()
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || sigCtx.Err() != nil {
|
||||
if interrupted || errors.Is(err, context.Canceled) {
|
||||
fmt.Println(c("\n[interrupted]", 33))
|
||||
} else {
|
||||
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
||||
@@ -1564,9 +1567,14 @@ func main() {
|
||||
fmt.Println(c("[compacting conversation...]", 33))
|
||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
||||
interrupted := sigCtx.Err() != nil
|
||||
cancel()
|
||||
if err != nil {
|
||||
fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
|
||||
if interrupted || errors.Is(err, context.Canceled) {
|
||||
fmt.Println(c("\n[interrupted]", 33))
|
||||
} else {
|
||||
fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
|
||||
}
|
||||
} else {
|
||||
msgs = nm
|
||||
autosave(msgs)
|
||||
|
||||
Reference in New Issue
Block a user