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
ffef3311
authored
Feb 04, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(gemini): remove GeminiVisionMaxImageNum constant and related image count logic
parent
5878ea6b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
12 deletions
+0
-12
common/init.go
+0
-1
constant/env.go
+0
-1
relay/channel/gemini/relay-gemini.go
+0
-10
No files found.
common/init.go
View file @
ffef3311
...
@@ -137,7 +137,6 @@ func initConstantEnv() {
...
@@ -137,7 +137,6 @@ func initConstantEnv() {
constant
.
GetMediaTokenNotStream
=
GetEnvOrDefaultBool
(
"GET_MEDIA_TOKEN_NOT_STREAM"
,
false
)
constant
.
GetMediaTokenNotStream
=
GetEnvOrDefaultBool
(
"GET_MEDIA_TOKEN_NOT_STREAM"
,
false
)
constant
.
UpdateTask
=
GetEnvOrDefaultBool
(
"UPDATE_TASK"
,
true
)
constant
.
UpdateTask
=
GetEnvOrDefaultBool
(
"UPDATE_TASK"
,
true
)
constant
.
AzureDefaultAPIVersion
=
GetEnvOrDefaultString
(
"AZURE_DEFAULT_API_VERSION"
,
"2025-04-01-preview"
)
constant
.
AzureDefaultAPIVersion
=
GetEnvOrDefaultString
(
"AZURE_DEFAULT_API_VERSION"
,
"2025-04-01-preview"
)
constant
.
GeminiVisionMaxImageNum
=
GetEnvOrDefault
(
"GEMINI_VISION_MAX_IMAGE_NUM"
,
16
)
constant
.
NotifyLimitCount
=
GetEnvOrDefault
(
"NOTIFY_LIMIT_COUNT"
,
2
)
constant
.
NotifyLimitCount
=
GetEnvOrDefault
(
"NOTIFY_LIMIT_COUNT"
,
2
)
constant
.
NotificationLimitDurationMinute
=
GetEnvOrDefault
(
"NOTIFICATION_LIMIT_DURATION_MINUTE"
,
10
)
constant
.
NotificationLimitDurationMinute
=
GetEnvOrDefault
(
"NOTIFICATION_LIMIT_DURATION_MINUTE"
,
10
)
// GenerateDefaultToken 是否生成初始令牌,默认关闭。
// GenerateDefaultToken 是否生成初始令牌,默认关闭。
...
...
constant/env.go
View file @
ffef3311
...
@@ -11,7 +11,6 @@ var GetMediaTokenNotStream bool
...
@@ -11,7 +11,6 @@ var GetMediaTokenNotStream bool
var
UpdateTask
bool
var
UpdateTask
bool
var
MaxRequestBodyMB
int
var
MaxRequestBodyMB
int
var
AzureDefaultAPIVersion
string
var
AzureDefaultAPIVersion
string
var
GeminiVisionMaxImageNum
int
var
NotifyLimitCount
int
var
NotifyLimitCount
int
var
NotificationLimitDurationMinute
int
var
NotificationLimitDurationMinute
int
var
GenerateDefaultToken
bool
var
GenerateDefaultToken
bool
...
...
relay/channel/gemini/relay-gemini.go
View file @
ffef3311
...
@@ -466,7 +466,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
...
@@ -466,7 +466,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
}
}
openaiContent
:=
message
.
ParseContent
()
openaiContent
:=
message
.
ParseContent
()
imageNum
:=
0
for
_
,
part
:=
range
openaiContent
{
for
_
,
part
:=
range
openaiContent
{
if
part
.
Type
==
dto
.
ContentTypeText
{
if
part
.
Type
==
dto
.
ContentTypeText
{
if
part
.
Text
==
""
{
if
part
.
Text
==
""
{
...
@@ -507,10 +506,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
...
@@ -507,10 +506,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
}
}
// 提取 data URL (从 "](" 后面开始,到 ")" 之前)
// 提取 data URL (从 "](" 后面开始,到 ")" 之前)
dataUrl
:=
text
[
bracketIdx
+
2
:
closeIdx
]
dataUrl
:=
text
[
bracketIdx
+
2
:
closeIdx
]
imageNum
+=
1
if
constant
.
GeminiVisionMaxImageNum
!=
-
1
&&
imageNum
>
constant
.
GeminiVisionMaxImageNum
{
return
nil
,
fmt
.
Errorf
(
"too many images in the message, max allowed is %d"
,
constant
.
GeminiVisionMaxImageNum
)
}
format
,
base64String
,
err
:=
service
.
DecodeBase64FileData
(
dataUrl
)
format
,
base64String
,
err
:=
service
.
DecodeBase64FileData
(
dataUrl
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"decode markdown base64 image data failed: %s"
,
err
.
Error
())
return
nil
,
fmt
.
Errorf
(
"decode markdown base64 image data failed: %s"
,
err
.
Error
())
...
@@ -535,11 +530,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
...
@@ -535,11 +530,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
})
})
}
}
}
else
if
part
.
Type
==
dto
.
ContentTypeImageURL
{
}
else
if
part
.
Type
==
dto
.
ContentTypeImageURL
{
imageNum
+=
1
if
constant
.
GeminiVisionMaxImageNum
!=
-
1
&&
imageNum
>
constant
.
GeminiVisionMaxImageNum
{
return
nil
,
fmt
.
Errorf
(
"too many images in the message, max allowed is %d"
,
constant
.
GeminiVisionMaxImageNum
)
}
// 使用统一的文件服务获取图片数据
// 使用统一的文件服务获取图片数据
var
source
*
types
.
FileSource
var
source
*
types
.
FileSource
imageUrl
:=
part
.
GetImageMedia
()
.
Url
imageUrl
:=
part
.
GetImageMedia
()
.
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