cafe_basics 0.1.50 → 0.1.52
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/lib/cafe_basics.rb +302 -148
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff9e36488c3054952fb1a1efddfa003d4dee61ca2486a0c18ea572871d6d5c6
|
4
|
+
data.tar.gz: 476445e25e0d71fda3cb4918642121515f337d9e9f59592f323cfb1696b3a251
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17fc8f553e4ff891b2ac22e3fb913b938446c2784ff2aad52afa7f306b0217ca7a747cfe0d936756d22149d6e6457ca9f3d5ae376e78430d025d39d6d5c93d25
|
7
|
+
data.tar.gz: 3843e6b48a29828279bcafe8e71c0f519a4e6bc1153a2145999ce9c4b335e42cf51f7406738bbecee65ffdc796690a43d58c059c98532b019267ae974183bbaa
|
data/lib/cafe_basics.rb
CHANGED
@@ -23,14 +23,16 @@ include AutoClickMethods
|
|
23
23
|
using Rainbow
|
24
24
|
include Glimmer
|
25
25
|
|
26
|
+
|
26
27
|
class Chat
|
27
|
-
def initialize(api_key, gpt_keyword_prompt)
|
28
|
+
def initialize(api_key, gpt_keyword_prompt, model)
|
28
29
|
@api_key = api_key
|
29
30
|
@gpt_keyword_prompt = gpt_keyword_prompt
|
31
|
+
@model = model # 모델을 인자로 받도록 수정
|
30
32
|
end
|
31
33
|
|
32
34
|
def message(keyword)
|
33
|
-
puts 'Sending request to GPT...(키워드 기반 글 생성 중...)'
|
35
|
+
puts 'Sending request to GPT...(키워드 기반 글 생성 중...)'.cyan
|
34
36
|
|
35
37
|
# "키워드 기반 글 생성 중..." 메시지 출력 스레드
|
36
38
|
thread = Thread.new do
|
@@ -54,7 +56,7 @@ class Chat
|
|
54
56
|
|
55
57
|
# 요청 데이터 설정
|
56
58
|
data = {
|
57
|
-
'model' =>
|
59
|
+
'model' => @model,
|
58
60
|
'messages' => [
|
59
61
|
{
|
60
62
|
"role" => "assistant",
|
@@ -64,9 +66,10 @@ class Chat
|
|
64
66
|
'max_tokens' => max_response_tokens # 최대 응답 토큰 설정
|
65
67
|
}
|
66
68
|
|
67
|
-
|
68
|
-
|
69
69
|
answer = ''
|
70
|
+
retry_count = 0
|
71
|
+
max_retries = 5 # 최대 재시도 횟수
|
72
|
+
|
70
73
|
begin
|
71
74
|
req = HTTP.headers(headers).post(url, :json => data)
|
72
75
|
|
@@ -77,7 +80,6 @@ class Chat
|
|
77
80
|
|
78
81
|
# 응답 내용 출력 (디버깅용)
|
79
82
|
response = JSON.parse(req.to_s)
|
80
|
-
|
81
83
|
|
82
84
|
# 응답 데이터에서 안전하게 값 추출
|
83
85
|
if response['choices'] && response['choices'][0] && response['choices'][0]['message']
|
@@ -88,14 +90,21 @@ class Chat
|
|
88
90
|
rescue => e
|
89
91
|
# 오류 메시지 출력
|
90
92
|
puts "Error occurred: #{e.message}"
|
91
|
-
|
93
|
+
if e.message.include?('502') && retry_count < max_retries
|
94
|
+
retry_count += 1
|
95
|
+
puts "Retrying... Attempt ##{retry_count}"
|
96
|
+
sleep(5) # 잠시 대기 후 재시도
|
97
|
+
retry
|
98
|
+
else
|
99
|
+
answer = "오류가 발생했습니다."
|
100
|
+
end
|
92
101
|
end
|
93
102
|
|
94
103
|
# "생성 중..." 메시지 출력 종료
|
95
104
|
thread.kill
|
96
105
|
|
97
106
|
# 결과 로그 출력
|
98
|
-
puts "Final API response ==> #{answer}"
|
107
|
+
puts "Final API response ==> #{answer}".cyan
|
99
108
|
return answer
|
100
109
|
end
|
101
110
|
|
@@ -108,16 +117,16 @@ end
|
|
108
117
|
|
109
118
|
|
110
119
|
|
111
|
-
|
112
|
-
|
113
120
|
class Chat_title
|
114
|
-
def initialize(api_key, gpt_title_prompt)
|
121
|
+
def initialize(api_key, gpt_title_prompt, model)
|
115
122
|
@api_key = api_key
|
116
123
|
@gpt_title_prompt = gpt_title_prompt
|
124
|
+
@model = model # 모델을 인자로 받도록 수정
|
117
125
|
end
|
118
126
|
|
119
127
|
def message(title)
|
120
|
-
puts 'Sending request to GPT...(제목 생성 중...)'
|
128
|
+
puts 'Sending request to GPT...(제목 생성 중...)'.cyan
|
129
|
+
|
121
130
|
# "키워드 기반 글 생성 중..." 메시지를 별도 스레드로 처리
|
122
131
|
thread = Thread.new do
|
123
132
|
while true
|
@@ -125,13 +134,15 @@ class Chat_title
|
|
125
134
|
sleep(3)
|
126
135
|
end
|
127
136
|
end
|
137
|
+
|
128
138
|
url = 'https://api.openai.com/v1/chat/completions'
|
129
139
|
headers = {
|
130
140
|
'Content-Type' => 'application/json',
|
131
141
|
'Authorization' => 'Bearer ' + @api_key
|
132
142
|
}
|
143
|
+
|
133
144
|
data = {
|
134
|
-
'model' =>
|
145
|
+
'model' => @model,
|
135
146
|
'messages' => [{
|
136
147
|
"role" => "system",
|
137
148
|
"content" => "너는 매우 친절하고 성의 있게 답변하는 AI 어시스턴트야."
|
@@ -142,11 +153,14 @@ class Chat_title
|
|
142
153
|
}]
|
143
154
|
}
|
144
155
|
|
156
|
+
answer = ''
|
157
|
+
retry_count = 0
|
158
|
+
max_retries = 5 # 최대 재시도 횟수
|
159
|
+
|
145
160
|
begin
|
146
161
|
req = HTTP.headers(headers).post(url, json: data)
|
147
162
|
|
148
163
|
response = JSON.parse(req.body.to_s)
|
149
|
-
|
150
164
|
|
151
165
|
if req.status == 429
|
152
166
|
return "API 요청 제한을 초과했습니다. 플랜 및 할당량을 확인하세요."
|
@@ -161,28 +175,37 @@ class Chat_title
|
|
161
175
|
answer ||= title # 응답이 없을 경우 기본 메시지 설정
|
162
176
|
rescue => e
|
163
177
|
puts "Error: #{e.message}"
|
164
|
-
|
178
|
+
if e.message.include?('502') && retry_count < max_retries
|
179
|
+
retry_count += 1
|
180
|
+
puts "Retrying... Attempt ##{retry_count}"
|
181
|
+
sleep(5) # 잠시 대기 후 재시도
|
182
|
+
retry
|
183
|
+
else
|
184
|
+
answer = "오류가 발생했습니다."
|
185
|
+
end
|
165
186
|
end
|
166
187
|
|
167
188
|
# "생성 중..." 메시지 출력 종료
|
168
189
|
thread.kill
|
169
190
|
|
170
|
-
puts 'API return ==> '
|
171
|
-
puts answer
|
191
|
+
puts 'API return ==> '.cyan
|
192
|
+
puts answer.cyan
|
172
193
|
answer
|
173
194
|
end
|
174
195
|
end
|
175
196
|
|
176
197
|
|
177
198
|
class Chat_content
|
178
|
-
def initialize(api_key, gpt_content_prompt)
|
199
|
+
def initialize(api_key, gpt_content_prompt, model)
|
179
200
|
@api_key = api_key
|
180
201
|
@gpt_content_prompt = gpt_content_prompt
|
202
|
+
@model = model # 모델을 인자로 받도록 수정
|
181
203
|
end
|
182
204
|
|
183
205
|
def message(content)
|
184
|
-
puts '주의:GPT 특성상 원고 길이가 공백 포함 4천자를 넘기면 오류가 발생할 수 있습니다.'
|
185
|
-
puts 'Sending request to GPT...(내용 변형 중...)'
|
206
|
+
puts '주의:GPT 특성상 원고 길이가 공백 포함 4천자를 넘기면 오류가 발생할 수 있습니다.'.cyan
|
207
|
+
puts 'Sending request to GPT...(내용 변형 중...)'.cyan
|
208
|
+
|
186
209
|
# "키워드 기반 글 생성 중..." 메시지를 별도 스레드로 처리
|
187
210
|
thread = Thread.new do
|
188
211
|
while true
|
@@ -190,14 +213,15 @@ class Chat_content
|
|
190
213
|
sleep(3)
|
191
214
|
end
|
192
215
|
end
|
193
|
-
|
216
|
+
|
194
217
|
url = 'https://api.openai.com/v1/chat/completions'
|
195
218
|
headers = {
|
196
219
|
'Content-Type' => 'application/json',
|
197
220
|
'Authorization' => 'Bearer ' + @api_key
|
198
221
|
}
|
222
|
+
|
199
223
|
data = {
|
200
|
-
'model' =>
|
224
|
+
'model' => @model,
|
201
225
|
'messages' => [{
|
202
226
|
"role" => "system",
|
203
227
|
"content" => "너는 매우 친절하고 성의 있게 답변하는 AI 어시스턴트야."
|
@@ -205,16 +229,18 @@ class Chat_content
|
|
205
229
|
{
|
206
230
|
"role" => "user",
|
207
231
|
"content" => "#{@gpt_content_prompt}\n#{content}"
|
208
|
-
|
209
232
|
}]
|
210
233
|
}
|
211
234
|
|
235
|
+
answer = ''
|
236
|
+
retry_count = 0
|
237
|
+
max_retries = 5 # 최대 재시도 횟수
|
238
|
+
|
212
239
|
begin
|
213
240
|
req = HTTP.headers(headers).post(url, json: data)
|
214
241
|
|
215
242
|
response = JSON.parse(req.body.to_s)
|
216
|
-
|
217
|
-
|
243
|
+
|
218
244
|
if req.status == 429
|
219
245
|
return "API 요청 제한을 초과했습니다. 플랜 및 할당량을 확인하세요."
|
220
246
|
end
|
@@ -224,14 +250,21 @@ class Chat_content
|
|
224
250
|
answer ||= (content) # 응답이 없을 경우 기본 메시지 설정
|
225
251
|
rescue => e
|
226
252
|
puts "Error: #{e.message}"
|
227
|
-
|
253
|
+
if e.message.include?('502') && retry_count < max_retries
|
254
|
+
retry_count += 1
|
255
|
+
puts "Retrying... Attempt ##{retry_count}"
|
256
|
+
sleep(5) # 잠시 대기 후 재시도
|
257
|
+
retry
|
258
|
+
else
|
259
|
+
answer = "오류가 발생했습니다."
|
260
|
+
end
|
228
261
|
end
|
229
262
|
|
230
263
|
# "생성 중..." 메시지 출력 종료
|
231
264
|
thread.kill
|
232
265
|
|
233
|
-
puts 'API return ==> '
|
234
|
-
puts answer
|
266
|
+
puts 'API return ==> '.cyan
|
267
|
+
puts answer.cyan
|
235
268
|
answer
|
236
269
|
end
|
237
270
|
end
|
@@ -1996,83 +2029,111 @@ class Wordpress
|
|
1996
2029
|
|
1997
2030
|
|
1998
2031
|
|
1999
|
-
def
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
client = HTTPClient.new
|
2004
|
-
client.default_header = {
|
2005
|
-
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
2006
|
-
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
2007
|
-
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
2008
|
-
'Accept-Language' => 'en-US,en;q=0.9',
|
2009
|
-
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
2010
|
-
'X-Requested-With' => 'XMLHttpRequest'
|
2011
|
-
}
|
2032
|
+
def crop_image_height_under_width(path, min_crop_ratio = 0.625)
|
2033
|
+
img = Magick::Image.read(path).first
|
2034
|
+
width = img.columns
|
2035
|
+
height = img.rows
|
2012
2036
|
|
2013
|
-
retry_count = 0
|
2014
|
-
max_retries = 10
|
2015
|
-
results = []
|
2016
2037
|
|
2017
|
-
begin
|
2018
|
-
page = rand(1..15)
|
2019
|
-
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
2020
|
-
puts "Request URL: #{url}"
|
2021
|
-
res = client.get(url)
|
2022
|
-
|
2023
|
-
unless res.status == 200
|
2024
|
-
puts "HTTP Error: #{res.status}"
|
2025
|
-
raise "HTTP Error"
|
2026
|
-
end
|
2027
2038
|
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2039
|
+
if height > width
|
2040
|
+
min_height = (width * min_crop_ratio).to_i
|
2041
|
+
new_height = rand(min_height..width)
|
2042
|
+
crop_top = ((height - new_height) / 2.0).round
|
2031
2043
|
|
2032
|
-
|
2033
|
-
|
2034
|
-
regular_url = photo.dig('urls', 'regular').to_s
|
2044
|
+
cropped = img.crop(0, crop_top, width, new_height, true)
|
2045
|
+
cropped.write(path)
|
2035
2046
|
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2047
|
+
|
2048
|
+
else
|
2049
|
+
|
2050
|
+
end
|
2051
|
+
end
|
2041
2052
|
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2053
|
+
def auto_image(keyword = nil)
|
2054
|
+
# auto_image 내부에서만 crop 호출
|
2055
|
+
keyword ||= @keyword
|
2056
|
+
puts "키워드: #{keyword}"
|
2057
|
+
|
2058
|
+
client = HTTPClient.new
|
2059
|
+
client.default_header = {
|
2060
|
+
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
|
2061
|
+
'(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
|
2062
|
+
'Accept' => 'application/json, text/javascript, */*; q=0.01',
|
2063
|
+
'Accept-Language' => 'en-US,en;q=0.9',
|
2064
|
+
'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
|
2065
|
+
'X-Requested-With' => 'XMLHttpRequest'
|
2066
|
+
}
|
2067
|
+
|
2068
|
+
retry_count = 0
|
2069
|
+
max_retries = 10
|
2070
|
+
results = []
|
2071
|
+
|
2072
|
+
begin
|
2073
|
+
page = rand(1..15)
|
2074
|
+
url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
|
2075
|
+
puts "Request URL: #{url}"
|
2076
|
+
res = client.get(url)
|
2077
|
+
|
2078
|
+
unless res.status == 200
|
2079
|
+
puts "HTTP Error: #{res.status}"
|
2080
|
+
raise "HTTP Error"
|
2081
|
+
end
|
2045
2082
|
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2083
|
+
json = JSON.parse(res.body)
|
2084
|
+
results = json['results']
|
2085
|
+
mm = []
|
2049
2086
|
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2087
|
+
results.each do |photo|
|
2088
|
+
full_url = photo.dig('urls', 'full').to_s
|
2089
|
+
regular_url = photo.dig('urls', 'regular').to_s
|
2090
|
+
|
2091
|
+
if full_url.start_with?("https://images.unsplash.com/photo-") &&
|
2092
|
+
regular_url.include?("1080")
|
2093
|
+
mm << full_url
|
2094
|
+
end
|
2095
|
+
end
|
2096
|
+
|
2097
|
+
if mm.empty?
|
2098
|
+
raise "No matching image"
|
2099
|
+
end
|
2100
|
+
|
2101
|
+
selected_url = mm.sample
|
2102
|
+
destination_path = "./image/memory.png"
|
2103
|
+
Down.download(selected_url, destination: destination_path)
|
2104
|
+
puts "이미지 다운로드 완료: #{selected_url}"
|
2105
|
+
|
2106
|
+
# 오직 auto_image에서만 자르기 호출
|
2107
|
+
crop_image_height_under_width(destination_path)
|
2108
|
+
|
2109
|
+
rescue => e
|
2110
|
+
retry_count += 1
|
2111
|
+
puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
|
2112
|
+
sleep(3)
|
2113
|
+
if retry_count < max_retries
|
2114
|
+
retry
|
2115
|
+
else
|
2116
|
+
puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
|
2117
|
+
|
2118
|
+
if results && !results.empty?
|
2119
|
+
random_photo = results.sample
|
2120
|
+
fallback_url = random_photo.dig('urls', 'full')
|
2121
|
+
if fallback_url
|
2122
|
+
Down.download(fallback_url, destination: "./image/memory.png")
|
2123
|
+
puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
|
2124
|
+
crop_image_height_under_width("./image/memory.png")
|
2069
2125
|
else
|
2070
|
-
|
2071
|
-
|
2072
|
-
end
|
2126
|
+
puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
|
2127
|
+
color_image
|
2073
2128
|
end
|
2129
|
+
else
|
2130
|
+
puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
|
2131
|
+
color_image
|
2132
|
+
end
|
2074
2133
|
end
|
2075
2134
|
end
|
2135
|
+
end
|
2136
|
+
|
2076
2137
|
|
2077
2138
|
def color_image
|
2078
2139
|
color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
|
@@ -2166,57 +2227,104 @@ class Wordpress
|
|
2166
2227
|
end
|
2167
2228
|
|
2168
2229
|
|
2169
|
-
|
2230
|
+
def image_text(text1, text2)
|
2231
|
+
begin
|
2232
|
+
color = File.open('./color.ini', 'r', encoding: 'utf-8').read.split("\n").map(&:strip).reject(&:empty?)
|
2233
|
+
font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
|
2234
|
+
font2 = './fonts/' + font_files.sample
|
2235
|
+
|
2236
|
+
# 랜덤 글자색 선택
|
2237
|
+
color2 = color.sample
|
2238
|
+
|
2239
|
+
# 헬퍼 함수: 색상 문자열 '#RRGGBB' -> [R,G,B] 배열로 변환
|
2240
|
+
def hex_to_rgb(hex)
|
2241
|
+
hex = hex.delete('#')
|
2242
|
+
[hex[0..1], hex[2..3], hex[4..5]].map { |c| c.to_i(16) }
|
2243
|
+
end
|
2244
|
+
|
2245
|
+
# 헬퍼 함수: 두 RGB 색상의 차이 계산 (간단한 유클리드 거리)
|
2246
|
+
def color_distance(c1, c2)
|
2247
|
+
Math.sqrt(
|
2248
|
+
(c1[0] - c2[0])**2 +
|
2249
|
+
(c1[1] - c2[1])**2 +
|
2250
|
+
(c1[2] - c2[2])**2
|
2251
|
+
)
|
2252
|
+
end
|
2253
|
+
|
2254
|
+
# 대비가 충분히 되는 테두리 색상 선택
|
2255
|
+
max_attempts = 10
|
2256
|
+
stroke_color = nil
|
2257
|
+
base_rgb = hex_to_rgb(color2)
|
2258
|
+
|
2259
|
+
max_attempts.times do
|
2260
|
+
candidate = color.sample
|
2261
|
+
candidate_rgb = hex_to_rgb(candidate)
|
2262
|
+
dist = color_distance(base_rgb, candidate_rgb)
|
2263
|
+
|
2264
|
+
# 거리(차이) 임계값 100 (0~441 범위) — 필요시 조절 가능
|
2265
|
+
if dist > 100
|
2266
|
+
stroke_color = candidate
|
2267
|
+
break
|
2268
|
+
end
|
2269
|
+
end
|
2270
|
+
stroke_color ||= '#000000' # 만약 충분히 다른 색 없으면 검정색 기본값
|
2271
|
+
|
2272
|
+
img = Magick::Image.read('./image/memory.png').first
|
2273
|
+
draw = Magick::Draw.new
|
2274
|
+
|
2275
|
+
raw_message = "#{text1}\n#{text2}".strip
|
2276
|
+
max_width = img.columns * 0.85
|
2277
|
+
max_height = img.rows * 0.6
|
2278
|
+
|
2170
2279
|
begin
|
2171
|
-
|
2172
|
-
font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
|
2173
|
-
font2 = './fonts/' + font_files.sample
|
2174
|
-
color2 = color.sample
|
2175
|
-
|
2176
|
-
img = Magick::Image.read('./image/memory.png').first
|
2177
|
-
draw = Magick::Draw.new
|
2178
|
-
|
2179
|
-
raw_message = "#{text1}\n#{text2}".strip
|
2180
|
-
max_width = img.columns * 0.85
|
2181
|
-
max_height = img.rows * 0.6
|
2182
|
-
|
2183
|
-
begin
|
2184
|
-
size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
|
2185
|
-
rescue
|
2186
|
-
size = 30
|
2187
|
-
end
|
2188
|
-
|
2189
|
-
wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
|
2190
|
-
|
2191
|
-
if @data['이미지설정']['글자그림자'].checked?
|
2192
|
-
img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
|
2193
|
-
draw.gravity = Magick::CenterGravity
|
2194
|
-
draw.pointsize = adjusted_size
|
2195
|
-
draw.fill = '#000000'
|
2196
|
-
draw.font = font2
|
2197
|
-
end
|
2198
|
-
end
|
2199
|
-
|
2200
|
-
draw2 = Magick::Draw.new
|
2201
|
-
img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
|
2202
|
-
draw2.gravity = Magick::CenterGravity
|
2203
|
-
draw2.pointsize = adjusted_size
|
2204
|
-
draw2.fill = color2
|
2205
|
-
draw2.font = font2
|
2206
|
-
if @data['이미지설정']['글자테두리'].checked?
|
2207
|
-
draw2.stroke_width = 2
|
2208
|
-
draw2.stroke = '#000000'
|
2209
|
-
end
|
2210
|
-
end
|
2211
|
-
|
2212
|
-
img.write('./image/memory.png')
|
2280
|
+
size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
|
2213
2281
|
rescue
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2282
|
+
size = 30
|
2283
|
+
end
|
2284
|
+
|
2285
|
+
wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
|
2286
|
+
|
2287
|
+
if @data['이미지설정']['글자그림자'].checked?
|
2288
|
+
img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
|
2289
|
+
draw.gravity = Magick::CenterGravity
|
2290
|
+
draw.pointsize = adjusted_size
|
2291
|
+
draw.fill = '#000000'
|
2292
|
+
draw.font = font2
|
2293
|
+
end
|
2294
|
+
end
|
2295
|
+
|
2296
|
+
if @data['이미지설정']['글자테두리'].checked?
|
2297
|
+
draw_stroke = Magick::Draw.new
|
2298
|
+
img.annotate(draw_stroke, 0, 0, 0, 0, wrapped_message) do
|
2299
|
+
draw_stroke.gravity = Magick::CenterGravity
|
2300
|
+
draw_stroke.pointsize = adjusted_size
|
2301
|
+
draw_stroke.fill = 'none'
|
2302
|
+
draw_stroke.stroke = stroke_color
|
2303
|
+
draw_stroke.stroke_width = rand(5..10)
|
2304
|
+
draw_stroke.font = font2
|
2305
|
+
end
|
2306
|
+
end
|
2307
|
+
|
2308
|
+
draw2 = Magick::Draw.new
|
2309
|
+
img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
|
2310
|
+
draw2.gravity = Magick::CenterGravity
|
2311
|
+
draw2.pointsize = adjusted_size
|
2312
|
+
draw2.fill = color2
|
2313
|
+
draw2.stroke = 'none'
|
2314
|
+
draw2.font = font2
|
2217
2315
|
end
|
2316
|
+
|
2317
|
+
img.write('./image/memory.png')
|
2318
|
+
|
2319
|
+
rescue => e
|
2320
|
+
puts "이미지 폰트 불러오기 오류 재시도... (#{e.message})"
|
2321
|
+
sleep(3)
|
2322
|
+
retry
|
2323
|
+
end
|
2218
2324
|
end
|
2219
2325
|
|
2326
|
+
|
2327
|
+
|
2220
2328
|
def border()
|
2221
2329
|
color = File.open('./color.ini', 'r',:encoding => 'utf-8').read().split("\n")
|
2222
2330
|
img = Magick::Image.read('./image/memory.png').first
|
@@ -2498,6 +2606,19 @@ class Wordpress
|
|
2498
2606
|
end
|
2499
2607
|
end
|
2500
2608
|
|
2609
|
+
if @data['포스트설정']['gpt35'].checked? || @data['포스트설정']['gpt4turbo'].checked? || @data['포스트설정']['gpt4'].checked?
|
2610
|
+
gpt_model = if @data['포스트설정']['gpt35'].checked?
|
2611
|
+
'gpt-3.5-turbo'
|
2612
|
+
elsif @data['포스트설정']['gpt4turbo'].checked?
|
2613
|
+
'gpt-4-turbo'
|
2614
|
+
elsif @data['포스트설정']['gpt4'].checked?
|
2615
|
+
'gpt-4'
|
2616
|
+
end
|
2617
|
+
puts "선택 된 GPT model: #{gpt_model}".green
|
2618
|
+
else
|
2619
|
+
|
2620
|
+
end
|
2621
|
+
|
2501
2622
|
if @data['포스트설정']['gpt제목'].checked?
|
2502
2623
|
gpt_title_prompt = @data['포스트설정']['gpt제목_프롬프트'].text.to_s.force_encoding('utf-8')
|
2503
2624
|
|
@@ -2505,7 +2626,7 @@ class Wordpress
|
|
2505
2626
|
gpt_title_prompt_sample = gpt_title_prompt.strip.empty? ? "프롬프트: 문장을 비슷한 길이로 ChatGPT의 멘트는 빼고 표현을 더 추가해서 하나만 만들어줘." : gpt_title_prompt
|
2506
2627
|
|
2507
2628
|
# gpt_title_prompt_sample을 Chat_title 객체에 전달
|
2508
|
-
chat = Chat_title.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_title_prompt_sample)
|
2629
|
+
chat = Chat_title.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_title_prompt_sample, gpt_model)
|
2509
2630
|
|
2510
2631
|
# 메시지 요청 후 title에 저장
|
2511
2632
|
gpt_text1 = chat.message(title)
|
@@ -2559,7 +2680,7 @@ class Wordpress
|
|
2559
2680
|
gpt_content_prompt_sample = gpt_content_prompt.strip.empty? ? "프롬프트:ChatGPT의 멘트는 빼고 위 전체적인 내용의 형식을 똑같이 표현을 더 추가하고 유사어로 변경하여 하나 만들어줘! 전화번호,연락처,가격,홈페이지안내 ,상담안내 관련 문구는 유지해야해" : gpt_content_prompt
|
2560
2681
|
|
2561
2682
|
# Chat_content 객체 생성 시 api_key와 gpt_content_prompt_sample을 두 개의 인자로 전달
|
2562
|
-
chat = Chat_content.new(api_key, gpt_content_prompt_sample)
|
2683
|
+
chat = Chat_content.new(api_key, gpt_content_prompt_sample, gpt_model)
|
2563
2684
|
|
2564
2685
|
# 메시지 요청 후 content에 저장
|
2565
2686
|
gpt_text3 = chat.message(content)
|
@@ -2707,7 +2828,7 @@ class Wordpress
|
|
2707
2828
|
if @data['포스트설정']['gpt키워드'].checked?
|
2708
2829
|
gpt_keyword_prompt = @data['포스트설정']['gpt키워드_프롬프트'].text.to_s.force_encoding('utf-8')
|
2709
2830
|
gpt_keyword_prompt_sample = gpt_keyword_prompt.strip.empty? ? "프롬프트: 관련된 글을 1500자에서 2500자 사이로 만들어줘" : gpt_keyword_prompt
|
2710
|
-
chat = Chat.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_keyword_prompt)
|
2831
|
+
chat = Chat.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_keyword_prompt, gpt_model)
|
2711
2832
|
gpt_text = chat.message(keyword)
|
2712
2833
|
#content = content.to_s + "\n(자동생성글)\n" + gpt_text.to_s
|
2713
2834
|
content = content.to_s + "(자동생성글)" + gpt_text.to_s
|
@@ -5033,17 +5154,49 @@ class Wordpress
|
|
5033
5154
|
top 15+ aa1
|
5034
5155
|
left 0
|
5035
5156
|
}
|
5036
|
-
|
5037
|
-
|
5038
|
-
|
5157
|
+
}
|
5158
|
+
grid{
|
5159
|
+
stretchy false
|
5160
|
+
@data['포스트설정']['ChatGPT사용'] = checkbox('Chat GPT 사용하기 '){
|
5161
|
+
top 1
|
5039
5162
|
left 0
|
5040
5163
|
}
|
5041
|
-
|
5164
|
+
|
5042
5165
|
@data['포스트설정']['api_key'] = entry(){
|
5043
|
-
top
|
5166
|
+
top 1
|
5044
5167
|
left 1
|
5045
|
-
text 'api key 입력
|
5168
|
+
text 'api key 입력'
|
5046
5169
|
}
|
5170
|
+
@data['포스트설정']['gpt35'] = checkbox('GPT 3.5-turbo'){
|
5171
|
+
top 1
|
5172
|
+
left 2
|
5173
|
+
on_toggled {
|
5174
|
+
if @data['포스트설정']['gpt35'].checked?
|
5175
|
+
@data['포스트설정']['gpt4'].checked = false
|
5176
|
+
@data['포스트설정']['gpt4turbo'].checked = false
|
5177
|
+
end
|
5178
|
+
}
|
5179
|
+
}
|
5180
|
+
@data['포스트설정']['gpt4'] = checkbox('GPT 4'){
|
5181
|
+
top 1
|
5182
|
+
left 3
|
5183
|
+
on_toggled {
|
5184
|
+
if @data['포스트설정']['gpt4'].checked?
|
5185
|
+
@data['포스트설정']['gpt35'].checked = false
|
5186
|
+
@data['포스트설정']['gpt4turbo'].checked = false
|
5187
|
+
end
|
5188
|
+
}
|
5189
|
+
}
|
5190
|
+
@data['포스트설정']['gpt4turbo'] = checkbox('GPT 4-turbo'){
|
5191
|
+
top 1
|
5192
|
+
left 4
|
5193
|
+
on_toggled {
|
5194
|
+
if @data['포스트설정']['gpt4turbo'].checked?
|
5195
|
+
@data['포스트설정']['gpt35'].checked = false
|
5196
|
+
@data['포스트설정']['gpt4'].checked = false
|
5197
|
+
end
|
5198
|
+
}
|
5199
|
+
}
|
5047
5200
|
}
|
5048
5201
|
}
|
5049
5202
|
|
@@ -5555,6 +5708,7 @@ class Wordpress
|
|
5555
5708
|
@data['포스트설정']['CCL사용'].checked = false
|
5556
5709
|
@data['포스트설정']['인용구랜덤'].checked = true
|
5557
5710
|
@data['이미지설정']['글자순서'].checked = true
|
5711
|
+
@data['포스트설정']['gpt35'].checked = true
|
5558
5712
|
}.show
|
5559
5713
|
end
|
5560
5714
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cafe_basics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.52
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zon
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-26 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: File to Clipboard gem
|
13
13
|
email: mymin26@naver.com
|