Skip to content

Commit

Permalink
Support agent messages to simplify multi-turn
Browse files Browse the repository at this point in the history
  • Loading branch information
ksylvest committed Oct 24, 2024
1 parent e895a7c commit 8e3c49e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
omniai (1.8.2)
omniai (1.8.3)
event_stream_parser
http
zeitwerk
Expand Down
18 changes: 18 additions & 0 deletions lib/omniai/chat/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ def system(content = nil, &)
def user(content = nil, &)
message(content, role: Role::USER, &)
end

# @example
# prompt.agent('the capital of Canada is Ottawa.')
#
# @example
# prompt.agent do |message|
# message.text 'the capital of Canada is Ottawa.'
# end
#
# @param content [String, nil]
#
# @yield [builder]
# @yieldparam builder [Message::Builder]
#
# @return [Message]
def agent(content = nil, &)
message(content, role: Role::AGENT, &)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/omniai/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OmniAI
VERSION = '1.8.2'
VERSION = '1.8.3'
end
14 changes: 14 additions & 0 deletions spec/omniai/chat/prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@
end
end

describe '#agent' do
context 'with some text' do
let(:message) { prompt.user('The capital of Canada is Ottawa.') }

it { expect { message }.to(change { prompt.messages.size }) }
end

context 'with a block' do
let(:message) { prompt.user { |message| message.text('The capital of Canada is Ottawa.') } }

it { expect { message }.to(change { prompt.messages.size }) }
end
end

describe '#serialize' do
subject(:serialize) { prompt.serialize }

Expand Down

0 comments on commit 8e3c49e

Please sign in to comment.