]> git.giacomolli.uk - onechat/blobdiff - compactor.go
Name and order the ChatGPT login code
[onechat] / compactor.go
index 6840fd41a2c53726acfc87a96b75db6857aa3a1c..48b855b743ae56cf6793e175be5543e8ef4ba1d5 100644 (file)
@@ -28,19 +28,20 @@ var ruler = strings.Repeat("-", nodeBytes)
 // because the view measures the real sizes. A call that fails before any line
 // fails the build, and the core tries it again at the next message.
 type Compactor struct {
 // because the view measures the real sizes. A call that fails before any line
 // fails the build, and the core tries it again at the next message.
 type Compactor struct {
-       client       *Client
+       client       *ModelClient
        model        ModelConfig
        model        ModelConfig
-       instructions string
-       tools        []Tool
+       instructions func() (string, error)
+       tools        []ModelTool
 }
 
 }
 
-// newCompactor returns the compactor of the agent name, which sends its calls
-// through client with model.
-func newCompactor(client *Client, name string, model ModelConfig) *Compactor {
+// newCompactor returns the compactor of an agent, which sends its calls through
+// client with model. instructions gives the system prompt of the agent at each
+// build, so a build sends the same prompt as the turns of that time.
+func newCompactor(client *ModelClient, instructions func() (string, error), model ModelConfig) *Compactor {
        return &Compactor{
                client:       client,
                model:        model,
        return &Compactor{
                client:       client,
                model:        model,
-               instructions: prompt(name),
+               instructions: instructions,
                tools:        agentTools(),
        }
 }
                tools:        agentTools(),
        }
 }
@@ -53,6 +54,11 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) {
                return "", err
        }
 
                return "", err
        }
 
+       instructions, err := c.instructions()
+       if err != nil {
+               return "", fmt.Errorf("compact node (%d, %d): %w", task.Level, task.Index, err)
+       }
+
        var lines []string
        note := ""
        for len(lines) < compactionTries {
        var lines []string
        note := ""
        for len(lines) < compactionTries {
@@ -61,13 +67,14 @@ func (c *Compactor) Summarize(ctx context.Context, task Task) (string, error) {
                        parts = append(parts, note)
                }
 
                        parts = append(parts, note)
                }
 
-               var response Response
-               response, err = c.client.Create(ctx, Request{
+               var response ModelResponse
+               response, err = c.client.Create(ctx, ModelRequest{
                        Model:        c.model.Model,
                        Effort:       c.model.Effort,
                        Model:        c.model.Model,
                        Effort:       c.model.Effort,
-                       Instructions: c.instructions,
+                       Instructions: instructions,
                        Tools:        c.tools,
                        Tools:        c.tools,
-                       Input:        []any{userMessage(parts...)},
+                       Input:        []any{modelUserMessage(parts...)},
+                       Node:         &nodeKey{task.Level, task.Index},
                })
                if err != nil {
                        break
                })
                if err != nil {
                        break
@@ -129,7 +136,7 @@ func tooLong(line string) string {
        return fmt.Sprintf(`Too long: your last line for this <input> was %d bytes,
 over the %d-byte limit. Write the whole line again, cutting just
 enough of the least valuable items to fit before this cut:
        return fmt.Sprintf(`Too long: your last line for this <input> was %d bytes,
 over the %d-byte limit. Write the whole line again, cutting just
 enough of the least valuable items to fit before this cut:
-%s| ← LIMIT`, len(line), nodeBytes, cutLine(line))
+%s| <- LIMIT`, len(line), nodeBytes, cutLine(line))
 }
 
 // cutLine returns the first nodeBytes bytes of line, without a part of a
 }
 
 // cutLine returns the first nodeBytes bytes of line, without a part of a