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
0b245ff4
authored
Jun 20, 2025
by
Calcium-Ion
Committed by
GitHub
Jun 20, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1268 from QuantumNous/alpha
fix: gemini relay empty response
parents
05aaf633
2b2e0a47
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
24 deletions
+62
-24
controller/channel.go
+19
-9
model/main.go
+9
-0
model/utils.go
+19
-2
relay/channel/gemini/relay-gemini-native.go
+0
-13
relay/relay-gemini.go
+15
-0
web/src/pages/TopUp/index.js
+0
-0
No files found.
controller/channel.go
View file @
0b245ff4
...
...
@@ -102,14 +102,14 @@ func GetAllChannels(c *gin.Context) {
typeCounts
,
_
:=
model
.
CountChannelsGroupByType
()
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"message"
:
""
,
"data"
:
gin
.
H
{
"items"
:
channelData
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
"type_counts"
:
typeCounts
,
"success"
:
true
,
"message"
:
""
,
"data"
:
gin
.
H
{
"items"
:
channelData
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
"type_counts"
:
typeCounts
,
},
})
return
...
...
@@ -237,10 +237,20 @@ func SearchChannels(c *gin.Context) {
}
channelData
=
channels
}
// calculate type counts for search results
typeCounts
:=
make
(
map
[
int64
]
int64
)
for
_
,
channel
:=
range
channelData
{
typeCounts
[
int64
(
channel
.
Type
)]
++
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"message"
:
""
,
"data"
:
channelData
,
"data"
:
gin
.
H
{
"items"
:
channelData
,
"type_counts"
:
typeCounts
,
},
})
return
}
...
...
model/main.go
View file @
0b245ff4
...
...
@@ -46,6 +46,15 @@ func initCol() {
logGroupCol
=
commonGroupCol
logKeyCol
=
commonKeyCol
}
}
else
{
// LOG_SQL_DSN 为空时,日志数据库与主数据库相同
if
common
.
UsingPostgreSQL
{
logGroupCol
=
`"group"`
logKeyCol
=
`"key"`
}
else
{
logGroupCol
=
commonGroupCol
logKeyCol
=
commonKeyCol
}
}
// log sql type and database type
common
.
SysLog
(
"Using Log SQL Type: "
+
common
.
LogSqlType
)
...
...
model/utils.go
View file @
0b245ff4
...
...
@@ -2,11 +2,12 @@ package model
import
(
"errors"
"github.com/bytedance/gopkg/util/gopool"
"gorm.io/gorm"
"one-api/common"
"sync"
"time"
"github.com/bytedance/gopkg/util/gopool"
"gorm.io/gorm"
)
const
(
...
...
@@ -48,6 +49,22 @@ func addNewRecord(type_ int, id int, value int) {
}
func
batchUpdate
()
{
// check if there's any data to update
hasData
:=
false
for
i
:=
0
;
i
<
BatchUpdateTypeCount
;
i
++
{
batchUpdateLocks
[
i
]
.
Lock
()
if
len
(
batchUpdateStores
[
i
])
>
0
{
hasData
=
true
batchUpdateLocks
[
i
]
.
Unlock
()
break
}
batchUpdateLocks
[
i
]
.
Unlock
()
}
if
!
hasData
{
return
}
common
.
SysLog
(
"batch update started"
)
for
i
:=
0
;
i
<
BatchUpdateTypeCount
;
i
++
{
batchUpdateLocks
[
i
]
.
Lock
()
...
...
relay/channel/gemini/relay-gemini-native.go
View file @
0b245ff4
...
...
@@ -35,19 +35,6 @@ func GeminiTextGenerationHandler(c *gin.Context, resp *http.Response, info *rela
return
nil
,
service
.
OpenAIErrorWrapper
(
err
,
"unmarshal_response_body_failed"
,
http
.
StatusInternalServerError
)
}
// 检查是否有候选响应
if
len
(
geminiResponse
.
Candidates
)
==
0
{
return
nil
,
&
dto
.
OpenAIErrorWithStatusCode
{
Error
:
dto
.
OpenAIError
{
Message
:
"No candidates returned"
,
Type
:
"server_error"
,
Param
:
""
,
Code
:
500
,
},
StatusCode
:
resp
.
StatusCode
,
}
}
// 计算使用量(基于 UsageMetadata)
usage
:=
dto
.
Usage
{
PromptTokens
:
geminiResponse
.
UsageMetadata
.
PromptTokenCount
,
...
...
relay/relay-gemini.go
View file @
0b245ff4
...
...
@@ -165,8 +165,23 @@ func GeminiHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
return
service
.
OpenAIErrorWrapperLocal
(
err
,
"do_request_failed"
,
http
.
StatusInternalServerError
)
}
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
var
httpResp
*
http
.
Response
if
resp
!=
nil
{
httpResp
=
resp
.
(
*
http
.
Response
)
relayInfo
.
IsStream
=
relayInfo
.
IsStream
||
strings
.
HasPrefix
(
httpResp
.
Header
.
Get
(
"Content-Type"
),
"text/event-stream"
)
if
httpResp
.
StatusCode
!=
http
.
StatusOK
{
openaiErr
=
service
.
RelayErrorHandler
(
httpResp
,
false
)
// reset status code 重置状态码
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
}
}
usage
,
openaiErr
:=
adaptor
.
DoResponse
(
c
,
resp
.
(
*
http
.
Response
),
relayInfo
)
if
openaiErr
!=
nil
{
service
.
ResetStatusCode
(
openaiErr
,
statusCodeMappingStr
)
return
openaiErr
}
...
...
web/src/pages/TopUp/index.js
View file @
0b245ff4
This diff is collapsed.
Click to expand it.
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