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
0e679d06
authored
Jul 22, 2025
by
t0ng7u
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/alpha' into alpha
parents
a2fc86a2
5c1f07ae
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
9 deletions
+24
-9
common/page_info.go
+1
-1
dto/openai_request.go
+2
-0
relay/channel/ollama/dto.go
+5
-1
relay/channel/ollama/relay-ollama.go
+6
-2
types/error.go
+10
-5
No files found.
common/page_info.go
View file @
0e679d06
...
@@ -41,7 +41,7 @@ func (p *PageInfo) SetItems(items any) {
...
@@ -41,7 +41,7 @@ func (p *PageInfo) SetItems(items any) {
func
GetPageQuery
(
c
*
gin
.
Context
)
*
PageInfo
{
func
GetPageQuery
(
c
*
gin
.
Context
)
*
PageInfo
{
pageInfo
:=
&
PageInfo
{}
pageInfo
:=
&
PageInfo
{}
// 手动获取并处理每个参数
// 手动获取并处理每个参数
if
page
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"p
age
"
));
err
==
nil
{
if
page
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
));
err
==
nil
{
pageInfo
.
Page
=
page
pageInfo
.
Page
=
page
}
}
if
pageSize
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
));
err
==
nil
{
if
pageSize
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
));
err
==
nil
{
...
...
dto/openai_request.go
View file @
0e679d06
...
@@ -62,6 +62,8 @@ type GeneralOpenAIRequest struct {
...
@@ -62,6 +62,8 @@ type GeneralOpenAIRequest struct {
Reasoning
json
.
RawMessage
`json:"reasoning,omitempty"`
Reasoning
json
.
RawMessage
`json:"reasoning,omitempty"`
// Ali Qwen Params
// Ali Qwen Params
VlHighResolutionImages
json
.
RawMessage
`json:"vl_high_resolution_images,omitempty"`
VlHighResolutionImages
json
.
RawMessage
`json:"vl_high_resolution_images,omitempty"`
// 用匿名参数接收额外参数,例如ollama的think参数在此接收
Extra
map
[
string
]
json
.
RawMessage
`json:"-"`
}
}
func
(
r
*
GeneralOpenAIRequest
)
ToMap
()
map
[
string
]
any
{
func
(
r
*
GeneralOpenAIRequest
)
ToMap
()
map
[
string
]
any
{
...
...
relay/channel/ollama/dto.go
View file @
0e679d06
package
ollama
package
ollama
import
"one-api/dto"
import
(
"encoding/json"
"one-api/dto"
)
type
OllamaRequest
struct
{
type
OllamaRequest
struct
{
Model
string
`json:"model,omitempty"`
Model
string
`json:"model,omitempty"`
...
@@ -19,6 +22,7 @@ type OllamaRequest struct {
...
@@ -19,6 +22,7 @@ type OllamaRequest struct {
Suffix
any
`json:"suffix,omitempty"`
Suffix
any
`json:"suffix,omitempty"`
StreamOptions
*
dto
.
StreamOptions
`json:"stream_options,omitempty"`
StreamOptions
*
dto
.
StreamOptions
`json:"stream_options,omitempty"`
Prompt
any
`json:"prompt,omitempty"`
Prompt
any
`json:"prompt,omitempty"`
Think
json
.
RawMessage
`json:"think,omitempty"`
}
}
type
Options
struct
{
type
Options
struct
{
...
...
relay/channel/ollama/relay-ollama.go
View file @
0e679d06
...
@@ -50,7 +50,7 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) (*OllamaRequest, err
...
@@ -50,7 +50,7 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) (*OllamaRequest, err
}
else
{
}
else
{
Stop
,
_
=
request
.
Stop
.
([]
string
)
Stop
,
_
=
request
.
Stop
.
([]
string
)
}
}
return
&
OllamaRequest
{
ollamaRequest
:=
&
OllamaRequest
{
Model
:
request
.
Model
,
Model
:
request
.
Model
,
Messages
:
messages
,
Messages
:
messages
,
Stream
:
request
.
Stream
,
Stream
:
request
.
Stream
,
...
@@ -67,7 +67,11 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) (*OllamaRequest, err
...
@@ -67,7 +67,11 @@ func requestOpenAI2Ollama(request dto.GeneralOpenAIRequest) (*OllamaRequest, err
Prompt
:
request
.
Prompt
,
Prompt
:
request
.
Prompt
,
StreamOptions
:
request
.
StreamOptions
,
StreamOptions
:
request
.
StreamOptions
,
Suffix
:
request
.
Suffix
,
Suffix
:
request
.
Suffix
,
},
nil
}
if
think
,
ok
:=
request
.
Extra
[
"think"
];
ok
{
ollamaRequest
.
Think
=
think
}
return
ollamaRequest
,
nil
}
}
func
requestOpenAI2Embeddings
(
request
dto
.
EmbeddingRequest
)
*
OllamaEmbeddingRequest
{
func
requestOpenAI2Embeddings
(
request
dto
.
EmbeddingRequest
)
*
OllamaEmbeddingRequest
{
...
...
types/error.go
View file @
0e679d06
...
@@ -105,23 +105,25 @@ func (e *NewAPIError) SetMessage(message string) {
...
@@ -105,23 +105,25 @@ func (e *NewAPIError) SetMessage(message string) {
func
(
e
*
NewAPIError
)
ToOpenAIError
()
OpenAIError
{
func
(
e
*
NewAPIError
)
ToOpenAIError
()
OpenAIError
{
switch
e
.
ErrorType
{
switch
e
.
ErrorType
{
case
ErrorTypeOpenAIError
:
case
ErrorTypeOpenAIError
:
return
e
.
RelayError
.
(
OpenAIError
)
if
openAIError
,
ok
:=
e
.
RelayError
.
(
OpenAIError
);
ok
{
return
openAIError
}
case
ErrorTypeClaudeError
:
case
ErrorTypeClaudeError
:
claudeError
:=
e
.
RelayError
.
(
ClaudeError
)
if
claudeError
,
ok
:=
e
.
RelayError
.
(
ClaudeError
);
ok
{
return
OpenAIError
{
return
OpenAIError
{
Message
:
e
.
Error
(),
Message
:
e
.
Error
(),
Type
:
claudeError
.
Type
,
Type
:
claudeError
.
Type
,
Param
:
""
,
Param
:
""
,
Code
:
e
.
errorCode
,
Code
:
e
.
errorCode
,
}
}
default
:
}
}
return
OpenAIError
{
return
OpenAIError
{
Message
:
e
.
Error
(),
Message
:
e
.
Error
(),
Type
:
string
(
e
.
ErrorType
),
Type
:
string
(
e
.
ErrorType
),
Param
:
""
,
Param
:
""
,
Code
:
e
.
errorCode
,
Code
:
e
.
errorCode
,
}
}
}
}
}
func
(
e
*
NewAPIError
)
ToClaudeError
()
ClaudeError
{
func
(
e
*
NewAPIError
)
ToClaudeError
()
ClaudeError
{
...
@@ -163,7 +165,10 @@ func NewOpenAIError(err error, errorCode ErrorCode, statusCode int) *NewAPIError
...
@@ -163,7 +165,10 @@ func NewOpenAIError(err error, errorCode ErrorCode, statusCode int) *NewAPIError
func
NewErrorWithStatusCode
(
err
error
,
errorCode
ErrorCode
,
statusCode
int
)
*
NewAPIError
{
func
NewErrorWithStatusCode
(
err
error
,
errorCode
ErrorCode
,
statusCode
int
)
*
NewAPIError
{
return
&
NewAPIError
{
return
&
NewAPIError
{
Err
:
err
,
Err
:
err
,
RelayError
:
nil
,
RelayError
:
OpenAIError
{
Message
:
err
.
Error
(),
Type
:
string
(
errorCode
),
},
ErrorType
:
ErrorTypeNewAPIError
,
ErrorType
:
ErrorTypeNewAPIError
,
StatusCode
:
statusCode
,
StatusCode
:
statusCode
,
errorCode
:
errorCode
,
errorCode
:
errorCode
,
...
...
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