mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-25 09:02:23 +00:00
FIX: Return structured output on non-streaming mode (#1318)
This commit is contained in:
parent
adc2716cec
commit
5bc9fdc06b
@ -114,8 +114,7 @@ module DiscourseAi
|
||||
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
|
||||
|
||||
@ -430,23 +429,9 @@ module DiscourseAi
|
||||
response_data.reject!(&:blank?)
|
||||
|
||||
if structured_output.present?
|
||||
has_string_response = false
|
||||
response_data.each { |data| structured_output << data if data.is_a?(String) }
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
|
@ -68,6 +68,7 @@ module DiscourseAi
|
||||
end
|
||||
|
||||
response = response.first if response.is_a?(Array) && response.length == 1
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user