FIX: title suggestions should return 5 unique titles

This update fixes a regression from https://github.com/discourse/discourse-ai/pull/1484, which caused AI helper title suggestions to begin suggesting numerous non-unique titles because it was looping through structured responses incorrectly.
This commit is contained in:
Keegan George 2025-07-07 13:49:27 -07:00
parent 7357280e88
commit 422f238f9f
No known key found for this signature in database
GPG Key ID: 91B40E38537AC000

View File

@ -142,14 +142,21 @@ module DiscourseAi
Proc.new do |partial, _, type| Proc.new do |partial, _, type|
if type == :structured_output && schema_type if type == :structured_output && schema_type
helper_chunk = partial.read_buffered_property(schema_key) helper_chunk = partial.read_buffered_property(schema_key)
if !helper_chunk.nil? && !helper_chunk.empty? next if helper_chunk.nil? || helper_chunk.empty?
if schema_type == "string" || schema_type == "array"
if schema_type == "array"
if helper_chunk.is_a?(Array)
helper_chunk.each do |item|
helper_response << item if helper_response.exclude?(item)
end
end
elsif schema_type == "string"
helper_response << helper_chunk helper_response << helper_chunk
else else
helper_response = helper_chunk helper_response = helper_chunk
end end
block.call(helper_chunk) if block && !bad_json block.call(helper_chunk) if block && !bad_json
end
elsif type.blank? elsif type.blank?
# Assume response is a regular completion. # Assume response is a regular completion.
helper_response << partial helper_response << partial