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} }
|
if cfg.Stream { p["stream_options"] = map[string]any{"include_usage": true} }
|
||||||
for k, v := range cfg.Raw {
|
for k, v := range cfg.Raw {
|
||||||
switch k {
|
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
|
continue
|
||||||
default:
|
default:
|
||||||
var jv any
|
var jv any
|
||||||
@@ -1409,9 +1409,10 @@ func main() {
|
|||||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
var usg Usage
|
var usg Usage
|
||||||
msgs, usg, err = AL(sigCtx, &cfg, msgs, sp, 0)
|
msgs, usg, err = AL(sigCtx, &cfg, msgs, sp, 0)
|
||||||
|
interrupted := sigCtx.Err() != nil
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
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))
|
fmt.Println(c("\n[interrupted]", 33))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
||||||
@@ -1481,9 +1482,10 @@ func main() {
|
|||||||
fmt.Println(c("[compacting conversation...]", 33))
|
fmt.Println(c("[compacting conversation...]", 33))
|
||||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
||||||
|
interrupted := sigCtx.Err() != nil
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
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))
|
fmt.Println(c("\n[interrupted]", 33))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
|
fmt.Println(c("[compact failed: "+err.Error()+"]", 31))
|
||||||
@@ -1542,9 +1544,10 @@ func main() {
|
|||||||
turnMsgs = append(turnMsgs, Message{Role: "user", Content: strp(u)})
|
turnMsgs = append(turnMsgs, Message{Role: "user", Content: strp(u)})
|
||||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
resMsgs, usg, err := AL(sigCtx, &cfg, turnMsgs, sp, 0)
|
resMsgs, usg, err := AL(sigCtx, &cfg, turnMsgs, sp, 0)
|
||||||
|
interrupted := sigCtx.Err() != nil
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
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))
|
fmt.Println(c("\n[interrupted]", 33))
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
fmt.Println(c("[error: "+err.Error()+"]", 31))
|
||||||
@@ -1564,9 +1567,14 @@ func main() {
|
|||||||
fmt.Println(c("[compacting conversation...]", 33))
|
fmt.Println(c("[compacting conversation...]", 33))
|
||||||
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
sigCtx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
|
||||||
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
nm, sm, err := compact(sigCtx, &cfg, msgs)
|
||||||
|
interrupted := sigCtx.Err() != nil
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
msgs = nm
|
msgs = nm
|
||||||
autosave(msgs)
|
autosave(msgs)
|
||||||
|
|||||||
Reference in New Issue
Block a user