Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
21 changes: 3 additions & 18 deletions lib/completions/endpoints/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def perform_completion!(
model_params[:response_format].dig(:json_schema, :schema, :properties)

if schema_properties.present?
structured_output =
DiscourseAi::Completions::StructuredOutput.new(schema_properties)
structured_output = DiscourseAi::Completions::StructuredOutput.new(schema_properties)
end
end

Expand Down Expand Up @@ -430,23 +429,9 @@ def non_streaming_response(
response_data.reject!(&:blank?)

if structured_output.present?
has_string_response = false

response_data =
response_data.reduce([]) do |memo, data|
if data.is_a?(String)
structured_output << data
has_string_response = true
next(memo)
else
memo << data
end

memo
end
response_data.each { |data| structured_output << data if data.is_a?(String) }

# We only include the structured output if there was actually a structured response
response_data << structured_output if has_string_response
return structured_output
end

# this is to keep stuff backwards compatible
Expand Down
1 change: 1 addition & 0 deletions lib/completions/endpoints/canned_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def perform_completion!(
end

response = response.first if response.is_a?(Array) && response.length == 1

response
end

Expand Down
Loading