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
74057324
authored
Aug 09, 2025
by
RedwindA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix typo; add ParamOverride for Gemini Embedding
parent
8127ad99
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
12 deletions
+26
-12
relay/channel/gemini/adaptor.go
+3
-2
relay/channel/gemini/relay-gemini-native.go
+1
-1
relay/common/relay_info.go
+8
-8
relay/gemini_handler.go
+14
-1
No files found.
relay/channel/gemini/adaptor.go
View file @
74057324
...
...
@@ -115,7 +115,7 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"embedding"
)
||
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"gemini-embedding"
)
{
action
:=
"embedContent"
if
info
.
IsGeminiBatchEmbdding
{
if
info
.
IsGeminiBatchEmb
e
dding
{
action
=
"batchEmbedContents"
}
return
fmt
.
Sprintf
(
"%s/%s/models/%s:%s"
,
info
.
BaseUrl
,
version
,
info
.
UpstreamModelName
,
action
),
nil
...
...
@@ -199,7 +199,8 @@ func (a *Adaptor) DoRequest(c *gin.Context, info *relaycommon.RelayInfo, request
func
(
a
*
Adaptor
)
DoResponse
(
c
*
gin
.
Context
,
resp
*
http
.
Response
,
info
*
relaycommon
.
RelayInfo
)
(
usage
any
,
err
*
types
.
NewAPIError
)
{
if
info
.
RelayMode
==
constant
.
RelayModeGemini
{
if
strings
.
Contains
(
info
.
RequestURLPath
,
"embed"
)
{
if
strings
.
HasSuffix
(
info
.
RequestURLPath
,
":embedContent"
)
||
strings
.
HasSuffix
(
info
.
RequestURLPath
,
":batchEmbedContents"
)
{
return
NativeGeminiEmbeddingHandler
(
c
,
resp
,
info
)
}
if
info
.
IsStream
{
...
...
relay/channel/gemini/relay-gemini-native.go
View file @
74057324
...
...
@@ -81,7 +81,7 @@ func NativeGeminiEmbeddingHandler(c *gin.Context, resp *http.Response, info *rel
TotalTokens
:
info
.
PromptTokens
,
}
if
info
.
IsGeminiBatchEmbdding
{
if
info
.
IsGeminiBatchEmb
e
dding
{
var
geminiResponse
dto
.
GeminiBatchEmbeddingResponse
err
=
common
.
Unmarshal
(
responseBody
,
&
geminiResponse
)
if
err
!=
nil
{
...
...
relay/common/relay_info.go
View file @
74057324
...
...
@@ -74,14 +74,14 @@ type RelayInfo struct {
FirstResponseTime
time
.
Time
isFirstResponse
bool
//SendLastReasoningResponse bool
ApiType
int
IsStream
bool
IsGeminiBatchEmbdding
bool
IsPlayground
bool
UsePrice
bool
RelayMode
int
UpstreamModelName
string
OriginModelName
string
ApiType
int
IsStream
bool
IsGeminiBatchEmb
e
dding
bool
IsPlayground
bool
UsePrice
bool
RelayMode
int
UpstreamModelName
string
OriginModelName
string
//RecodeModelName string
RequestURLPath
string
ApiVersion
string
...
...
relay/gemini_handler.go
View file @
74057324
...
...
@@ -269,7 +269,7 @@ func GeminiEmbeddingHandler(c *gin.Context) (newAPIError *types.NewAPIError) {
relayInfo
:=
relaycommon
.
GenRelayInfoGemini
(
c
)
isBatch
:=
strings
.
HasSuffix
(
c
.
Request
.
URL
.
Path
,
"batchEmbedContents"
)
relayInfo
.
IsGeminiBatchEmbdding
=
isBatch
relayInfo
.
IsGeminiBatchEmb
e
dding
=
isBatch
var
promptTokens
int
var
req
any
...
...
@@ -338,6 +338,19 @@ func GeminiEmbeddingHandler(c *gin.Context) (newAPIError *types.NewAPIError) {
if
err
!=
nil
{
return
types
.
NewError
(
err
,
types
.
ErrorCodeConvertRequestFailed
,
types
.
ErrOptionWithSkipRetry
())
}
// apply param override
if
len
(
relayInfo
.
ParamOverride
)
>
0
{
reqMap
:=
make
(
map
[
string
]
interface
{})
_
=
common
.
Unmarshal
(
jsonData
,
&
reqMap
)
for
key
,
value
:=
range
relayInfo
.
ParamOverride
{
reqMap
[
key
]
=
value
}
jsonData
,
err
=
common
.
Marshal
(
reqMap
)
if
err
!=
nil
{
return
types
.
NewError
(
err
,
types
.
ErrorCodeChannelParamOverrideInvalid
,
types
.
ErrOptionWithSkipRetry
())
}
}
requestBody
=
bytes
.
NewReader
(
jsonData
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
relayInfo
,
requestBody
)
...
...
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