ox-ai-workers 0.9.3 → 0.9.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/CHANGELOG.md +1 -0
- data/config/locales/ru.oxaiworkers.tool.yml +6 -2
- data/lib/oxaiworkers/tool/pixels.rb +60 -6
- data/lib/oxaiworkers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0e2cfa9b2f611dc00729dfff984e91b4b3977703d91f360f80ff4625013cccc
|
4
|
+
data.tar.gz: fe2e37c5fc822a1a661f36b421f511f24c4979962ab4d67e79912d0101ace732
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab9b3e707484c1607ad46ba9cecaedc19d9e673aa4e3a17564402e5b80e8d63617a62842176eb01aea46e29e98b9b2c6e63861cb5ad82470581fc2ba379606a6
|
7
|
+
data.tar.gz: ceba0647dbbcc2a1cde6b34963d7f3a7f6d9d0c299826bd06891c03d6501c3edb6f3e9eecc3f84c155f61bc70deb613897c8c6ae7e62c41084784b3e5688c0b8
|
data/CHANGELOG.md
CHANGED
@@ -42,6 +42,10 @@ ru:
|
|
42
42
|
generate_image:
|
43
43
|
description: 'Инструмент генерации изображений: Создает изображение на основе предоставленного текстового запроса. Если указать имя файла, изображение будет сохранено в формате png. В любом случае будет возвращен url изображения.'
|
44
44
|
prompt: 'Текстовое описание изображения для генерации'
|
45
|
-
size: 'Размер генерируемого изображения
|
46
|
-
quality: 'Качество генерируемого изображения
|
45
|
+
size: 'Размер генерируемого изображения'
|
46
|
+
quality: 'Качество генерируемого изображения'
|
47
47
|
file_name: 'Имя файла для сохранения изображения в формате png. Например: image.png'
|
48
|
+
edit_image:
|
49
|
+
description: 'Инструмент редактирования изображений: Редактирует изображение на основе предоставленного текстового запроса. Если указать имя файла, изображение будет сохранено в формате png. В любом случае будет возвращен url изображения.'
|
50
|
+
input_image: 'URL или путь к изображению для редактирования'
|
51
|
+
prompt: 'Текстовое описание действий для редактирования изображения'
|
@@ -8,9 +8,22 @@ module OxAiWorkers
|
|
8
8
|
include OxAiWorkers::DependencyHelper
|
9
9
|
include OxAiWorkers::LoadI18n
|
10
10
|
|
11
|
-
attr_accessor :worker, :url, :current_dir
|
11
|
+
attr_accessor :worker, :url, :current_dir, :image_model, :mask
|
12
12
|
|
13
|
-
|
13
|
+
MODELS = {
|
14
|
+
'dall-e-3' => {
|
15
|
+
'model' => 'dall-e-3',
|
16
|
+
'size' => %w[1024x1024 1024x1792 1792x1024],
|
17
|
+
'quality' => %w[standard hd]
|
18
|
+
},
|
19
|
+
'gpt-image-1' => {
|
20
|
+
'model' => 'gpt-image-1',
|
21
|
+
'size' => %w[1024x1024 1024x1792 1792x1024],
|
22
|
+
'quality' => %w[auto low medium high]
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
def initialize(worker:, current_dir: nil, only: nil, image_model: 'dall-e-3', mask: nil)
|
14
27
|
store_locale
|
15
28
|
|
16
29
|
init_white_list_with only
|
@@ -19,27 +32,44 @@ module OxAiWorkers
|
|
19
32
|
property :prompt, type: 'string', description: I18n.t('oxaiworkers.tool.pixels.generate_image.prompt'),
|
20
33
|
required: true
|
21
34
|
property :size, type: 'string', description: I18n.t('oxaiworkers.tool.pixels.generate_image.size'),
|
22
|
-
enum:
|
35
|
+
enum: MODELS[image_model]['size']
|
23
36
|
if current_dir.present?
|
24
37
|
property :file_name, type: 'string',
|
25
38
|
description: I18n.t('oxaiworkers.tool.pixels.generate_image.file_name'),
|
26
39
|
required: true
|
27
40
|
end
|
28
41
|
property :quality, type: 'string', description: I18n.t('oxaiworkers.tool.pixels.generate_image.quality'),
|
29
|
-
enum:
|
42
|
+
enum: MODELS[image_model]['quality']
|
30
43
|
end
|
31
44
|
|
45
|
+
# define_function :edit_image, description: I18n.t('oxaiworkers.tool.pixels.edit_image.description') do
|
46
|
+
# property :input_image, type: 'string', description: I18n.t('oxaiworkers.tool.pixels.edit_image.input_image'),
|
47
|
+
# required: true
|
48
|
+
# property :prompt, type: 'string', description: I18n.t('oxaiworkers.tool.pixels.edit_image.prompt'),
|
49
|
+
# required: true
|
50
|
+
# if current_dir.present?
|
51
|
+
# property :output_file_name, type: 'string',
|
52
|
+
# description: I18n.t('oxaiworkers.tool.pixels.generate_image.file_name'),
|
53
|
+
# required: true
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
|
32
57
|
@worker = worker
|
33
58
|
@current_dir = current_dir
|
59
|
+
@image_model = MODELS[image_model]
|
60
|
+
@mask = mask
|
34
61
|
end
|
35
62
|
|
36
|
-
def generate_image(prompt:, file_name: nil, size:
|
63
|
+
def generate_image(prompt:, file_name: nil, size: nil, quality: nil)
|
37
64
|
puts "generate_image: #{prompt}"
|
38
65
|
|
66
|
+
size ||= @image_model['size'].first
|
67
|
+
quality ||= @image_model['quality'].first
|
68
|
+
|
39
69
|
response = @worker.client.images.generate(
|
40
70
|
parameters: {
|
41
71
|
prompt:,
|
42
|
-
model: '
|
72
|
+
model: @image_model['model'],
|
43
73
|
size:,
|
44
74
|
quality:
|
45
75
|
}
|
@@ -55,6 +85,30 @@ module OxAiWorkers
|
|
55
85
|
end
|
56
86
|
end
|
57
87
|
|
88
|
+
def edit_image(input_image:, prompt:, output_file_name: nil, size: nil, mask: nil)
|
89
|
+
size ||= @image_model['size'].first
|
90
|
+
mask ||= @mask
|
91
|
+
|
92
|
+
response = @worker.client.images.edit(
|
93
|
+
parameters: {
|
94
|
+
image: input_image,
|
95
|
+
model: @image_model['model'],
|
96
|
+
prompt:,
|
97
|
+
size:,
|
98
|
+
mask:
|
99
|
+
}
|
100
|
+
)
|
101
|
+
|
102
|
+
@url = response.dig('data', 0, 'url')
|
103
|
+
revised_prompt = response.dig('data', 0, 'revised_prompt')
|
104
|
+
if output_file_name.present?
|
105
|
+
path = save_generated_image(file_name: output_file_name)
|
106
|
+
"url: #{@url}\nfile_name: #{path}\n\nrevised_prompt: #{revised_prompt}"
|
107
|
+
else
|
108
|
+
"url: #{@url}\n\nrevised_prompt: #{revised_prompt}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
58
112
|
def save_generated_image(file_name:)
|
59
113
|
unless @current_dir.present?
|
60
114
|
return 'Current directory not set for OxAiWorkers::Tool::Pixels. Please set current directory first.'
|
data/lib/oxaiworkers/version.rb
CHANGED