Skip to content

Commit

Permalink
Hotfix: Correct double serialization of tool call
Browse files Browse the repository at this point in the history
  • Loading branch information
krschacht committed Nov 23, 2024
1 parent 15da3fb commit e73019b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/serializers/JsonSerializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def self.convert_value(value)
value
end
end
end
end
2 changes: 1 addition & 1 deletion app/services/ai_backend/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_tool_messages_by_calling(tool_calls_response)
{
role: "tool",
content: function_response.to_json,
content_tool_calls: tool_call.to_json,
content_tool_calls: tool_call,
tool_call_id: id,
}
end
Expand Down
2 changes: 1 addition & 1 deletion test/services/ai_backend/open_ai_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AIBackend::OpenAITest < ActiveSupport::TestCase
role: "tool",
content: "\"Hello, World!\"",
tool_call_id: "abc123",
content_tool_calls: messages(:weather_tool_call).content_tool_calls.first.to_json,
content_tool_calls: messages(:weather_tool_call).content_tool_calls.first,
}
assert_equal [tool_message], AIBackend::OpenAI.get_tool_messages_by_calling(messages(:weather_tool_call).content_tool_calls)
end
Expand Down
6 changes: 3 additions & 3 deletions test/services/ai_backend/tools_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AIBackend::ToolsTest < ActiveSupport::TestCase
role: "tool",
content: "\"Hello, World!\"",
tool_call_id: "abc123",
content_tool_calls: messages(:weather_tool_call).content_tool_calls.first.to_json,
content_tool_calls: messages(:weather_tool_call).content_tool_calls.first,
}
assert_equal [tool_message], AIBackend.get_tool_messages_by_calling(messages(:weather_tool_call).content_tool_calls)
end
Expand All @@ -19,7 +19,7 @@ class AIBackend::ToolsTest < ActiveSupport::TestCase
msg = AIBackend::OpenAI.get_tool_messages_by_calling(tool_calls).first
assert_equal "tool", msg[:role]
assert_equal "abc123", msg[:tool_call_id]
assert_equal messages(:weather_tool_call).content_tool_calls.first.to_json, msg[:content_tool_calls]
assert_equal messages(:weather_tool_call).content_tool_calls.first, msg[:content_tool_calls]
assert msg[:content].starts_with?('"An unexpected error occurred')
end

Expand All @@ -31,7 +31,7 @@ class AIBackend::ToolsTest < ActiveSupport::TestCase
msg = AIBackend::OpenAI.get_tool_messages_by_calling(tool_calls).first
assert_equal "tool", msg[:role]
assert_equal "abc123", msg[:tool_call_id]
assert_equal messages(:weather_tool_call).content_tool_calls.first.to_json, msg[:content_tool_calls]
assert_equal messages(:weather_tool_call).content_tool_calls.first, msg[:content_tool_calls]
assert msg[:content].starts_with?('"An unexpected error occurred')
end
end

0 comments on commit e73019b

Please sign in to comment.