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
503a2669
authored
Sep 15, 2025
by
somnifex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 更新请求转换逻辑,优化工具调用解析
parent
cdf0c9da
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
8 deletions
+9
-8
relay/channel/ollama/adaptor.go
+2
-1
relay/channel/ollama/dto.go
+0
-1
relay/channel/ollama/relay-ollama.go
+7
-5
relay/channel/ollama/stream.go
+0
-1
No files found.
relay/channel/ollama/adaptor.go
View file @
503a2669
...
...
@@ -32,7 +32,8 @@ func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayIn
openaiRequest
.
(
*
dto
.
GeneralOpenAIRequest
)
.
StreamOptions
=
&
dto
.
StreamOptions
{
IncludeUsage
:
true
,
}
return
requestOpenAI2Ollama
(
c
,
openaiRequest
.
(
*
dto
.
GeneralOpenAIRequest
))
// map to ollama chat request (Claude -> OpenAI -> Ollama chat)
return
openAIChatToOllamaChat
(
c
,
openaiRequest
.
(
*
dto
.
GeneralOpenAIRequest
))
}
func
(
a
*
Adaptor
)
ConvertAudioRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
AudioRequest
)
(
io
.
Reader
,
error
)
{
...
...
relay/channel/ollama/dto.go
View file @
503a2669
...
...
@@ -2,7 +2,6 @@ package ollama
import
(
"encoding/json"
"one-api/dto"
)
// OllamaChatMessage represents a single chat message
...
...
relay/channel/ollama/relay-ollama.go
View file @
503a2669
...
...
@@ -101,19 +101,22 @@ func openAIChatToOllamaChat(c *gin.Context, r *dto.GeneralOpenAIRequest) (*Ollam
// history tool call result message
if
m
.
Role
==
"tool"
&&
m
.
Name
!=
nil
{
cm
.
ToolName
=
*
m
.
Name
}
// tool calls from assistant previous message
if
len
(
m
.
ToolCalls
)
>
0
{
calls
:=
make
([]
OllamaToolCall
,
0
,
len
(
m
.
ToolCalls
))
for
_
,
tc
:=
range
m
.
ToolCalls
{
if
m
.
ToolCalls
!=
nil
&&
len
(
m
.
ToolCalls
)
>
0
{
parsed
:=
m
.
ParseToolCalls
()
if
len
(
parsed
)
>
0
{
calls
:=
make
([]
OllamaToolCall
,
0
,
len
(
parsed
))
for
_
,
tc
:=
range
parsed
{
var
args
interface
{}
if
tc
.
Function
.
Arguments
!=
""
{
_
=
json
.
Unmarshal
([]
byte
(
tc
.
Function
.
Arguments
),
&
args
)
}
if
args
==
nil
{
args
=
map
[
string
]
any
{}
}
oc
:=
OllamaToolCall
{}
oc
.
Function
.
Name
=
tc
.
Function
.
Name
if
args
==
nil
{
args
=
map
[
string
]
any
{}
}
oc
.
Function
.
Arguments
=
args
calls
=
append
(
calls
,
oc
)
}
cm
.
ToolCalls
=
calls
}
}
chatReq
.
Messages
=
append
(
chatReq
.
Messages
,
cm
)
}
return
chatReq
,
nil
...
...
@@ -165,7 +168,6 @@ func requestOpenAI2Embeddings(r dto.EmbeddingRequest) *OllamaEmbeddingRequest {
opts
:=
map
[
string
]
any
{}
if
r
.
Temperature
!=
nil
{
opts
[
"temperature"
]
=
r
.
Temperature
}
if
r
.
TopP
!=
0
{
opts
[
"top_p"
]
=
r
.
TopP
}
if
r
.
TopK
!=
0
{
opts
[
"top_k"
]
=
r
.
TopK
}
if
r
.
FrequencyPenalty
!=
0
{
opts
[
"frequency_penalty"
]
=
r
.
FrequencyPenalty
}
if
r
.
PresencePenalty
!=
0
{
opts
[
"presence_penalty"
]
=
r
.
PresencePenalty
}
if
r
.
Seed
!=
0
{
opts
[
"seed"
]
=
int
(
r
.
Seed
)
}
...
...
relay/channel/ollama/stream.go
View file @
503a2669
...
...
@@ -87,7 +87,6 @@ func ollamaStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http
// delta content
var
content
string
if
chunk
.
Message
!=
nil
{
content
=
chunk
.
Message
.
Content
}
else
{
content
=
chunk
.
Response
}
if
content
!=
""
{
aggregatedText
.
WriteString
(
content
)
}
delta
:=
dto
.
ChatCompletionsStreamResponse
{
Id
:
responseId
,
Object
:
"chat.completion.chunk"
,
...
...
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