lib/intelli_agent/openai.rb in intelli_agent-0.1.2 vs lib/intelli_agent/openai.rb in intelli_agent-0.1.3

- old
+ new

@@ -59,10 +59,12 @@ end def self.chat(messages:, model: :basic, response_format: nil, max_tokens: MAX_TOKENS) model = select_model(model) + messages = determine_message_format(messages).eql?(:short_format) ? convert_message_to_standard_format(messages) : messages + parameters = { model:, messages:, max_tokens: } parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json) response = OpenAI::Client.new.chat(parameters:) if response_format.nil? @@ -82,6 +84,24 @@ ADVANCED_MODEL else model end end + + def self.determine_message_format(messages) + case messages + in [{ role: String, content: String }, *] + :standard_format + in [{ system: String }, { user: String }, *] + :short_format + else + :unknown_format + end + end + + def self.convert_message_to_standard_format(messages) + messages.map do |msg| + role, content = msg.first + { role: role.to_s, content: content } + end + end end \ No newline at end of file