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
99928bcf
authored
Feb 05, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: charge local input tokens when Gemini returns empty response
parent
c70fa24e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
relay/channel/gemini/relay-gemini.go
+1
-2
relay/common/relay_info.go
+1
-0
relay/helper/stream_scanner.go
+7
-7
No files found.
relay/channel/gemini/relay-gemini.go
View file @
99928bcf
...
...
@@ -1258,8 +1258,7 @@ func geminiStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http
}
if
usage
.
CompletionTokens
<=
0
{
str
:=
responseText
.
String
()
if
len
(
str
)
>
0
{
if
info
.
ReceivedResponseCount
>
0
{
usage
=
service
.
ResponseText2Usage
(
c
,
responseText
.
String
(),
info
.
UpstreamModelName
,
info
.
GetEstimatePromptTokens
())
}
else
{
usage
=
&
dto
.
Usage
{}
...
...
relay/common/relay_info.go
View file @
99928bcf
...
...
@@ -113,6 +113,7 @@ type RelayInfo struct {
UserQuota
int
RelayFormat
types
.
RelayFormat
SendResponseCount
int
ReceivedResponseCount
int
FinalPreConsumedQuota
int
// 最终预消耗的配额
// BillingSource indicates whether this request is billed from wallet quota or subscription.
// "" or "wallet" => wallet; "subscription" => subscription
...
...
relay/helper/stream_scanner.go
View file @
99928bcf
...
...
@@ -90,10 +90,10 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
// 等待所有 goroutine 退出,最多等待5秒
done
:=
make
(
chan
struct
{})
go
func
()
{
go
pool
.
Go
(
func
()
{
wg
.
Wait
()
close
(
done
)
}
(
)
})
select
{
case
<-
done
:
...
...
@@ -138,11 +138,11 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
case
<-
pingTicker
.
C
:
// 使用超时机制防止写操作阻塞
done
:=
make
(
chan
error
,
1
)
go
func
()
{
go
pool
.
Go
(
func
()
{
writeMutex
.
Lock
()
defer
writeMutex
.
Unlock
()
done
<-
PingData
(
c
)
}
(
)
})
select
{
case
err
:=
<-
done
:
...
...
@@ -219,14 +219,14 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
data
=
strings
.
TrimSuffix
(
data
,
"
\r
"
)
if
!
strings
.
HasPrefix
(
data
,
"[DONE]"
)
{
info
.
SetFirstResponseTime
()
info
.
ReceivedResponseCount
++
// 使用超时机制防止写操作阻塞
done
:=
make
(
chan
bool
,
1
)
go
func
()
{
go
pool
.
Go
(
func
()
{
writeMutex
.
Lock
()
defer
writeMutex
.
Unlock
()
done
<-
dataHandler
(
data
)
}
(
)
})
select
{
case
success
:=
<-
done
:
...
...
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