Class: Plain::Message

Inherits:
ApplicationRecord show all
Defined in:
app/models/plain/message.rb

Instance Method Summary collapse

Instance Method Details

#assistant?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/plain/message.rb', line 30

def assistant?
  role == "assistant"
end

#persist_as_document(path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/plain/message.rb', line 34

def persist_as_document(path)
  # Remove starting '/' if present
  path = path.sub(/\A\//, '')

  # Add '.md' extension if it's not already present
  path += '.md' unless path.end_with?('.md')

  # Construct the full path to the desired file
  full_path = Rails.root.join('docs', path)

  # Create the directory path, unless it already exists
  dirname = File.dirname(full_path)
  FileUtils.mkdir_p(dirname) unless File.directory?(dirname)

  # Write content from self.body to the file, unless it already exists
  File.write(full_path, self.content) unless File.exist?(full_path)
end

#typeObject



52
53
54
55
56
57
58
59
# File 'app/models/plain/message.rb', line 52

def type
  case self.role
  when "user"
    "human"
  when "assistant"
    "ai"
  end
end