feat(tools): add MultimodalResult.URLs for remote-hosted media
MultimodalResult only modeled local bytes written under SubdirHint
(Files). A tool whose media lives at a remote, already-hosted URL --
a generation API's result, for example -- had nowhere to put it.
MediaRef{Type, URL} and the new URLs field give it one, reusing the
existing envelope rather than forking a second convention for the
same concept.
This commit is contained in:
1 parent
f6d7d0dce2
commit
da8ffc0908
2 files changed
+40
No files matched your search
@@ -22,4 +22,19 @@ type MultimodalResult struct {
|
||||
// Files lists the full paths written under SubdirHint, in the order
|
||||
// the source content blocks appeared.
|
||||
Files []string `json:"files,omitempty"`
|
||||
// URLs lists media that lives at a remote, already-hosted URL rather
|
||||
// than local bytes -- a generation API's result, for example, which
|
||||
// has nowhere to go in Files: there is no SubdirHint to write it under
|
||||
// because nothing was downloaded.
|
||||
URLs []MediaRef `json:"urls,omitempty"`
|
||||
}
|
||||
|
||||
// MediaRef is one piece of remote-hosted media within a MultimodalResult.
|
||||
type MediaRef struct {
|
||||
// Type is "image", "video", "audio", or "document" -- the same
|
||||
// vocabulary gateway.MediaAttachment.Type uses, so a caller can build
|
||||
// one directly from this without translation.
|
||||
Type string `json:"type"`
|
||||
// URL is where the media is hosted.
|
||||
URL string `json:"url"`
|
||||
}
|
||||
@@ -47,4 +47,29 @@ func TestMultimodalResultOmitsEmptyOptionalFields(t *testing.T) {
|
||||
if _, ok := got["files"]; ok {
|
||||
t.Error("files should be omitted when empty")
|
||||
}
|
||||
if _, ok := got["urls"]; ok {
|
||||
t.Error("urls should be omitted when empty")
|
||||
}
|
||||
}
|
||||
|
||||
// A tool whose media lives at a remote URL (a generation API's hosted
|
||||
// result) rather than local bytes has nowhere to put it in Files, which is
|
||||
// always a path under SubdirHint. URLs is that case.
|
||||
func TestMultimodalResultURLsRoundTrip(t *testing.T) {
|
||||
r := MultimodalResult{
|
||||
IsMultimodal: true,
|
||||
Summary: "generated a video",
|
||||
URLs: []MediaRef{{Type: "video", URL: "https://example.com/v.mp4"}},
|
||||
}
|
||||
data, err := json.Marshal(r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got MultimodalResult
|
||||
if err := json.Unmarshal(data, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(got.URLs) != 1 || got.URLs[0].Type != "video" || got.URLs[0].URL != "https://example.com/v.mp4" {
|
||||
t.Errorf("URLs round-trip = %+v, want [{video https://example.com/v.mp4}]", got.URLs)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user