Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1cdb03d8
authored
Dec 29, 2024
by
Yan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Gemini 其他文件类型的支持(Base64URL)
parent
9fc2f6a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
relay/channel/gemini/relay-gemini.go
+2
-2
service/image.go
+27
-1
No files found.
relay/channel/gemini/relay-gemini.go
View file @
1cdb03d8
...
...
@@ -204,13 +204,13 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatReque
},
})
}
else
{
_
,
format
,
base64String
,
err
:=
service
.
DecodeBase64Imag
eData
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
format
,
base64String
,
err
:=
service
.
DecodeBase64Fil
eData
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"decode base64 image data failed: %s"
,
err
.
Error
())
}
parts
=
append
(
parts
,
GeminiPart
{
InlineData
:
&
GeminiInlineData
{
MimeType
:
"image/"
+
format
,
MimeType
:
format
,
Data
:
base64String
,
},
})
...
...
service/image.go
View file @
1cdb03d8
...
...
@@ -5,11 +5,12 @@ import (
"encoding/base64"
"errors"
"fmt"
"golang.org/x/image/webp"
"image"
"io"
"one-api/common"
"strings"
"golang.org/x/image/webp"
)
func
DecodeBase64ImageData
(
base64String
string
)
(
image
.
Config
,
string
,
string
,
error
)
{
...
...
@@ -31,6 +32,31 @@ func DecodeBase64ImageData(base64String string) (image.Config, string, string, e
return
config
,
format
,
base64String
,
err
}
func
DecodeBase64FileData
(
base64String
string
)
(
string
,
string
,
error
)
{
var
mimeType
string
var
idx
int
idx
=
strings
.
Index
(
base64String
,
","
)
if
idx
==
-
1
{
_
,
file_type
,
base64
,
err
:=
DecodeBase64ImageData
(
base64String
)
return
"image/"
+
file_type
,
base64
,
err
}
mimeType
=
base64String
[
:
idx
]
base64String
=
base64String
[
idx
+
1
:
]
idx
=
strings
.
Index
(
mimeType
,
";"
)
if
idx
==
-
1
{
_
,
file_type
,
base64
,
err
:=
DecodeBase64ImageData
(
base64String
)
return
"image/"
+
file_type
,
base64
,
err
}
mimeType
=
mimeType
[
:
idx
]
idx
=
strings
.
Index
(
mimeType
,
":"
)
if
idx
==
-
1
{
_
,
file_type
,
base64
,
err
:=
DecodeBase64ImageData
(
base64String
)
return
"image/"
+
file_type
,
base64
,
err
}
mimeType
=
mimeType
[
idx
+
1
:
]
return
mimeType
,
base64String
,
nil
}
// GetImageFromUrl 获取图片的类型和base64编码的数据
func
GetImageFromUrl
(
url
string
)
(
mimeType
string
,
data
string
,
err
error
)
{
resp
,
err
:=
DoDownloadRequest
(
url
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment