Class: Langchain::Assistant
- Inherits:
-
Object
- Object
- Langchain::Assistant
- Defined in:
- lib/langchainrb_overrides/assistant.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id: nil, **kwargs) ⇒ Assistant
constructor
rubocop:disable Style/ArgumentsForwarding.
- #original_initialize ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(id: nil, **kwargs) ⇒ Assistant
rubocop:disable Style/ArgumentsForwarding
11 12 13 14 |
# File 'lib/langchainrb_overrides/assistant.rb', line 11 def initialize(id: nil, **kwargs) # rubocop:disable Style/ArgumentsForwarding @id = id original_initialize(**kwargs) # rubocop:disable Style/ArgumentsForwarding end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/langchainrb_overrides/assistant.rb', line 7 def id @id end |
Class Method Details
.find_assistant(id) ⇒ Object
47 48 49 |
# File 'lib/langchainrb_overrides/assistant.rb', line 47 def find_assistant(id) ::Assistant.find(id) end |
.load(id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/langchainrb_overrides/assistant.rb', line 51 def load(id) ar_assistant = find_assistant(id) tools = ar_assistant.tools.map { |tool_name| Object.const_get(tool_name).new } assistant = Langchain::Assistant.new( id: ar_assistant.id, llm: ar_assistant.llm, tools: tools, instructions: ar_assistant.instructions, tool_choice: ar_assistant.tool_choice ) ar_assistant..each do || = assistant.( role: .role, content: .content, tool_calls: .tool_calls, tool_call_id: .tool_call_id ) .last.id = .id end assistant end |
Instance Method Details
#original_initialize ⇒ Object
9 |
# File 'lib/langchainrb_overrides/assistant.rb', line 9 alias_method :original_initialize, :initialize |
#save ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/langchainrb_overrides/assistant.rb', line 16 def save ::ActiveRecord::Base.transaction do ar_assistant = if id self.class.find_assistant(id) else ::Assistant.new end ar_assistant.update!( instructions: instructions, tool_choice: tool_choice, tools: tools.map(&:class).map(&:name) ) .each do || = ar_assistant..find_or_initialize_by(id: .id) .update!( role: .role, content: .content, tool_calls: .tool_calls, tool_call_id: .tool_call_id ) .id = .id end @id = ar_assistant.id true end end |