openai-mapper 0.1.0 → 0.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.diffend.yml +3 -0
- data/.rubocop.yml +2 -3
- data/README.md +127 -16
- data/lib/openai/images/create.rb +2 -2
- data/lib/openai/images/edit.rb +2 -2
- data/lib/openai/images/variations.rb +48 -0
- data/lib/openai/mapper/annotation.rb +10 -0
- data/lib/openai/mapper/assistant.rb +31 -0
- data/lib/openai/mapper/assistant_file.rb +19 -0
- data/lib/openai/mapper/assistant_files.rb +21 -0
- data/lib/openai/mapper/assistants.rb +21 -0
- data/lib/openai/mapper/categories.rb +32 -0
- data/lib/openai/mapper/category_scores.rb +31 -0
- data/lib/openai/mapper/chat/completion_chunk.rb +2 -0
- data/lib/openai/mapper/chat/completions.rb +3 -1
- data/lib/openai/mapper/content.rb +17 -0
- data/lib/openai/mapper/delete.rb +17 -0
- data/lib/openai/mapper/embedding.rb +17 -0
- data/lib/openai/mapper/embeddings.rb +19 -0
- data/lib/openai/mapper/file.rb +19 -11
- data/lib/openai/mapper/files/list.rb +17 -0
- data/lib/openai/mapper/image_file.rb +13 -0
- data/lib/openai/mapper/moderation.rb +17 -0
- data/lib/openai/mapper/moderation_results.rb +17 -0
- data/lib/openai/mapper/text.rb +15 -0
- data/lib/openai/mapper/thread.rb +19 -0
- data/lib/openai/mapper/thread_message.rb +31 -0
- data/lib/openai/mapper/tool.rb +13 -0
- data/lib/openai/request/embedding.rb +9 -0
- data/lib/openai/request/images/{variation.rb → variations.rb} +1 -1
- data/lib/openai/version.rb +1 -1
- data/lib/openai.rb +1 -0
- data/openai-mapper.gemspec +6 -7
- metadata +39 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09785aab43c3391a9583dfc1a0b7c52d29b0f8ddac93e8ac5005b8729a48cbd3'
|
4
|
+
data.tar.gz: 7606d4e7d724ccb55781c7eefcbc35c35f009c5133c1896ec4cb41a90374362d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfe078628093ab50235d4b708ddf288108a8f17331a85703eb8519dc39d08d89ebe8ea405fcf08a845408bfa3ea1263a64f159940f5b151540b9f474444c6a49
|
7
|
+
data.tar.gz: 0ffc8ca7f584e923ac9cf6761f4c4adc912fd6815d5aeccbe35379a5b1640044fd7f2525b10be1f6726e86698000ae193c59a798a18309846b7a0a9ddb90b360
|
data/.diffend.yml
ADDED
data/.rubocop.yml
CHANGED
@@ -17,7 +17,6 @@ require:
|
|
17
17
|
- rubocop-rspec
|
18
18
|
- rubocop-rake
|
19
19
|
- rubocop-performance
|
20
|
-
- rubocop-packs
|
21
20
|
|
22
21
|
inherit_gem:
|
23
22
|
standard: config/base.yml
|
@@ -30,11 +29,11 @@ AllCops:
|
|
30
29
|
- vendor/**/*
|
31
30
|
TargetRubyVersion: 3.2
|
32
31
|
NewCops: enable
|
33
|
-
|
32
|
+
|
34
33
|
|
35
34
|
RSpec:
|
36
35
|
Enabled: true # enable rubocop-rspec cops
|
37
|
-
|
36
|
+
|
38
37
|
RSpec/DescribeClass:
|
39
38
|
Enabled: false # ignore missing comments on classes
|
40
39
|
|
data/README.md
CHANGED
@@ -1,35 +1,146 @@
|
|
1
1
|
# Openai::Mapper
|
2
2
|
|
3
|
-
|
3
|
+
OpenAI client and question/answer mapper.
|
4
4
|
|
5
|
-
|
5
|
+
Most of API requests are covered, others in progress...
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add to the Gemfile
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
11
|
+
```
|
12
|
+
gem "openai-mapper"
|
13
|
+
```
|
18
14
|
|
19
15
|
## Usage
|
20
16
|
|
21
|
-
|
17
|
+
Set environment variables:
|
18
|
+
- `OPENAI_TOKEN` OpenAI secret token
|
19
|
+
- `OPENAI_ORGANIZATION` (Optional) OpenAI organization token
|
20
|
+
|
21
|
+
### Simple chat-completion
|
22
|
+
|
23
|
+
```Ruby
|
24
|
+
question = {
|
25
|
+
model: "gpt-3.5-turbo",
|
26
|
+
messages: [
|
27
|
+
::Openai::Mapper::Message.new(
|
28
|
+
role: "system",
|
29
|
+
content: "Hello from openai-mapper: https://github.com/sbezugliy/openai-mapper"
|
30
|
+
),
|
31
|
+
::Openai::Mapper::Message.new(
|
32
|
+
role: "user",
|
33
|
+
content: "Hello!"
|
34
|
+
)
|
35
|
+
]
|
36
|
+
}
|
37
|
+
|
38
|
+
chat_completion = Openai::Chat::Completions.new
|
39
|
+
answer = chat_completion.request(question)
|
40
|
+
```
|
41
|
+
|
42
|
+
It returns `Openai::Mapper::Chat::Completions` object.
|
43
|
+
|
44
|
+
JSON answer object example:
|
45
|
+
```JSON
|
46
|
+
{
|
47
|
+
"id": "chatcmpl-8EwrQEw3dxpnPxalQhjoqljGS46NW",
|
48
|
+
"object": "chat.completion",
|
49
|
+
"created": 1698573544,
|
50
|
+
"model": "gpt-3.5-turbo-0613",
|
51
|
+
"choices": [
|
52
|
+
{
|
53
|
+
"index": 0,
|
54
|
+
"message": {
|
55
|
+
"role": "assistant",
|
56
|
+
"content": "Hello there! How can"
|
57
|
+
},
|
58
|
+
"finish_reason": "length"
|
59
|
+
}
|
60
|
+
],
|
61
|
+
"usage": {
|
62
|
+
"prompt_tokens": 33,
|
63
|
+
"completion_tokens": 5,
|
64
|
+
"total_tokens": 38
|
65
|
+
}
|
66
|
+
}
|
67
|
+
```
|
68
|
+
|
69
|
+
### Image generation
|
70
|
+
|
71
|
+
#### Image by text question
|
72
|
+
Image may be generated as an `base64` binary and image file.
|
73
|
+
|
74
|
+
```Ruby
|
75
|
+
question = "technopunk"
|
76
|
+
|
77
|
+
dalle = Openai::Images::Create.new
|
78
|
+
dalle.request(
|
79
|
+
prompt: question,
|
80
|
+
n: 10,
|
81
|
+
size: "1024x1024",
|
82
|
+
user: "s.bezugliy@codenv.top",
|
83
|
+
response_format: "b64_json"
|
84
|
+
)
|
85
|
+
|
86
|
+
dalle.data.data.each.with_index do |image, index|
|
87
|
+
f = File.new(File.join(__dir__, "../output/#{dalle.data.created}-#{index}.png"), "w")
|
88
|
+
f.write(Base64.decode64(image.b64_json))
|
89
|
+
f.close
|
90
|
+
end
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Edit Image with text instructions
|
94
|
+
|
95
|
+
```Ruby
|
96
|
+
question = "Replace heads with a teapot"
|
97
|
+
|
98
|
+
dalle = Openai::Images::Edit.new
|
99
|
+
dalle.request(
|
100
|
+
image: "origin1.png",
|
101
|
+
prompt: question,
|
102
|
+
n: 10,
|
103
|
+
size: "1024x1024",
|
104
|
+
response_format: "b64_json",
|
105
|
+
user: "s.bezugliy@codenv.top"
|
106
|
+
)
|
107
|
+
|
108
|
+
dalle.data.data.each.with_index do |image, index|
|
109
|
+
f = File.new(File.join(__dir__, "../output/edits/#{dalle.data.created}-#{index}.png"), "w")
|
110
|
+
f.write(Base64.decode64(image.b64_json))
|
111
|
+
f.close
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
#### Image variations by origin image
|
116
|
+
|
117
|
+
Pass original image
|
118
|
+
|
119
|
+
```Ruby
|
120
|
+
dalle = Openai::Images::Variations.new
|
121
|
+
dalle.request(
|
122
|
+
image: "origin1.png",
|
123
|
+
n: 10,
|
124
|
+
size: "1024x1024",
|
125
|
+
response_format: "b64_json",
|
126
|
+
user: "s.bezugliy@codenv.top"
|
127
|
+
)
|
128
|
+
|
129
|
+
dalle.data.data.each.with_index do |image, index|
|
130
|
+
f = File.new(File.join(__dir__, "../output/variations/#{dalle.data.created}-#{index}.png"), "w")
|
131
|
+
f.write(Base64.decode64(image.b64_json))
|
132
|
+
f.close
|
133
|
+
end
|
134
|
+
```
|
22
135
|
|
23
136
|
## Development
|
24
137
|
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
26
|
-
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
138
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
139
|
|
29
140
|
## Contributing
|
30
141
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
142
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sbezugliy/openai-mapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sbezugliy/openai-mapper/blob/main/CODE_OF_CONDUCT.md).
|
32
143
|
|
33
144
|
## Code of Conduct
|
34
145
|
|
35
|
-
Everyone interacting in the Openai::Mapper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
146
|
+
Everyone interacting in the Openai::Mapper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sbezugliy/openai-mapper/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/openai/images/create.rb
CHANGED
@@ -8,10 +8,10 @@ module Openai
|
|
8
8
|
super()
|
9
9
|
end
|
10
10
|
|
11
|
-
def request(**
|
11
|
+
def request(**)
|
12
12
|
@response = @connection.post(
|
13
13
|
path: @path,
|
14
|
-
body: ::Openai::Request::Images::Create.new(**
|
14
|
+
body: ::Openai::Request::Images::Create.new(**).to_json
|
15
15
|
)
|
16
16
|
@data = ::Openai::Mapper::Images::List.from_json(@response.body)
|
17
17
|
end
|
data/lib/openai/images/edit.rb
CHANGED
@@ -10,11 +10,11 @@ module Openai
|
|
10
10
|
super()
|
11
11
|
end
|
12
12
|
|
13
|
-
def request(**
|
13
|
+
def request(**)
|
14
14
|
@response = @connection.post(
|
15
15
|
path: @path,
|
16
16
|
headers: multipart_headers,
|
17
|
-
body: multipart_body(::Openai::Request::Images::Edit.new(**
|
17
|
+
body: multipart_body(::Openai::Request::Images::Edit.new(**))
|
18
18
|
).tap { |r| puts r }
|
19
19
|
@data = ::Openai::Mapper::Images::List.from_json(@response.body)
|
20
20
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Images
|
5
|
+
class Variations < ::Openai::Resource::Api
|
6
|
+
def initialize
|
7
|
+
@path = "/v1/images/variations"
|
8
|
+
@boundary = ::SecureRandom.hex(4)
|
9
|
+
|
10
|
+
super()
|
11
|
+
end
|
12
|
+
|
13
|
+
def request(**)
|
14
|
+
@response = @connection.post(
|
15
|
+
path: @path,
|
16
|
+
headers: multipart_headers,
|
17
|
+
body: multipart_body(::Openai::Request::Images::Variations.new(**))
|
18
|
+
).tap { |r| puts r }
|
19
|
+
@data = ::Openai::Mapper::Images::List.from_json(@response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def multipart_headers
|
25
|
+
{
|
26
|
+
"Content-Type" => %(multipart/form-data; boundary="#{@boundary}"),
|
27
|
+
"Authorization" => "Bearer #{ACCESS_TOKEN}"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def multipart_body(params)
|
32
|
+
body = ""
|
33
|
+
body << attach_image("image", "image.png", read_image(params.image))
|
34
|
+
body << multipart_fields(params)
|
35
|
+
body << "--#{@boundary}--#{Excon::CR_NL}"
|
36
|
+
body
|
37
|
+
end
|
38
|
+
|
39
|
+
def multipart_fields(params)
|
40
|
+
body = multipart_field("n", params.n)
|
41
|
+
body << multipart_field("size", params.size)
|
42
|
+
body << multipart_field("response_format", params.response_format)
|
43
|
+
body << multipart_field("user", params.user)
|
44
|
+
body
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Assistant < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :object, ::Shale::Type::String, default: -> { "assistant" }
|
8
|
+
attribute :created_at, ::Shale::Type::Time
|
9
|
+
attribute :name, ::Shale::Type::String
|
10
|
+
attribute :description, ::Shale::Type::String, default: -> {}
|
11
|
+
attribute :model, ::Shale::Type::String
|
12
|
+
attribute :instructions, ::Shale::Type::String, default: -> {}
|
13
|
+
attribute :tools, ::Openai::Mapper::Tool, collection: true
|
14
|
+
attribute :file_ids, ::Shale::Type::String, collection: true
|
15
|
+
attribute :metadata, ::Shale::Type::String
|
16
|
+
|
17
|
+
json do
|
18
|
+
map "id", to: :id
|
19
|
+
map "object", to: :object
|
20
|
+
map "created_at", using: {from: :from_timestamp, to: :to_timestamp}
|
21
|
+
map "name", to: :name
|
22
|
+
map "description", to: :description
|
23
|
+
map "model", to: :model
|
24
|
+
map "instructions", to: :instructions
|
25
|
+
map "tools", to: :tools
|
26
|
+
map "file_ids", to: :file_ids
|
27
|
+
map "metadata", to: :metadata
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class AssistantFile < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :object, ::Shale::Type::String, default: -> { "assistant.file" }
|
8
|
+
attribute :created_at, ::Shale::Type::Time
|
9
|
+
attribute :assistant_id, ::Shale::Type::String
|
10
|
+
|
11
|
+
json do
|
12
|
+
map "id", to: :id
|
13
|
+
map "object", to: :object
|
14
|
+
map "created_at", using: {from: :from_timestamp, to: :to_timestamp}
|
15
|
+
map "assistant_id", to: :assistant_id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class AssistantFiles < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :object, ::Shale::Type::String, default: -> { "embedding" }
|
7
|
+
attribute :data, ::Openai::Mapper::AssistantFile, collection: true
|
8
|
+
attribute :first_id, ::Shale::Type::String
|
9
|
+
attribute :last_id, ::Shale::Type::String
|
10
|
+
attribute :has_more, ::Shale::Type::Boolean
|
11
|
+
|
12
|
+
json do
|
13
|
+
map "object", to: :object
|
14
|
+
map "data", to: :data
|
15
|
+
map "first_id", to: :first_id
|
16
|
+
map "last_id", to: :last_id
|
17
|
+
map "has_more", to: :has_more
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Assistants < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :object, ::Shale::Type::String, default: -> { "embedding" }
|
7
|
+
attribute :data, ::Openai::Mapper::Assistant, collection: true
|
8
|
+
attribute :first_id, ::Shale::Type::String
|
9
|
+
attribute :last_id, ::Shale::Type::String
|
10
|
+
attribute :has_more, ::Shale::Type::Boolean
|
11
|
+
|
12
|
+
json do
|
13
|
+
map "object", to: :object
|
14
|
+
map "data", to: :data
|
15
|
+
map "first_id", to: :first_id
|
16
|
+
map "last_id", to: :last_id
|
17
|
+
map "has_more", to: :has_more
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Categories < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :sexual, ::Shale::Type::Boolean
|
7
|
+
attribute :hate, ::Shale::Type::Boolean
|
8
|
+
attribute :harassment, ::Shale::Type::Boolean
|
9
|
+
attribute :self_harm, ::Shale::Type::Boolean
|
10
|
+
attribute :sexual_minors, ::Shale::Type::Boolean
|
11
|
+
attribute :hate_threatening, ::Shale::Type::Boolean
|
12
|
+
attribute :violence_graphic, ::Shale::Type::Boolean
|
13
|
+
attribute :self_harm_intent, ::Shale::Type::Boolean
|
14
|
+
attribute :self_harm_instructions, ::Shale::Type::Boolean
|
15
|
+
attribute :harassment_threatening, ::Shale::Type::Boolean
|
16
|
+
attribute :violence, ::Shale::Type::Boolean
|
17
|
+
|
18
|
+
json do
|
19
|
+
map "hate", to: :hate
|
20
|
+
map "harassment", to: :harassment
|
21
|
+
map "self-harm", to: :self_harm
|
22
|
+
map "sexual/minors", to: :sexual_minors
|
23
|
+
map "hate/threatening", to: :hate_threatening
|
24
|
+
map "violence/graphic", to: :violence_graphic
|
25
|
+
map "self-harm/intent", to: :self_harm_intent
|
26
|
+
map "self-harm/instructions", to: :self_harm_instructions
|
27
|
+
map "harassment/threatening", to: :harassment_threatening
|
28
|
+
map "violence", to: :violence
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Openai
|
2
|
+
module Mapper
|
3
|
+
class CategoryScores < ::Openai::Mapper::BaseMapper
|
4
|
+
attribute :sexual, ::Shale::Type::String
|
5
|
+
attribute :hate, ::Shale::Type::String
|
6
|
+
attribute :harassment, ::Shale::Type::String
|
7
|
+
attribute :self_harm, ::Shale::Type::String
|
8
|
+
attribute :sexual_minors, ::Shale::Type::String
|
9
|
+
attribute :hate_threatening, ::Shale::Type::String
|
10
|
+
attribute :violence_graphic, ::Shale::Type::String
|
11
|
+
attribute :self_harm_intent, ::Shale::Type::String
|
12
|
+
attribute :self_harm_instructions, ::Shale::Type::String
|
13
|
+
attribute :harassment_threatening, ::Shale::Type::String
|
14
|
+
attribute :violence, ::Shale::Type::String
|
15
|
+
|
16
|
+
json do
|
17
|
+
map "sexual", to: :sexual
|
18
|
+
map "hate", to: :hate
|
19
|
+
map "harassment", to: :harassment
|
20
|
+
map "self-harm", to: :self_harm
|
21
|
+
map "sexual/minors", to: :sexual_minors
|
22
|
+
map "hate/threatening", to: :hate_threatening
|
23
|
+
map "violence/graphic", to: :violence_graphic
|
24
|
+
map "self-harm/intent", to: :self_harm_intent
|
25
|
+
map "self-harm/instructions", to: :self_harm_instructions
|
26
|
+
map "harassment/threatening", to: :harassment_threatening
|
27
|
+
map "violence", to: :violence
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -8,6 +8,7 @@ module Openai
|
|
8
8
|
attribute :object, ::Shale::Type::String
|
9
9
|
attribute :created, ::Shale::Type::Time
|
10
10
|
attribute :model, ::Shale::Type::String
|
11
|
+
attribute :system_fingerprint, ::Shale::Type::String
|
11
12
|
attribute :choices, ::Openai::Mapper::Choices, collection: true
|
12
13
|
attribute :usage, ::Openai::Mapper::Usage
|
13
14
|
|
@@ -16,6 +17,7 @@ module Openai
|
|
16
17
|
map "object", to: :object
|
17
18
|
map "created", using: {from: :from_timestamp, to: :to_timestamp}
|
18
19
|
map "model", to: :model
|
20
|
+
map "system_fingerprint", to: :system_fingerprint
|
19
21
|
map "choices", to: :choices
|
20
22
|
map "usage", to: :usage
|
21
23
|
end
|
@@ -8,16 +8,18 @@ module Openai
|
|
8
8
|
attribute :object, ::Shale::Type::String
|
9
9
|
attribute :created, ::Shale::Type::Time
|
10
10
|
attribute :model, ::Shale::Type::String
|
11
|
+
attribute :system_fingerprint, ::Shale::Type::String
|
11
12
|
attribute :choices, ::Openai::Mapper::Choices, collection: true
|
12
13
|
attribute :usage, ::Openai::Mapper::Usage
|
13
14
|
|
14
15
|
json do
|
15
16
|
map "id", to: :id
|
16
17
|
map "object", to: :object
|
18
|
+
map "created", using: {from: :from_timestamp, to: :to_timestamp}
|
17
19
|
map "model", to: :model
|
20
|
+
map "system_fingerprint", to: :system_fingerprint
|
18
21
|
map "choices", to: :choices
|
19
22
|
map "usage", to: :usage
|
20
|
-
map "created", using: {from: :from_timestamp, to: :to_timestamp}
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Content < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :type, ::Shale::Type::String
|
7
|
+
attribute :image_file, ::Openai::Mapper::ImageFile
|
8
|
+
attribute :text, ::Openai::Mapper::Text
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "type", to: :type
|
12
|
+
map "image_file", to: :image_file
|
13
|
+
map "text", to: :text
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Delete < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :data, ::Openai::Mapper::File, collection: true
|
7
|
+
attribute :object, ::Shale::Type::String
|
8
|
+
attribute :deleted, ::Shale::Type::Boolean
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "data", to: :data
|
12
|
+
map "object", to: :object
|
13
|
+
map "deleted", to: :deleted
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Embedding < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :object, ::Shale::Type::String, default: -> { "embedding" }
|
7
|
+
attribute :arguments, ::Shale::Type::Float, collection: true
|
8
|
+
attribute :index, ::Shale::Type::String, default: -> { 0 }
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "name", to: :name
|
12
|
+
map "arguments", to: :arguments
|
13
|
+
map "index", to: :index
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Embeddings < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :object, ::Shale::Type::String, default: -> { "embedding" }
|
7
|
+
attribute :data, ::Openai::Mapper::Embedding, collection: true
|
8
|
+
attribute :model, ::Shale::Type::String
|
9
|
+
attribute :usage, ::Openai::Mapper::Usage
|
10
|
+
|
11
|
+
json do
|
12
|
+
map "object", to: :object
|
13
|
+
map "data", to: :data
|
14
|
+
map "model", to: :model
|
15
|
+
map "usage", to: :usage
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/openai/mapper/file.rb
CHANGED
@@ -3,17 +3,25 @@
|
|
3
3
|
module Openai
|
4
4
|
module Mapper
|
5
5
|
class File < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :object, ::Shale::Type::String, default: -> { "file" }
|
8
|
+
attribute :bytes, ::Shale::Type::Integer
|
9
|
+
attribute :created_at, ::Shale::Type::Time
|
10
|
+
attribute :filename, ::Shale::Type::String
|
11
|
+
attribute :purpose, ::Shale::Type::String
|
12
|
+
attribute :status, ::Shale::Type::String, default: -> {}
|
13
|
+
attribute :status_details, ::Shale::Type::String, default: -> {}
|
14
|
+
|
15
|
+
json do
|
16
|
+
map "id", to: :id
|
17
|
+
map "object", to: :object
|
18
|
+
map "bytes", to: :bytes
|
19
|
+
map "created_at", using: {from: :from_timestamp, to: :to_timestamp}
|
20
|
+
map "filename", to: :filename
|
21
|
+
map "purpose", to: :purpose
|
22
|
+
map "status", to: :status
|
23
|
+
map "status_details", to: :status_details
|
24
|
+
end
|
6
25
|
end
|
7
26
|
end
|
8
27
|
end
|
9
|
-
|
10
|
-
# {
|
11
|
-
# "id": "file-abc123",
|
12
|
-
# "object": "file",
|
13
|
-
# "bytes": 120000,
|
14
|
-
# "created_at": 1677610602,
|
15
|
-
# "filename": "my_file.jsonl",
|
16
|
-
# "purpose": "fine-tune",
|
17
|
-
# "status": "uploaded",
|
18
|
-
# "status_details": null
|
19
|
-
# }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
module Files
|
6
|
+
class List < ::Openai::Mapper::BaseMapper
|
7
|
+
attribute :data, ::Openai::Mapper::File, collection: true
|
8
|
+
attribute :object, ::Shale::Type::String, default: -> { "list" }
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "data", to: :data
|
12
|
+
map "object", to: :object
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Moderation < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :model, ::Shale::Type::String
|
8
|
+
attribute :results, ::Openai::Mapper::ModerationResults, collection: true
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "data", to: :data
|
12
|
+
map "object", to: :object
|
13
|
+
map "deleted", to: :deleted
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class ModerationResults < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :flagged, ::Shale::Type::Boolean
|
7
|
+
attribute :categories, ::Openai::Mapper::Categories
|
8
|
+
attribute :category_scores, ::Openai::Mapper::CategoryScores
|
9
|
+
|
10
|
+
json do
|
11
|
+
map "flagged", to: :flagged
|
12
|
+
map "categories", to: :categories
|
13
|
+
map "category_scores", to: :category_scores
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Text < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :value, ::Shale::Type::String
|
7
|
+
attribute :annotations, ::Openai::Mapper::Annotation, collection: true
|
8
|
+
|
9
|
+
json do
|
10
|
+
map "value", to: :value
|
11
|
+
map "annotations", to: :annotations
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class Thread < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :object, ::Shale::Type::String, default: -> { "assistant" }
|
8
|
+
attribute :created_at, ::Shale::Type::Time
|
9
|
+
attribute :metadata, ::Shale::Type::String
|
10
|
+
|
11
|
+
json do
|
12
|
+
map "id", to: :id
|
13
|
+
map "object", to: :object
|
14
|
+
map "created_at", using: {from: :from_timestamp, to: :to_timestamp}
|
15
|
+
map "metadata", to: :metadata
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
3
|
+
module Openai
|
4
|
+
module Mapper
|
5
|
+
class ThreadMessage < ::Openai::Mapper::BaseMapper
|
6
|
+
attribute :id, ::Shale::Type::String
|
7
|
+
attribute :object, ::Shale::Type::String, default: -> { "thread.message" }
|
8
|
+
attribute :created_at, ::Shale::Type::Time
|
9
|
+
attribute :thread_id, ::Shale::Type::String
|
10
|
+
attribute :role, ::Shale::Type::String, default: -> { "assistant" }
|
11
|
+
attribute :content, ::Openai::Mapper::Content, collection: true
|
12
|
+
attribute :assistant_id, ::Shale::Type::String
|
13
|
+
attribute :file_ids, ::Shale::Type::String, collection: true
|
14
|
+
attribute :run_id, ::Shale::Type::String
|
15
|
+
attribute :metadata, ::Shale::Type::String
|
16
|
+
|
17
|
+
json do
|
18
|
+
map "id", to: :id
|
19
|
+
map "object", to: :object
|
20
|
+
map "created_at", using: {from: :from_timestamp, to: :to_timestamp}
|
21
|
+
map "thread_id", to: :thread_id
|
22
|
+
map "role", to: :role
|
23
|
+
map "content", to: :content
|
24
|
+
map "assistant_id", to: :assistant_id
|
25
|
+
map "file_ids", to: :file_ids
|
26
|
+
map "run_id", to: :run_ids
|
27
|
+
map "metadata", to: :metadata
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Openai
|
4
4
|
module Request
|
5
5
|
module Images
|
6
|
-
class
|
6
|
+
class Variations < ::Openai::Mapper::BaseMapper
|
7
7
|
attribute :image, ::Shale::Type::String
|
8
8
|
attribute :n, ::Shale::Type::Integer, default: -> { 1 }
|
9
9
|
attribute :response_format, ::Shale::Type::String, default: -> { "url" }
|
data/lib/openai/version.rb
CHANGED
data/lib/openai.rb
CHANGED
data/openai-mapper.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Openai::VERSION
|
8
8
|
spec.authors = ["Sergey Bezugliy"]
|
9
9
|
spec.email = ["s.bezugliy@gmail.com"]
|
10
|
-
spec.licenses
|
10
|
+
spec.licenses = ["MIT"]
|
11
11
|
|
12
12
|
spec.summary = "OpenAI resources API client and object mapper"
|
13
13
|
spec.description = "OpenAI resources API client and object mapper"
|
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
25
|
spec.files = Dir.chdir(__dir__) do
|
26
26
|
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.end_with?(".gem") || (File.expand_path(f) == __FILE__) ||
|
28
28
|
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile output])
|
29
29
|
end
|
30
30
|
end
|
@@ -49,16 +49,15 @@ Gem::Specification.new do |spec|
|
|
49
49
|
spec.add_development_dependency "rubocop", "~> 1.56.0"
|
50
50
|
spec.add_development_dependency "rubocop-capybara"
|
51
51
|
spec.add_development_dependency "rubocop-factory_bot"
|
52
|
-
spec.add_development_dependency "rubocop-performance"
|
52
|
+
spec.add_development_dependency "rubocop-performance"
|
53
53
|
spec.add_development_dependency "rubocop-rake"
|
54
54
|
spec.add_development_dependency "rubocop-rspec"
|
55
|
-
spec.add_development_dependency "rubocop-packs"
|
56
55
|
spec.add_development_dependency "simplecov"
|
57
|
-
spec.add_development_dependency "standard"
|
58
|
-
spec.add_development_dependency "standard-performance"
|
56
|
+
spec.add_development_dependency "standard"
|
57
|
+
spec.add_development_dependency "standard-performance"
|
59
58
|
spec.add_development_dependency "shoulda-matchers"
|
60
59
|
spec.add_development_dependency "webmock"
|
61
|
-
spec.add_development_dependency "async-rspec"
|
60
|
+
spec.add_development_dependency "async-rspec"
|
62
61
|
|
63
62
|
spec.add_development_dependency "bundler-audit"
|
64
63
|
spec.add_development_dependency "dawnscanner"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openai-mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Bezugliy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -194,20 +194,6 @@ dependencies:
|
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: rubocop-performance
|
197
|
-
requirement: !ruby/object:Gem::Requirement
|
198
|
-
requirements:
|
199
|
-
- - "~>"
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
version: 1.18.0
|
202
|
-
type: :development
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
205
|
-
requirements:
|
206
|
-
- - "~>"
|
207
|
-
- !ruby/object:Gem::Version
|
208
|
-
version: 1.18.0
|
209
|
-
- !ruby/object:Gem::Dependency
|
210
|
-
name: rubocop-rake
|
211
197
|
requirement: !ruby/object:Gem::Requirement
|
212
198
|
requirements:
|
213
199
|
- - ">="
|
@@ -221,7 +207,7 @@ dependencies:
|
|
221
207
|
- !ruby/object:Gem::Version
|
222
208
|
version: '0'
|
223
209
|
- !ruby/object:Gem::Dependency
|
224
|
-
name: rubocop-
|
210
|
+
name: rubocop-rake
|
225
211
|
requirement: !ruby/object:Gem::Requirement
|
226
212
|
requirements:
|
227
213
|
- - ">="
|
@@ -235,7 +221,7 @@ dependencies:
|
|
235
221
|
- !ruby/object:Gem::Version
|
236
222
|
version: '0'
|
237
223
|
- !ruby/object:Gem::Dependency
|
238
|
-
name: rubocop-
|
224
|
+
name: rubocop-rspec
|
239
225
|
requirement: !ruby/object:Gem::Requirement
|
240
226
|
requirements:
|
241
227
|
- - ">="
|
@@ -266,30 +252,30 @@ dependencies:
|
|
266
252
|
name: standard
|
267
253
|
requirement: !ruby/object:Gem::Requirement
|
268
254
|
requirements:
|
269
|
-
- - "
|
255
|
+
- - ">="
|
270
256
|
- !ruby/object:Gem::Version
|
271
|
-
version: '
|
257
|
+
version: '0'
|
272
258
|
type: :development
|
273
259
|
prerelease: false
|
274
260
|
version_requirements: !ruby/object:Gem::Requirement
|
275
261
|
requirements:
|
276
|
-
- - "
|
262
|
+
- - ">="
|
277
263
|
- !ruby/object:Gem::Version
|
278
|
-
version: '
|
264
|
+
version: '0'
|
279
265
|
- !ruby/object:Gem::Dependency
|
280
266
|
name: standard-performance
|
281
267
|
requirement: !ruby/object:Gem::Requirement
|
282
268
|
requirements:
|
283
|
-
- - "
|
269
|
+
- - ">="
|
284
270
|
- !ruby/object:Gem::Version
|
285
|
-
version:
|
271
|
+
version: '0'
|
286
272
|
type: :development
|
287
273
|
prerelease: false
|
288
274
|
version_requirements: !ruby/object:Gem::Requirement
|
289
275
|
requirements:
|
290
|
-
- - "
|
276
|
+
- - ">="
|
291
277
|
- !ruby/object:Gem::Version
|
292
|
-
version:
|
278
|
+
version: '0'
|
293
279
|
- !ruby/object:Gem::Dependency
|
294
280
|
name: shoulda-matchers
|
295
281
|
requirement: !ruby/object:Gem::Requirement
|
@@ -322,16 +308,16 @@ dependencies:
|
|
322
308
|
name: async-rspec
|
323
309
|
requirement: !ruby/object:Gem::Requirement
|
324
310
|
requirements:
|
325
|
-
- - "
|
311
|
+
- - ">="
|
326
312
|
- !ruby/object:Gem::Version
|
327
|
-
version: '
|
313
|
+
version: '0'
|
328
314
|
type: :development
|
329
315
|
prerelease: false
|
330
316
|
version_requirements: !ruby/object:Gem::Requirement
|
331
317
|
requirements:
|
332
|
-
- - "
|
318
|
+
- - ">="
|
333
319
|
- !ruby/object:Gem::Version
|
334
|
-
version: '
|
320
|
+
version: '0'
|
335
321
|
- !ruby/object:Gem::Dependency
|
336
322
|
name: bundler-audit
|
337
323
|
requirement: !ruby/object:Gem::Requirement
|
@@ -381,6 +367,7 @@ executables: []
|
|
381
367
|
extensions: []
|
382
368
|
extra_rdoc_files: []
|
383
369
|
files:
|
370
|
+
- ".diffend.yml"
|
384
371
|
- ".rspec"
|
385
372
|
- ".rubocop.yml"
|
386
373
|
- CHANGELOG.md
|
@@ -394,26 +381,47 @@ files:
|
|
394
381
|
- lib/openai/fine_tune/create.rb
|
395
382
|
- lib/openai/images/create.rb
|
396
383
|
- lib/openai/images/edit.rb
|
384
|
+
- lib/openai/images/variations.rb
|
397
385
|
- lib/openai/mapper.rb
|
386
|
+
- lib/openai/mapper/annotation.rb
|
387
|
+
- lib/openai/mapper/assistant.rb
|
388
|
+
- lib/openai/mapper/assistant_file.rb
|
389
|
+
- lib/openai/mapper/assistant_files.rb
|
390
|
+
- lib/openai/mapper/assistants.rb
|
391
|
+
- lib/openai/mapper/categories.rb
|
392
|
+
- lib/openai/mapper/category_scores.rb
|
398
393
|
- lib/openai/mapper/chat/completion_chunk.rb
|
399
394
|
- lib/openai/mapper/chat/completions.rb
|
400
395
|
- lib/openai/mapper/choices.rb
|
396
|
+
- lib/openai/mapper/content.rb
|
397
|
+
- lib/openai/mapper/delete.rb
|
398
|
+
- lib/openai/mapper/embedding.rb
|
399
|
+
- lib/openai/mapper/embeddings.rb
|
401
400
|
- lib/openai/mapper/file.rb
|
401
|
+
- lib/openai/mapper/files/list.rb
|
402
402
|
- lib/openai/mapper/function_call.rb
|
403
403
|
- lib/openai/mapper/functions.rb
|
404
|
+
- lib/openai/mapper/image_file.rb
|
404
405
|
- lib/openai/mapper/images/image.rb
|
405
406
|
- lib/openai/mapper/images/list.rb
|
406
407
|
- lib/openai/mapper/message.rb
|
407
408
|
- lib/openai/mapper/model.rb
|
408
409
|
- lib/openai/mapper/model_permission.rb
|
409
410
|
- lib/openai/mapper/models.rb
|
411
|
+
- lib/openai/mapper/moderation.rb
|
412
|
+
- lib/openai/mapper/moderation_results.rb
|
413
|
+
- lib/openai/mapper/text.rb
|
414
|
+
- lib/openai/mapper/thread.rb
|
415
|
+
- lib/openai/mapper/thread_message.rb
|
416
|
+
- lib/openai/mapper/tool.rb
|
410
417
|
- lib/openai/mapper/usage.rb
|
411
418
|
- lib/openai/model.rb
|
412
419
|
- lib/openai/models.rb
|
413
420
|
- lib/openai/request/chat/completion.rb
|
421
|
+
- lib/openai/request/embedding.rb
|
414
422
|
- lib/openai/request/images/create.rb
|
415
423
|
- lib/openai/request/images/edit.rb
|
416
|
-
- lib/openai/request/images/
|
424
|
+
- lib/openai/request/images/variations.rb
|
417
425
|
- lib/openai/resource/api.rb
|
418
426
|
- lib/openai/version.rb
|
419
427
|
- openai-mapper.gemspec
|