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
5a10552d
authored
Oct 15, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: gemini embedding
parent
f91522b5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
1 deletions
+7
-1
dto/gemini.go
+1
-0
relay/embedding_handler.go
+2
-0
relay/gemini_handler.go
+3
-0
relay/helper/valid_request.go
+1
-1
No files found.
dto/gemini.go
View file @
5a10552d
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
)
)
type
GeminiChatRequest
struct
{
type
GeminiChatRequest
struct
{
Requests
[]
GeminiChatRequest
`json:"requests,omitempty"`
// For batch requests
Contents
[]
GeminiChatContent
`json:"contents"`
Contents
[]
GeminiChatContent
`json:"contents"`
SafetySettings
[]
GeminiChatSafetySettings
`json:"safetySettings,omitempty"`
SafetySettings
[]
GeminiChatSafetySettings
`json:"safetySettings,omitempty"`
GenerationConfig
GeminiChatGenerationConfig
`json:"generationConfig,omitempty"`
GenerationConfig
GeminiChatGenerationConfig
`json:"generationConfig,omitempty"`
...
...
relay/embedding_handler.go
View file @
5a10552d
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/dto"
"github.com/QuantumNous/new-api/logger"
relaycommon
"github.com/QuantumNous/new-api/relay/common"
relaycommon
"github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/relay/helper"
"github.com/QuantumNous/new-api/relay/helper"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/service"
...
@@ -48,6 +49,7 @@ func EmbeddingHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *
...
@@ -48,6 +49,7 @@ func EmbeddingHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *
if
err
!=
nil
{
if
err
!=
nil
{
return
types
.
NewError
(
err
,
types
.
ErrorCodeConvertRequestFailed
,
types
.
ErrOptionWithSkipRetry
())
return
types
.
NewError
(
err
,
types
.
ErrorCodeConvertRequestFailed
,
types
.
ErrOptionWithSkipRetry
())
}
}
logger
.
LogDebug
(
c
,
fmt
.
Sprintf
(
"converted embedding request body: %s"
,
string
(
jsonData
)))
requestBody
:=
bytes
.
NewBuffer
(
jsonData
)
requestBody
:=
bytes
.
NewBuffer
(
jsonData
)
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
statusCodeMappingStr
:=
c
.
GetString
(
"status_code_mapping"
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
info
,
requestBody
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
info
,
requestBody
)
...
...
relay/gemini_handler.go
View file @
5a10552d
...
@@ -240,6 +240,8 @@ func GeminiEmbeddingHandler(c *gin.Context, info *relaycommon.RelayInfo) (newAPI
...
@@ -240,6 +240,8 @@ func GeminiEmbeddingHandler(c *gin.Context, info *relaycommon.RelayInfo) (newAPI
return
types
.
NewError
(
err
,
types
.
ErrorCodeChannelModelMappedError
,
types
.
ErrOptionWithSkipRetry
())
return
types
.
NewError
(
err
,
types
.
ErrorCodeChannelModelMappedError
,
types
.
ErrOptionWithSkipRetry
())
}
}
req
.
SetModelName
(
"models/"
+
info
.
UpstreamModelName
)
adaptor
:=
GetAdaptor
(
info
.
ApiType
)
adaptor
:=
GetAdaptor
(
info
.
ApiType
)
if
adaptor
==
nil
{
if
adaptor
==
nil
{
return
types
.
NewError
(
fmt
.
Errorf
(
"invalid api type: %d"
,
info
.
ApiType
),
types
.
ErrorCodeInvalidApiType
,
types
.
ErrOptionWithSkipRetry
())
return
types
.
NewError
(
fmt
.
Errorf
(
"invalid api type: %d"
,
info
.
ApiType
),
types
.
ErrorCodeInvalidApiType
,
types
.
ErrOptionWithSkipRetry
())
...
@@ -264,6 +266,7 @@ func GeminiEmbeddingHandler(c *gin.Context, info *relaycommon.RelayInfo) (newAPI
...
@@ -264,6 +266,7 @@ func GeminiEmbeddingHandler(c *gin.Context, info *relaycommon.RelayInfo) (newAPI
return
types
.
NewError
(
err
,
types
.
ErrorCodeChannelParamOverrideInvalid
,
types
.
ErrOptionWithSkipRetry
())
return
types
.
NewError
(
err
,
types
.
ErrorCodeChannelParamOverrideInvalid
,
types
.
ErrOptionWithSkipRetry
())
}
}
}
}
logger
.
LogDebug
(
c
,
"Gemini embedding request body: "
+
string
(
jsonData
))
requestBody
=
bytes
.
NewReader
(
jsonData
)
requestBody
=
bytes
.
NewReader
(
jsonData
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
info
,
requestBody
)
resp
,
err
:=
adaptor
.
DoRequest
(
c
,
info
,
requestBody
)
...
...
relay/helper/valid_request.go
View file @
5a10552d
...
@@ -300,7 +300,7 @@ func GetAndValidateGeminiRequest(c *gin.Context) (*dto.GeminiChatRequest, error)
...
@@ -300,7 +300,7 @@ func GetAndValidateGeminiRequest(c *gin.Context) (*dto.GeminiChatRequest, error)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
len
(
request
.
Contents
)
==
0
{
if
len
(
request
.
Contents
)
==
0
&&
len
(
request
.
Requests
)
==
0
{
return
nil
,
errors
.
New
(
"contents is required"
)
return
nil
,
errors
.
New
(
"contents is required"
)
}
}
...
...
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