omniai-openai 1.2.1 → 1.3.1
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.
- checksums.yaml +4 -4
- data/README.md +184 -1
- data/lib/omniai/openai/assistant.rb +185 -0
- data/lib/omniai/openai/assistants.rb +38 -0
- data/lib/omniai/openai/chat.rb +2 -0
- data/lib/omniai/openai/client.rb +26 -8
- data/lib/omniai/openai/config.rb +27 -12
- data/lib/omniai/openai/file.rb +170 -0
- data/lib/omniai/openai/files.rb +44 -0
- data/lib/omniai/openai/thread/message.rb +207 -0
- data/lib/omniai/openai/thread/messages.rb +45 -0
- data/lib/omniai/openai/thread/run.rb +213 -0
- data/lib/omniai/openai/thread/runs.rb +56 -0
- data/lib/omniai/openai/thread.rb +141 -0
- data/lib/omniai/openai/threads.rb +29 -0
- data/lib/omniai/openai/tool.rb +11 -0
- data/lib/omniai/openai/version.rb +1 -1
- metadata +13 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
module OpenAI
|
5
|
+
class Thread
|
6
|
+
# An OpenAI scope for establishing messages.
|
7
|
+
class Runs
|
8
|
+
# @param client [OmniAI::OpenAI::Client] required
|
9
|
+
# @param thread [OmniAI::OpenAI::Thread] required
|
10
|
+
def initialize(client:, thread:)
|
11
|
+
@client = client
|
12
|
+
@thread = thread
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param limit [Integer] optional
|
16
|
+
# @return [Array<OmniAI::Thread::Message>]
|
17
|
+
def all(limit:)
|
18
|
+
Run.all(thread_id: @thread.id, limit:, client: @client)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param id [String] required
|
22
|
+
# @return [OmniAI::OpenAI::Thread::Message]
|
23
|
+
def find(id:)
|
24
|
+
Run.find(id:, thread_id: @thread.id, client: @client)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param id [String] required
|
28
|
+
# @return [Hash]
|
29
|
+
def cancel!(id:)
|
30
|
+
Run.cancel!(id:, thread_id: @thread.id, client: @client)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param assistant_id [String] required
|
34
|
+
# @param model [String] optional
|
35
|
+
# @param temperature [Float] optional
|
36
|
+
# @param instructions [String] optional
|
37
|
+
# @param tools [Array<Hash>, nil] optional
|
38
|
+
# @param metadata [Hash, nil] optional
|
39
|
+
# @param client [OmniAI::OpenAI::Client] optional
|
40
|
+
# @return [OmniAI::OpenAI::Thread::Message]
|
41
|
+
def build(assistant_id:, model: nil, temperature: nil, instructions: nil, tools: nil, metadata: {})
|
42
|
+
Run.new(
|
43
|
+
assistant_id:,
|
44
|
+
thread_id: @thread.id,
|
45
|
+
model:,
|
46
|
+
temperature:,
|
47
|
+
instructions:,
|
48
|
+
tools:,
|
49
|
+
metadata:,
|
50
|
+
client: @client
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,141 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -62,10 +62,21 @@ files:
|
|
62
62
|
- Gemfile
|
63
63
|
- README.md
|
64
64
|
- lib/omniai/openai.rb
|
65
|
+
- lib/omniai/openai/assistant.rb
|
66
|
+
- lib/omniai/openai/assistants.rb
|
65
67
|
- lib/omniai/openai/chat.rb
|
66
68
|
- lib/omniai/openai/client.rb
|
67
69
|
- lib/omniai/openai/config.rb
|
70
|
+
- lib/omniai/openai/file.rb
|
71
|
+
- lib/omniai/openai/files.rb
|
68
72
|
- lib/omniai/openai/speak.rb
|
73
|
+
- lib/omniai/openai/thread.rb
|
74
|
+
- lib/omniai/openai/thread/message.rb
|
75
|
+
- lib/omniai/openai/thread/messages.rb
|
76
|
+
- lib/omniai/openai/thread/run.rb
|
77
|
+
- lib/omniai/openai/thread/runs.rb
|
78
|
+
- lib/omniai/openai/threads.rb
|
79
|
+
- lib/omniai/openai/tool.rb
|
69
80
|
- lib/omniai/openai/transcribe.rb
|
70
81
|
- lib/omniai/openai/version.rb
|
71
82
|
homepage: https://github.com/ksylvest/omniai-openai
|