Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/ruby_llm/providers/openai/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module Media
module_function

def format_content(content) # rubocop:disable Metrics/PerceivedComplexity
return content.value if content.is_a?(RubyLLM::Content::Raw)
if content.is_a?(RubyLLM::Content::Raw)
value = content.value
return (value.is_a?(Hash) || value.is_a?(Array)) ? value.to_json : value
end
return content.to_json if content.is_a?(Hash) || content.is_a?(Array)
return content unless content.is_a?(Content)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions spec/ruby_llm/active_record/acts_as_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,30 @@ def execute(expression:)
expect(saved_message.role).to eq('assistant')
expect(saved_message.content_raw).to eq({ 'name' => 'Alice', 'age' => 25 })
end

it 'supports multi-turn conversations with structured responses' do
chat = Chat.create!(model: model)

schema = {
type: 'object',
properties: {
country: { type: 'string' }
},
required: %w[country],
additionalProperties: false
}

chat.with_schema(schema)

# First turn
chat.ask('What country is Paris in?')

# Second turn - this should not raise an error
response = chat.ask('What about Berlin?')

expect(response.content).to be_a(Hash)
expect(response.content['country']).to eq('Germany')
end
end

describe 'parameter passing' do
Expand Down