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
fffef91d
authored
Sep 12, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support ollama multi-text embedding
parent
daa5004f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
relay/channel/ollama/dto.go
+16
-2
relay/channel/ollama/relay-ollama.go
+12
-3
No files found.
relay/channel/ollama/dto.go
View file @
fffef91d
...
@@ -17,11 +17,25 @@ type OllamaRequest struct {
...
@@ -17,11 +17,25 @@ type OllamaRequest struct {
PresencePenalty
float64
`json:"presence_penalty,omitempty"`
PresencePenalty
float64
`json:"presence_penalty,omitempty"`
}
}
type
Options
struct
{
Seed
int
`json:"seed,omitempty"`
Temperature
float64
`json:"temperature,omitempty"`
TopK
int
`json:"top_k,omitempty"`
TopP
float64
`json:"top_p,omitempty"`
FrequencyPenalty
float64
`json:"frequency_penalty,omitempty"`
PresencePenalty
float64
`json:"presence_penalty,omitempty"`
NumPredict
int
`json:"num_predict,omitempty"`
NumCtx
int
`json:"num_ctx,omitempty"`
}
type
OllamaEmbeddingRequest
struct
{
type
OllamaEmbeddingRequest
struct
{
Model
string
`json:"model,omitempty"`
Model
string
`json:"model,omitempty"`
Prompt
any
`json:"prompt,omitempty"`
Input
[]
string
`json:"input"`
Options
*
Options
`json:"options,omitempty"`
}
}
type
OllamaEmbeddingResponse
struct
{
type
OllamaEmbeddingResponse
struct
{
Error
string
`json:"error,omitempty"`
Model
string
`json:"model"`
Embedding
[]
float64
`json:"embedding,omitempty"`
Embedding
[]
float64
`json:"embedding,omitempty"`
}
}
relay/channel/ollama/relay-ollama.go
View file @
fffef91d
...
@@ -9,7 +9,6 @@ import (
...
@@ -9,7 +9,6 @@ import (
"net/http"
"net/http"
"one-api/dto"
"one-api/dto"
"one-api/service"
"one-api/service"
"strings"
)
)
func
requestOpenAI2Ollama
(
request
dto
.
GeneralOpenAIRequest
)
*
OllamaRequest
{
func
requestOpenAI2Ollama
(
request
dto
.
GeneralOpenAIRequest
)
*
OllamaRequest
{
...
@@ -45,8 +44,15 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) *OllamaRequest {
...
@@ -45,8 +44,15 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) *OllamaRequest {
func
requestOpenAI2Embeddings
(
request
dto
.
GeneralOpenAIRequest
)
*
OllamaEmbeddingRequest
{
func
requestOpenAI2Embeddings
(
request
dto
.
GeneralOpenAIRequest
)
*
OllamaEmbeddingRequest
{
return
&
OllamaEmbeddingRequest
{
return
&
OllamaEmbeddingRequest
{
Model
:
request
.
Model
,
Model
:
request
.
Model
,
Prompt
:
strings
.
Join
(
request
.
ParseInput
(),
" "
),
Input
:
request
.
ParseInput
(),
Options
:
&
Options
{
Seed
:
int
(
request
.
Seed
),
Temperature
:
request
.
Temperature
,
TopP
:
request
.
TopP
,
FrequencyPenalty
:
request
.
FrequencyPenalty
,
PresencePenalty
:
request
.
PresencePenalty
,
},
}
}
}
}
...
@@ -64,6 +70,9 @@ func ollamaEmbeddingHandler(c *gin.Context, resp *http.Response, promptTokens in
...
@@ -64,6 +70,9 @@ func ollamaEmbeddingHandler(c *gin.Context, resp *http.Response, promptTokens in
if
err
!=
nil
{
if
err
!=
nil
{
return
service
.
OpenAIErrorWrapper
(
err
,
"unmarshal_response_body_failed"
,
http
.
StatusInternalServerError
),
nil
return
service
.
OpenAIErrorWrapper
(
err
,
"unmarshal_response_body_failed"
,
http
.
StatusInternalServerError
),
nil
}
}
if
ollamaEmbeddingResponse
.
Error
!=
""
{
return
service
.
OpenAIErrorWrapper
(
err
,
"ollama_error"
,
resp
.
StatusCode
),
nil
}
data
:=
make
([]
dto
.
OpenAIEmbeddingResponseItem
,
0
,
1
)
data
:=
make
([]
dto
.
OpenAIEmbeddingResponseItem
,
0
,
1
)
data
=
append
(
data
,
dto
.
OpenAIEmbeddingResponseItem
{
data
=
append
(
data
,
dto
.
OpenAIEmbeddingResponseItem
{
Embedding
:
ollamaEmbeddingResponse
.
Embedding
,
Embedding
:
ollamaEmbeddingResponse
.
Embedding
,
...
...
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