Class: ActivePinecone::Assistant
- Inherits:
-
Object
- Object
- ActivePinecone::Assistant
- Defined in:
- lib/active_pinecone/assistant.rb
Instance Attribute Summary collapse
-
#instruction ⇒ Object
readonly
Returns the value of attribute instruction.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model, instruction: 'Context:') ⇒ Assistant
constructor
A new instance of Assistant.
- #messages ⇒ Object
- #reply(message) ⇒ Object
Constructor Details
#initialize(model, instruction: 'Context:') ⇒ Assistant
Returns a new instance of Assistant.
5 6 7 8 9 |
# File 'lib/active_pinecone/assistant.rb', line 5 def initialize(model, instruction: 'Context:') @model = model @instruction = instruction @messages_with_system = [{ role: 'system', content: '' }] end |
Instance Attribute Details
#instruction ⇒ Object (readonly)
Returns the value of attribute instruction.
3 4 5 |
# File 'lib/active_pinecone/assistant.rb', line 3 def instruction @instruction end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/active_pinecone/assistant.rb', line 3 def model @model end |
Class Method Details
.openai ⇒ Object
11 12 13 |
# File 'lib/active_pinecone/assistant.rb', line 11 def self.openai @openai ||= ActivePinecone::Openai.new end |
Instance Method Details
#messages ⇒ Object
15 16 17 |
# File 'lib/active_pinecone/assistant.rb', line 15 def @messages_with_system.drop(1) end |
#reply(message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_pinecone/assistant.rb', line 19 def reply() @messages_with_system << { role: 'user', content: } records = model.search(.pluck(:content)) @messages_with_system[0][:content] = [instruction, records.map(&:attributes).to_json].join("\n") result = self.class.openai.chat( parameters: { model: ActivePinecone.configuration.chat_model, messages: , temperature: 0.7 } ) rep = ActivePinecone::Message.new(role: 'assistant', content: result['choices'][0]['message']['content'], references: ) @messages_with_system << rep rep end |