Class: GAI18n::OpenAI::Message

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Message

Returns a new instance of Message.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gai18n/openai/message.rb', line 26

def initialize(response)
  @id = response['id']
  @object = response['object']
  @created_at = response['created_at']
  @role = response['role']
  @thread_id = response['thread_id']
  @content = response['content']
  @file_ids = response['file_ids']
  @assisistant_id = response['assistant_id']
  @run_id = response['run_id']
   = response['metadata']
end

Instance Attribute Details

#assistant_idObject (readonly)

Returns the value of attribute assistant_id.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def assistant_id
  @assistant_id
end

#contentObject (readonly)

Returns the value of attribute content.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def created_at
  @created_at
end

#file_idsObject (readonly)

Returns the value of attribute file_ids.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def file_ids
  @file_ids
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def 
  
end

#objectObject (readonly)

Returns the value of attribute object.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def object
  @object
end

#roleObject (readonly)

Returns the value of attribute role.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def role
  @role
end

#run_idObject (readonly)

Returns the value of attribute run_id.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def run_id
  @run_id
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



23
24
25
# File 'lib/gai18n/openai/message.rb', line 23

def thread_id
  @thread_id
end

Class Method Details

.all(thread_id:) ⇒ Object



16
17
18
19
20
# File 'lib/gai18n/openai/message.rb', line 16

def all(thread_id:)
  openai_client = GAI18n.config.openai_client
  response = openai_client.messages.list(thread_id: thread_id)
  response['data'].map { |message| new message }
end

.create(thread_id:, content:, uploads: []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/gai18n/openai/message.rb', line 5

def create(thread_id:, content:, uploads: [])
  openai_client = GAI18n.config.openai_client
  parameters = {
    role: 'user',
    content: content
  }
  response = openai_client.messages.create thread_id: thread_id,
                                           parameters: parameters
  new response
end