]> git.giacomolli.uk - onechat/blobdiff - chain.go
Order model and chat declarations
[onechat] / chain.go
index c4a4302472d030ee944af5d7bc33f1e96ed7d9f1..59ce563524543d058a7809633451f09a867f02ef 100644 (file)
--- a/chain.go
+++ b/chain.go
@@ -32,6 +32,23 @@ type Chain struct {
        tools   *Toolbox
        request ModelRequest
        take    func() []Message
        tools   *Toolbox
        request ModelRequest
        take    func() []Message
+       images  *ImageStore
+}
+
+// ChainFunctionCall holds the fields of a function call output item.
+type ChainFunctionCall struct {
+       Type      string `json:"type"`
+       Name      string `json:"name"`
+       Arguments string `json:"arguments"`
+       CallID    string `json:"call_id"`
+}
+
+// ChainFunctionCallOutput is the input item with the result of a function
+// call.
+type ChainFunctionCallOutput struct {
+       Type   string `json:"type"`
+       CallID string `json:"call_id"`
+       Output any    `json:"output"`
 }
 
 // Run runs the chain from input, the input of its first request, and returns
 }
 
 // Run runs the chain from input, the input of its first request, and returns
@@ -122,28 +139,17 @@ func (c *Chain) handle(ctx context.Context, input []any, response ModelResponse)
 
        input = append(input, outputs...)
        for _, message := range c.take() {
 
        input = append(input, outputs...)
        for _, message := range c.take() {
-               input = append(input, modelUserMessage(message.Text))
+               item, err := imageUserMessage(c.images, message.Text)
+               if err != nil {
+                       return nil, "", fmt.Errorf("read queued images: %w", err)
+               }
+
+               input = append(input, item)
        }
 
        return input, "", nil
 }
 
        }
 
        return input, "", nil
 }
 
-// ChainFunctionCall holds the fields of a function call output item.
-type ChainFunctionCall struct {
-       Type      string `json:"type"`
-       Name      string `json:"name"`
-       Arguments string `json:"arguments"`
-       CallID    string `json:"call_id"`
-}
-
-// ChainFunctionCallOutput is the input item with the result of a function
-// call.
-type ChainFunctionCallOutput struct {
-       Type   string `json:"type"`
-       CallID string `json:"call_id"`
-       Output string `json:"output"`
-}
-
 // chainInputItem returns an output item as an input item for the next request.
 // The calls do not store their items, so the item goes back whole, without its
 // id.
 // chainInputItem returns an output item as an input item for the next request.
 // The calls do not store their items, so the item goes back whole, without its
 // id.