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
05da87ec
authored
Jul 22, 2024
by
Yan Tau
Committed by
GitHub
Jul 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: the base64 format image_url for gemini
parent
2041a2e4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
relay/channel/gemini/relay-gemini.go
+16
-0
No files found.
relay/channel/gemini/relay-gemini.go
View file @
05da87ec
...
@@ -83,6 +83,9 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
...
@@ -83,6 +83,9 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
if
imageNum
>
GeminiVisionMaxImageNum
{
if
imageNum
>
GeminiVisionMaxImageNum
{
continue
continue
}
}
// 判断是否是url
if
strings
.
HasPrefix
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
,
"http"
)
{
// 是url,获取图片的类型和base64编码的数据
mimeType
,
data
,
_
:=
service
.
GetImageFromUrl
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
mimeType
,
data
,
_
:=
service
.
GetImageFromUrl
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
parts
=
append
(
parts
,
GeminiPart
{
parts
=
append
(
parts
,
GeminiPart
{
InlineData
:
&
GeminiInlineData
{
InlineData
:
&
GeminiInlineData
{
...
@@ -91,6 +94,19 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
...
@@ -91,6 +94,19 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
},
},
})
})
}
}
else
{
_
,
format
,
base64String
,
err
:=
service
.
DecodeBase64ImageData
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
if
err
!=
nil
{
return
nil
,
err
}
parts
=
append
(
parts
,
GeminiPart
{
InlineData
:
&
GeminiInlineData
{
MimeType
:
"image/"
+
format
,
Data
:
base64String
,
},
})
}
}
}
}
content
.
Parts
=
parts
content
.
Parts
=
parts
...
...
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