Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(readme): Move 'messages << message' outside of loop to prevent duplicatentries #554

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix: Move 'messages << message' outside of loop to prevent duplicate …
…entries
taro1025 committed Dec 6, 2024
commit dfb540506789e458150e46a348726b655e6565fe
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -489,6 +489,10 @@ response =
message = response.dig("choices", 0, "message")

if message["role"] == "assistant" && message["tool_calls"]

# For a subsequent message with the role "tool", OpenAI requires the preceding message to have a tool_calls argument.
messages << message

message["tool_calls"].each do |tool_call|
tool_call_id = tool_call.dig("id")
function_name = tool_call.dig("function", "name")
@@ -504,9 +508,6 @@ if message["role"] == "assistant" && message["tool_calls"]
# decide how to handle
end

# For a subsequent message with the role "tool", OpenAI requires the preceding message to have a tool_calls argument.
messages << message

messages << {
tool_call_id: tool_call_id,
role: "tool",