Class: OmniAI::OpenAI::Thread::Message
- Inherits:
-
Object
- Object
- OmniAI::OpenAI::Thread::Message
- Defined in:
- lib/omniai/openai/thread/message.rb
Overview
An OpenAI message within a thread.
Instance Attribute Summary collapse
- #assistant_id ⇒ String?
- #attachments ⇒ Array?
- #content ⇒ String, ...
- #deleted ⇒ Boolean?
- #id ⇒ String?
- #metadata ⇒ Array?
- #role ⇒ String?
- #run_id ⇒ String?
- #thread_id ⇒ String?
Class Method Summary collapse
- .all(thread_id:, limit: nil, client: Client.new) ⇒ Array<OmniAI::OpenAI::Thread::Message>
- .destroy!(thread_id:, id:, client: Client.new) ⇒ Hash
- .find(thread_id:, id:, client: Client.new) ⇒ OmniAI::OpenAI::Thread::Message
Instance Method Summary collapse
- #destroy! ⇒ OmniAI::OpenAI::Thread
-
#initialize(id: nil, assistant_id: nil, thread_id: nil, run_id: nil, role: nil, content: nil, attachments: [], metadata: {}, client: Client.new) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ String
- #save! ⇒ OmniAI::OpenAI::Thread
Constructor Details
#initialize(id: nil, assistant_id: nil, thread_id: nil, run_id: nil, role: nil, content: nil, attachments: [], metadata: {}, client: Client.new) ⇒ Message
Returns a new instance of Message.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omniai/openai/thread/message.rb', line 53 def initialize( id: nil, assistant_id: nil, thread_id: nil, run_id: nil, role: nil, content: nil, attachments: [], metadata: {}, client: Client.new ) @id = id @assistant_id = assistant_id @thread_id = thread_id @run_id = run_id @role = role @content = content @attachments = @metadata = @client = client end |
Instance Attribute Details
#assistant_id ⇒ String?
14 15 16 |
# File 'lib/omniai/openai/thread/message.rb', line 14 def assistant_id @assistant_id end |
#attachments ⇒ Array?
34 35 36 |
# File 'lib/omniai/openai/thread/message.rb', line 34 def @attachments end |
#content ⇒ String, ...
30 31 32 |
# File 'lib/omniai/openai/thread/message.rb', line 30 def content @content end |
#deleted ⇒ Boolean?
42 43 44 |
# File 'lib/omniai/openai/thread/message.rb', line 42 def deleted @deleted end |
#id ⇒ String?
10 11 12 |
# File 'lib/omniai/openai/thread/message.rb', line 10 def id @id end |
#metadata ⇒ Array?
38 39 40 |
# File 'lib/omniai/openai/thread/message.rb', line 38 def @metadata end |
#role ⇒ String?
26 27 28 |
# File 'lib/omniai/openai/thread/message.rb', line 26 def role @role end |
#run_id ⇒ String?
22 23 24 |
# File 'lib/omniai/openai/thread/message.rb', line 22 def run_id @run_id end |
#thread_id ⇒ String?
18 19 20 |
# File 'lib/omniai/openai/thread/message.rb', line 18 def thread_id @thread_id end |
Class Method Details
.all(thread_id:, limit: nil, client: Client.new) ⇒ Array<OmniAI::OpenAI::Thread::Message>
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/omniai/openai/thread/message.rb', line 105 def self.all(thread_id:, limit: nil, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .get("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{thread_id}/messages", params: { limit: }.compact) raise HTTPError, response.flush unless response.status.ok? response.parse['data'].map { |data| parse(data:, client:) } end |
.destroy!(thread_id:, id:, client: Client.new) ⇒ Hash
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/omniai/openai/thread/message.rb', line 120 def self.destroy!(thread_id:, id:, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .delete("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{thread_id}/messages/#{id}") raise HTTPError, response.flush unless response.status.ok? response.parse end |
.find(thread_id:, id:, client: Client.new) ⇒ OmniAI::OpenAI::Thread::Message
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omniai/openai/thread/message.rb', line 91 def self.find(thread_id:, id:, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .get("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{thread_id}/messages/#{id}") raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) end |
Instance Method Details
#destroy! ⇒ OmniAI::OpenAI::Thread
147 148 149 150 151 152 153 |
# File 'lib/omniai/openai/thread/message.rb', line 147 def destroy! raise OmniAI::Error, 'cannot destroy a non-persisted thread' unless @id data = self.class.destroy!(thread_id: @thread_id, id: @id, client: @client) @deleted = data['deleted'] self end |
#inspect ⇒ String
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omniai/openai/thread/message.rb', line 76 def inspect props = [ "id=#{@id.inspect}", ("assistant_id=#{@assistant_id.inspect}" if @assistant_id), ("thread_id=#{@thread_id.inspect}" if @thread_id), ("content=#{@content.inspect}" if @content), ].compact "#<#{self.class.name} #{props.join(' ')}>" end |
#save! ⇒ OmniAI::OpenAI::Thread
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/omniai/openai/thread/message.rb', line 133 def save! response = @client.connection .accept(:json) .headers(HEADERS) .post(path, json: payload) raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) self end |