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
258bad0a
authored
Jun 08, 2025
by
Calcium-Ion
Committed by
GitHub
Jun 08, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1173 from RedwindA/fix/ali-embedding
馃悰
fix(ali): Remove hardcoding of embedding model names.
parents
ff6e1286
894f9b98
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
relay/channel/ali/text.go
+9
-7
No files found.
relay/channel/ali/text.go
View file @
258bad0a
...
...
@@ -3,7 +3,6 @@ package ali
import
(
"bufio"
"encoding/json"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/common"
...
...
@@ -11,6 +10,8 @@ import (
"one-api/relay/helper"
"one-api/service"
"strings"
"github.com/gin-gonic/gin"
)
// https://help.aliyun.com/document_detail/613695.html?spm=a2c4g.2399480.0.0.1adb778fAdzP9w#341800c0f8w0r
...
...
@@ -27,9 +28,6 @@ func requestOpenAI2Ali(request dto.GeneralOpenAIRequest) *dto.GeneralOpenAIReque
}
func
embeddingRequestOpenAI2Ali
(
request
dto
.
EmbeddingRequest
)
*
AliEmbeddingRequest
{
if
request
.
Model
==
""
{
request
.
Model
=
"text-embedding-v1"
}
return
&
AliEmbeddingRequest
{
Model
:
request
.
Model
,
Input
:
struct
{
...
...
@@ -64,7 +62,11 @@ func aliEmbeddingHandler(c *gin.Context, resp *http.Response) (*dto.OpenAIErrorW
},
nil
}
fullTextResponse
:=
embeddingResponseAli2OpenAI
(
&
aliResponse
)
model
:=
c
.
GetString
(
"model"
)
if
model
==
""
{
model
=
"text-embedding-v4"
}
fullTextResponse
:=
embeddingResponseAli2OpenAI
(
&
aliResponse
,
model
)
jsonResponse
,
err
:=
json
.
Marshal
(
fullTextResponse
)
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapper
(
err
,
"marshal_response_body_failed"
,
http
.
StatusInternalServerError
),
nil
...
...
@@ -75,11 +77,11 @@ func aliEmbeddingHandler(c *gin.Context, resp *http.Response) (*dto.OpenAIErrorW
return
nil
,
&
fullTextResponse
.
Usage
}
func
embeddingResponseAli2OpenAI
(
response
*
AliEmbeddingResponse
)
*
dto
.
OpenAIEmbeddingResponse
{
func
embeddingResponseAli2OpenAI
(
response
*
AliEmbeddingResponse
,
model
string
)
*
dto
.
OpenAIEmbeddingResponse
{
openAIEmbeddingResponse
:=
dto
.
OpenAIEmbeddingResponse
{
Object
:
"list"
,
Data
:
make
([]
dto
.
OpenAIEmbeddingResponseItem
,
0
,
len
(
response
.
Output
.
Embeddings
)),
Model
:
"text-embedding-v1"
,
Model
:
model
,
Usage
:
dto
.
Usage
{
TotalTokens
:
response
.
Usage
.
TotalTokens
},
}
...
...
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