Skip to content

Commit

Permalink
Multi-turn tool fix
Browse files Browse the repository at this point in the history
  • Loading branch information
svilupp authored Oct 20, 2024
1 parent 06fcd59 commit 6e728ab
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.59.1]

### Fixed
- Fixed a bug in multi-turn tool calls for OpenAI models where an empty tools array could have been, which causes an API error.

## [0.59.0]

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PromptingTools"
uuid = "670122d1-24a8-4d70-bfce-740807c42192"
authors = ["J S @svilupp and contributors"]
version = "0.59.0"
version = "0.59.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
16 changes: 11 additions & 5 deletions src/llm_openai.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@ function render(schema::AbstractOpenAISchema,
end
Dict("role" => role4render(schema, msg), "content" => content)
elseif isaitoolrequest(msg)
Dict("role" => role4render(schema, msg), "content" => msg.content,
"tool_calls" => [Dict("id" => tool.tool_call_id, "type" => "function",
"function" => Dict("name" => tool.name,
"arguments" => tool.raw))
for tool in msg.tool_calls])
output = Dict{String, Any}(
"role" => role4render(schema, msg),
"content" => msg.content)
if !isempty(msg.tool_calls)
output["tool_calls"] = [Dict("id" => tool.tool_call_id,
"type" => "function",
"function" => Dict("name" => tool.name,
"arguments" => tool.raw))
for tool in msg.tool_calls]
end
output
elseif istoolmessage(msg)
content = msg.content isa AbstractString ? msg.content : string(msg.content)
Dict("role" => role4render(schema, msg), "content" => content,
Expand Down
14 changes: 14 additions & 0 deletions test/llm_openai.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,20 @@ using PromptingTools: pick_tokenizer, OPENAI_TOKEN_IDS_GPT35_GPT4, OPENAI_TOKEN_
]
@test conversation == expected_output

# With empty tools
messages = [
SystemMessage("System message"),
UserMessage("User message"),
AIToolRequest(;content="content")
]
conversation = render(schema, messages)
expected_output = Dict{String, Any}[
Dict("role" => "system", "content" => "System message"),
Dict("role" => "user", "content" => "User message"),
Dict("role" => "assistant", "content" => "content")
]
@test conversation == expected_output

# With a list of images and detail="low"
messages = [
SystemMessage("System message 2"),
Expand Down

2 comments on commit 6e728ab

@svilupp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

### Fixed

  • Fixed a bug in multi-turn tool calls for OpenAI models where an empty tools array could have been, which causes an API error.

Commits

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117701

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.59.1 -m "<description of version>" 6e728ab3261200bfec91b5cea188188e31897ea5
git push origin v0.59.1

Please sign in to comment.