Class: OmniAI::OpenAI::Thread
- Inherits:
-
Object
- Object
- OmniAI::OpenAI::Thread
show all
- Defined in:
- lib/omniai/openai/thread.rb,
lib/omniai/openai/thread/run.rb,
lib/omniai/openai/thread/runs.rb,
lib/omniai/openai/thread/text.rb,
lib/omniai/openai/thread/content.rb,
lib/omniai/openai/thread/message.rb,
lib/omniai/openai/thread/messages.rb,
lib/omniai/openai/thread/annotation.rb,
lib/omniai/openai/thread/attachment.rb
Overview
An OpenAI threads implementation.
Defined Under Namespace
Classes: Annotation, Attachment, Content, Message, Messages, Run, Runs, Text
Constant Summary
collapse
{ 'OpenAI-Beta': 'assistants=v2' }.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client: Client.new, id: nil, metadata: {}, tool_resources: {}) ⇒ Thread
Returns a new instance of Thread.
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/omniai/openai/thread.rb', line 28
def initialize(
client: Client.new,
id: nil,
metadata: {},
tool_resources: {}
)
@client = client
@id = id
@metadata = metadata
@tool_resources = tool_resources
end
|
Instance Attribute Details
#deleted ⇒ Boolean?
23
24
25
|
# File 'lib/omniai/openai/thread.rb', line 23
def deleted
@deleted
end
|
#id ⇒ String?
11
12
13
|
# File 'lib/omniai/openai/thread.rb', line 11
def id
@id
end
|
15
16
17
|
# File 'lib/omniai/openai/thread.rb', line 15
def metadata
@metadata
end
|
19
20
21
|
# File 'lib/omniai/openai/thread.rb', line 19
def tool_resources
@tool_resources
end
|
Class Method Details
.destroy!(id:, client: Client.new) ⇒ Hash
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/omniai/openai/thread.rb', line 62
def self.destroy!(id:, client: Client.new)
response = client.connection
.accept(:json)
.(HEADERS)
.delete("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{id}")
raise HTTPError, response.flush unless response.status.ok?
response.parse
end
|
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/omniai/openai/thread.rb', line 48
def self.find(id:, client: Client.new)
response = client.connection
.accept(:json)
.(HEADERS)
.get("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{id}")
raise HTTPError, response.flush unless response.status.ok?
parse(data: response.parse)
end
|
Instance Method Details
88
89
90
91
92
93
94
|
# File 'lib/omniai/openai/thread.rb', line 88
def destroy!
raise OmniAI::Error, 'cannot destroy a non-persisted thread' unless @id
data = self.class.destroy!(id: @id, client: @client)
@deleted = data['deleted']
self
end
|
#inspect ⇒ String
41
42
43
|
# File 'lib/omniai/openai/thread.rb', line 41
def inspect
"#<#{self.class.name} id=#{@id.inspect}>"
end
|
97
98
99
|
# File 'lib/omniai/openai/thread.rb', line 97
def messages
Messages.new(client: @client, thread: self)
end
|
102
103
104
|
# File 'lib/omniai/openai/thread.rb', line 102
def runs
Runs.new(client: @client, thread: self)
end
|
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/omniai/openai/thread.rb', line 75
def save!
response = @client.connection
.accept(:json)
.(HEADERS)
.post("/#{OmniAI::OpenAI::Client::VERSION}/threads#{"/#{@id}" if @id}", json: payload)
raise HTTPError, response.flush unless response.status.ok?
parse(data: response.parse)
self
end
|