Image input

This commit is contained in:
Ian Gulliver
2026-10-14 20:07:26 -07:00
parent bd8702ee87
commit 9e741ede32
27 changed files with 1044 additions and 122 deletions
+27 -2
View File
@@ -5,6 +5,7 @@ import (
"bytes"
"context"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
@@ -359,10 +360,34 @@ func (s *Session) ID() string {
return s.id
}
func (s *Session) Send(text string) error {
type Image struct {
MediaType string
Data []byte
}
func (s *Session) Send(text string, images ...Image) error {
var content any = text
if len(images) > 0 {
blocks := []map[string]any{}
for _, img := range images {
blocks = append(blocks, map[string]any{
"type": "image",
"source": map[string]any{
"type": "base64",
"media_type": img.MediaType,
"data": base64.StdEncoding.EncodeToString(img.Data),
},
})
}
if text != "" {
blocks = append(blocks, map[string]any{"type": "text", "text": text})
}
content = blocks
}
return s.write(map[string]any{
"type": "user",
"message": map[string]any{"role": "user", "content": text},
"message": map[string]any{"role": "user", "content": content},
"parent_tool_use_id": nil,
"session_id": s.ID(),
})