Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 422f238

Browse files
committed
FIX: title suggestions should return 5 unique titles
This update fixes a regression from #1484, which caused AI helper title suggestions to begin suggesting numerous non-unique titles because it was looping through structured responses incorrectly.
1 parent 7357280 commit 422f238

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/ai_helper/assistant.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,21 @@ def generate_prompt(
142142
Proc.new do |partial, _, type|
143143
if type == :structured_output && schema_type
144144
helper_chunk = partial.read_buffered_property(schema_key)
145-
if !helper_chunk.nil? && !helper_chunk.empty?
146-
if schema_type == "string" || schema_type == "array"
147-
helper_response << helper_chunk
148-
else
149-
helper_response = helper_chunk
145+
next if helper_chunk.nil? || helper_chunk.empty?
146+
147+
if schema_type == "array"
148+
if helper_chunk.is_a?(Array)
149+
helper_chunk.each do |item|
150+
helper_response << item if helper_response.exclude?(item)
151+
end
150152
end
151-
block.call(helper_chunk) if block && !bad_json
153+
elsif schema_type == "string"
154+
helper_response << helper_chunk
155+
else
156+
helper_response = helper_chunk
152157
end
158+
159+
block.call(helper_chunk) if block && !bad_json
153160
elsif type.blank?
154161
# Assume response is a regular completion.
155162
helper_response << partial

0 commit comments

Comments
 (0)