omniai-openai 2.6.1 → 2.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- module OpenAI
5
- # An OpenAI threads implementation.
6
- class Thread
7
- HEADERS = { "OpenAI-Beta": "assistants=v2" }.freeze
8
-
9
- # @!attribute [rw] id
10
- # @return [String, nil]
11
- attr_accessor :id
12
-
13
- # @!attribute [rw] metadata
14
- # @return [Hash]
15
- attr_accessor :metadata
16
-
17
- # @!attribute [rw] tool_resources
18
- # @return [Hash]
19
- attr_accessor :tool_resources
20
-
21
- # @!attribute [rw] deleted
22
- # @return [Boolean, nil]
23
- attr_accessor :deleted
24
-
25
- # @param client [OmniAI::OpenAI::Client] optional
26
- # @param id [String]
27
- # @param metadata [String]
28
- def initialize(
29
- client: Client.new,
30
- id: nil,
31
- metadata: {},
32
- tool_resources: {}
33
- )
34
- @client = client
35
- @id = id
36
- @metadata = metadata
37
- @tool_resources = tool_resources
38
- end
39
-
40
- # @return [String]
41
- def inspect
42
- "#<#{self.class.name} id=#{@id.inspect}>"
43
- end
44
-
45
- # @param id [String] required
46
- # @param client [OmniAI::OpenAI::Client] optional
47
- # @return [OmniAI::OpenAI::Thread]
48
- def self.find(id:, client: Client.new)
49
- response = client.connection
50
- .accept(:json)
51
- .headers(HEADERS)
52
- .get("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{id}")
53
-
54
- raise HTTPError, response.flush unless response.status.ok?
55
-
56
- parse(data: response.parse)
57
- end
58
-
59
- # @param id [String] required
60
- # @param client [OmniAI::OpenAI::Client] optional
61
- # @return [Hash]
62
- def self.destroy!(id:, client: Client.new)
63
- response = client.connection
64
- .accept(:json)
65
- .headers(HEADERS)
66
- .delete("/#{OmniAI::OpenAI::Client::VERSION}/threads/#{id}")
67
-
68
- raise HTTPError, response.flush unless response.status.ok?
69
-
70
- response.parse
71
- end
72
-
73
- # @raise [HTTPError]
74
- # @return [OmniAI::OpenAI::Thread]
75
- def save!
76
- response = @client.connection
77
- .accept(:json)
78
- .headers(HEADERS)
79
- .post("/#{OmniAI::OpenAI::Client::VERSION}/threads#{"/#{@id}" if @id}", json: payload)
80
- raise HTTPError, response.flush unless response.status.ok?
81
-
82
- parse(data: response.parse)
83
- self
84
- end
85
-
86
- # @raise [OmniAI::Error]
87
- # @return [OmniAI::OpenAI::Thread]
88
- def destroy!
89
- raise OmniAI::Error, "cannot destroy a non-persisted thread" unless @id
90
-
91
- data = self.class.destroy!(id: @id, client: @client)
92
- @deleted = data["deleted"]
93
- self
94
- end
95
-
96
- # @return [OmniAI::OpenAI::Thread::Messages]
97
- def messages
98
- Messages.new(client: @client, thread: self)
99
- end
100
-
101
- # @return [OmniAI::OpenAI::Thread::Runs]
102
- def runs
103
- Runs.new(client: @client, thread: self)
104
- end
105
-
106
- private
107
-
108
- class << self
109
- private
110
-
111
- # @param data [Hash] required
112
- # @param client [OmniAI::OpenAI::Client] required
113
- # @return [OmniAI::OpenAI::Thread]
114
- def parse(data:, client: Client.new)
115
- new(
116
- client:,
117
- id: data["id"],
118
- metadata: data["metadata"],
119
- tool_resources: data["tool_resources"]
120
- )
121
- end
122
- end
123
-
124
- # @param data [Hash] required
125
- # @return [OmniAI::OpenAI::Thread]
126
- def parse(data:)
127
- @id = data["id"]
128
- @metadata = data["metadata"]
129
- @tool_resources = data["tool_resources"]
130
- end
131
-
132
- # @return [Hash]
133
- def payload
134
- {
135
- metadata: @metadata,
136
- tool_resources: @tool_resources,
137
- }.compact
138
- end
139
- end
140
- end
141
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- module OpenAI
5
- # An OpenAI scope for establishing threads.
6
- class Threads
7
- # @param client [OmniAI::OpenAI::Client] required
8
- def initialize(client:)
9
- @client = client
10
- end
11
-
12
- # @param id [String] required
13
- def find(id:)
14
- Thread.find(id:, client: @client)
15
- end
16
-
17
- # @param id [String] required
18
- def destroy!(id:)
19
- Thread.destroy!(id:, client: @client)
20
- end
21
-
22
- # @param metadata [Hash] optional
23
- # @param tool_resources [Hash] optional
24
- def build(metadata: {}, tool_resources: {})
25
- Thread.new(metadata:, tool_resources:, client: @client)
26
- end
27
- end
28
- end
29
- end