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
1962ce69
authored
Jul 23, 2024
by
Calcium-Ion
Committed by
GitHub
Jul 23, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #383 from Yan-Zero/main
fix: the base64 format image_url for gemini
parents
5083eaab
05da87ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
relay/channel/gemini/relay-gemini.go
+23
-7
No files found.
relay/channel/gemini/relay-gemini.go
View file @
1962ce69
...
@@ -83,13 +83,29 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
...
@@ -83,13 +83,29 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
if
imageNum
>
GeminiVisionMaxImageNum
{
if
imageNum
>
GeminiVisionMaxImageNum
{
continue
continue
}
}
mimeType
,
data
,
_
:=
service
.
GetImageFromUrl
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
// 判断是否是url
parts
=
append
(
parts
,
GeminiPart
{
if
strings
.
HasPrefix
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
,
"http"
)
{
InlineData
:
&
GeminiInlineData
{
// 是url,获取图片的类型和base64编码的数据
MimeType
:
mimeType
,
mimeType
,
data
,
_
:=
service
.
GetImageFromUrl
(
part
.
ImageUrl
.
(
dto
.
MessageImageUrl
)
.
Url
)
Data
:
data
,
parts
=
append
(
parts
,
GeminiPart
{
},
InlineData
:
&
GeminiInlineData
{
})
MimeType
:
mimeType
,
Data
:
data
,
},
})
}
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