Class: Luogu::OpenAI::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/luogu/openai.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessages

Returns a new instance of Messages.



86
87
88
89
# File 'lib/luogu/openai.rb', line 86

def initialize
  @messages = []
  @system = {}
end

Class Method Details

.createObject



114
115
116
# File 'lib/luogu/openai.rb', line 114

def create
  self.new
end

Instance Method Details

#assistant(text: nil, file: nil) ⇒ Object



103
104
105
106
107
# File 'lib/luogu/openai.rb', line 103

def assistant(text: nil, file: nil)
  data = text || File.read(file)
  @messages << {role: "assistant", content: data}
  self
end

#system(text: nil, file: nil) ⇒ Object



91
92
93
94
95
# File 'lib/luogu/openai.rb', line 91

def system(text: nil, file: nil)
  data = text || File.read(file)
  @system = {role: "system", content: data}
  self
end

#to_aObject



109
110
111
# File 'lib/luogu/openai.rb', line 109

def to_a
  @messages.unshift @system
end

#user(text: nil, file: nil) ⇒ Object



97
98
99
100
101
# File 'lib/luogu/openai.rb', line 97

def user(text: nil, file: nil)
  data = text || File.read(file)
  @messages << {role: "user", content: data}
  self
end