mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-28 06:25:00 +00:00
feat(api): allow to pass videos to backends (#3601)
This prepares the API to receive videos as well for video understanding. It works similarly to images, where the request should be in the form: { "type": "video_url", "video_url": { "url": "url or base64 data" } } Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
c6a819e92f
commit
fbb9facda4
8 changed files with 47 additions and 27 deletions
|
@ -13,14 +13,8 @@ var base64DownloadClient http.Client = http.Client{
|
|||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
// this function check if the string is an URL, if it's an URL downloads the image in memory
|
||||
// encodes it in base64 and returns the base64 string
|
||||
|
||||
// This may look weird down in pkg/utils while it is currently only used in core/config
|
||||
//
|
||||
// but I believe it may be useful for MQTT as well in the near future, so I'm
|
||||
// extracting it while I'm thinking of it.
|
||||
func GetImageURLAsBase64(s string) (string, error) {
|
||||
// GetContentURIAsBase64 checks if the string is an URL, if it's an URL downloads the content in memory encodes it in base64 and returns the base64 string, otherwise returns the string by stripping base64 data headers
|
||||
func GetContentURIAsBase64(s string) (string, error) {
|
||||
if strings.HasPrefix(s, "http") {
|
||||
// download the image
|
||||
resp, err := base64DownloadClient.Get(s)
|
||||
|
|
|
@ -10,20 +10,20 @@ var _ = Describe("utils/base64 tests", func() {
|
|||
It("GetImageURLAsBase64 can strip jpeg data url prefixes", func() {
|
||||
// This one doesn't actually _care_ that it's base64, so feed "bad" data in this test in order to catch a change in that behavior for informational purposes.
|
||||
input := "data:image/jpeg;base64,FOO"
|
||||
b64, err := GetImageURLAsBase64(input)
|
||||
b64, err := GetContentURIAsBase64(input)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(b64).To(Equal("FOO"))
|
||||
})
|
||||
It("GetImageURLAsBase64 can strip png data url prefixes", func() {
|
||||
// This one doesn't actually _care_ that it's base64, so feed "bad" data in this test in order to catch a change in that behavior for informational purposes.
|
||||
input := "data:image/png;base64,BAR"
|
||||
b64, err := GetImageURLAsBase64(input)
|
||||
b64, err := GetContentURIAsBase64(input)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(b64).To(Equal("BAR"))
|
||||
})
|
||||
It("GetImageURLAsBase64 returns an error for bogus data", func() {
|
||||
input := "FOO"
|
||||
b64, err := GetImageURLAsBase64(input)
|
||||
b64, err := GetContentURIAsBase64(input)
|
||||
Expect(b64).To(Equal(""))
|
||||
Expect(err).ToNot(BeNil())
|
||||
Expect(err).To(MatchError("not valid string"))
|
||||
|
@ -31,7 +31,7 @@ var _ = Describe("utils/base64 tests", func() {
|
|||
It("GetImageURLAsBase64 can actually download images and calculates something", func() {
|
||||
// This test doesn't actually _check_ the results at this time, which is bad, but there wasn't a test at all before...
|
||||
input := "https://upload.wikimedia.org/wikipedia/en/2/29/Wargames.jpg"
|
||||
b64, err := GetImageURLAsBase64(input)
|
||||
b64, err := GetContentURIAsBase64(input)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(b64).ToNot(BeNil())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue