]> git.giacomolli.uk - onechat/blobdiff - model.go
Name timeouts for the operations they limit
[onechat] / model.go
index 507fbb1a260265dbdd0f61c817ba33aef07d9cfa..6ddd3008cca12c96577ccc5a9a8b6ca913ebfe7e 100644 (file)
--- a/model.go
+++ b/model.go
@@ -73,22 +73,22 @@ func newModelClient(url string, auth ModelAuthorizer, cacheKey, usagePath string
 
 // modelUserMessage returns a user input item with one text part for each text.
 func modelUserMessage(texts ...string) any {
-       type part struct {
-               Type string `json:"type"`
-               Text string `json:"text"`
-       }
-
-       content := make([]part, len(texts))
+       content := make([]ModelInputPart, len(texts))
        for n, text := range texts {
-               content[n] = part{
+               content[n] = ModelInputPart{
                        Type: "input_text",
                        Text: text,
                }
        }
 
+       return modelUserParts(content)
+}
+
+// modelUserParts keeps text and image parts in one user message.
+func modelUserParts(content []ModelInputPart) any {
        return struct {
-               Role    string `json:"role"`
-               Content []part `json:"content"`
+               Role    string           `json:"role"`
+               Content []ModelInputPart `json:"content"`
        }{
                Role:    "user",
                Content: content,
@@ -321,6 +321,13 @@ type ModelOutputItem struct {
        } `json:"content"`
 }
 
+// ModelInputPart is a text or image part in a user message or tool result.
+type ModelInputPart struct {
+       Type     string `json:"type"`
+       Text     string `json:"text,omitempty"`
+       ImageURL string `json:"image_url,omitempty"`
+}
+
 // ModelRequest is one model call. Input holds the input items in order, such as
 // modelUserMessage values or output items of an earlier response. Node names
 // the node that a compaction builds, or is nil. Turn names the request of a