Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
565b802a
Unverified
Commit
565b802a
authored
Nov 06, 2025
by
Jeffrey Morgan
Committed by
GitHub
Nov 06, 2025
Browse files
openai: fix tool call ID mapping (#12988)
parent
6c79e6c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
15 deletions
+18
-15
middleware/openai_test.go
middleware/openai_test.go
+10
-3
openai/openai.go
openai/openai.go
+8
-12
No files found.
middleware/openai_test.go
View file @
565b802a
...
@@ -218,6 +218,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -218,6 +218,7 @@ func TestChatMiddleware(t *testing.T) {
Role
:
"assistant"
,
Role
:
"assistant"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
@@ -257,6 +258,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -257,6 +258,7 @@ func TestChatMiddleware(t *testing.T) {
Content
:
"Let's see what the weather is like in Paris"
,
Content
:
"Let's see what the weather is like in Paris"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
@@ -295,6 +297,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -295,6 +297,7 @@ func TestChatMiddleware(t *testing.T) {
Role
:
"assistant"
,
Role
:
"assistant"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
@@ -334,6 +337,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -334,6 +337,7 @@ func TestChatMiddleware(t *testing.T) {
Thinking
:
"Let's see what the weather is like in Paris"
,
Thinking
:
"Let's see what the weather is like in Paris"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
@@ -373,6 +377,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -373,6 +377,7 @@ func TestChatMiddleware(t *testing.T) {
Role
:
"assistant"
,
Role
:
"assistant"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id_abc"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
@@ -384,9 +389,10 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -384,9 +389,10 @@ func TestChatMiddleware(t *testing.T) {
},
},
},
},
{
{
Role
:
"tool"
,
Role
:
"tool"
,
Content
:
"The weather in Paris is 20 degrees Celsius"
,
Content
:
"The weather in Paris is 20 degrees Celsius"
,
ToolName
:
"get_current_weather"
,
ToolName
:
"get_current_weather"
,
ToolCallID
:
"id_abc"
,
},
},
},
},
Options
:
map
[
string
]
any
{
Options
:
map
[
string
]
any
{
...
@@ -417,6 +423,7 @@ func TestChatMiddleware(t *testing.T) {
...
@@ -417,6 +423,7 @@ func TestChatMiddleware(t *testing.T) {
Role
:
"assistant"
,
Role
:
"assistant"
,
ToolCalls
:
[]
api
.
ToolCall
{
ToolCalls
:
[]
api
.
ToolCall
{
{
{
ID
:
"id"
,
Function
:
api
.
ToolCallFunction
{
Function
:
api
.
ToolCallFunction
{
Name
:
"get_current_weather"
,
Name
:
"get_current_weather"
,
Arguments
:
map
[
string
]
any
{
Arguments
:
map
[
string
]
any
{
...
...
openai/openai.go
View file @
565b802a
...
@@ -437,7 +437,7 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
...
@@ -437,7 +437,7 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
messages
=
append
(
messages
,
api
.
Message
{
Role
:
msg
.
Role
,
Content
:
content
,
Thinking
:
msg
.
Reasoning
,
ToolCalls
:
toolCalls
,
ToolName
:
toolName
})
messages
=
append
(
messages
,
api
.
Message
{
Role
:
msg
.
Role
,
Content
:
content
,
Thinking
:
msg
.
Reasoning
,
ToolCalls
:
toolCalls
,
ToolName
:
toolName
,
ToolCallID
:
msg
.
ToolCallID
})
case
[]
any
:
case
[]
any
:
for
_
,
c
:=
range
content
{
for
_
,
c
:=
range
content
{
data
,
ok
:=
c
.
(
map
[
string
]
any
)
data
,
ok
:=
c
.
(
map
[
string
]
any
)
...
@@ -501,9 +501,8 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
...
@@ -501,9 +501,8 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
return
nil
,
err
return
nil
,
err
}
}
messages
[
len
(
messages
)
-
1
]
.
ToolCalls
=
toolCalls
messages
[
len
(
messages
)
-
1
]
.
ToolCalls
=
toolCalls
if
toolName
!=
""
{
messages
[
len
(
messages
)
-
1
]
.
ToolName
=
toolName
messages
[
len
(
messages
)
-
1
]
.
ToolName
=
toolName
messages
[
len
(
messages
)
-
1
]
.
ToolCallID
=
msg
.
ToolCallID
}
messages
[
len
(
messages
)
-
1
]
.
Thinking
=
msg
.
Reasoning
messages
[
len
(
messages
)
-
1
]
.
Thinking
=
msg
.
Reasoning
}
}
default
:
default
:
...
@@ -512,15 +511,11 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
...
@@ -512,15 +511,11 @@ func FromChatRequest(r ChatCompletionRequest) (*api.ChatRequest, error) {
return
nil
,
fmt
.
Errorf
(
"invalid message content type: %T"
,
content
)
return
nil
,
fmt
.
Errorf
(
"invalid message content type: %T"
,
content
)
}
}
toolCalls
:=
make
([]
api
.
ToolCall
,
len
(
msg
.
ToolCalls
))
toolCalls
,
err
:=
FromCompletionToolCall
(
msg
.
ToolCalls
)
for
i
,
tc
:=
range
msg
.
ToolCalls
{
if
err
!=
nil
{
toolCalls
[
i
]
.
Function
.
Name
=
tc
.
Function
.
Name
return
nil
,
err
err
:=
json
.
Unmarshal
([]
byte
(
tc
.
Function
.
Arguments
),
&
toolCalls
[
i
]
.
Function
.
Arguments
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"invalid tool call arguments"
)
}
}
}
messages
=
append
(
messages
,
api
.
Message
{
Role
:
msg
.
Role
,
Thinking
:
msg
.
Reasoning
,
ToolCalls
:
toolCalls
})
messages
=
append
(
messages
,
api
.
Message
{
Role
:
msg
.
Role
,
Thinking
:
msg
.
Reasoning
,
ToolCalls
:
toolCalls
,
ToolCallID
:
msg
.
ToolCallID
})
}
}
}
}
...
@@ -631,6 +626,7 @@ func nameFromToolCallID(messages []Message, toolCallID string) string {
...
@@ -631,6 +626,7 @@ func nameFromToolCallID(messages []Message, toolCallID string) string {
func
FromCompletionToolCall
(
toolCalls
[]
ToolCall
)
([]
api
.
ToolCall
,
error
)
{
func
FromCompletionToolCall
(
toolCalls
[]
ToolCall
)
([]
api
.
ToolCall
,
error
)
{
apiToolCalls
:=
make
([]
api
.
ToolCall
,
len
(
toolCalls
))
apiToolCalls
:=
make
([]
api
.
ToolCall
,
len
(
toolCalls
))
for
i
,
tc
:=
range
toolCalls
{
for
i
,
tc
:=
range
toolCalls
{
apiToolCalls
[
i
]
.
ID
=
tc
.
ID
apiToolCalls
[
i
]
.
Function
.
Name
=
tc
.
Function
.
Name
apiToolCalls
[
i
]
.
Function
.
Name
=
tc
.
Function
.
Name
err
:=
json
.
Unmarshal
([]
byte
(
tc
.
Function
.
Arguments
),
&
apiToolCalls
[
i
]
.
Function
.
Arguments
)
err
:=
json
.
Unmarshal
([]
byte
(
tc
.
Function
.
Arguments
),
&
apiToolCalls
[
i
]
.
Function
.
Arguments
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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