cafe_buy 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cafe_buy.rb +301 -148
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4d403ac6f2afce272b8518c9416ab90a62bc2450b0f0ecb9927950e81e99d6e
4
- data.tar.gz: 3f93799ad72b1988800510465c507d0d11a2353a09e5e1608c5ab5c3e1847256
3
+ metadata.gz: f94b7d1bcfb6264a812baed1a521a2f8f4ddf2724b49520f03db280675989019
4
+ data.tar.gz: a85ba553efe2bdc42104ca639ecc5d67035b4e74a1a87db6873ba082d1d7c4a7
5
5
  SHA512:
6
- metadata.gz: f86c9003070a2324904424b0047de0ba5a52f69328f212483d40ac3a2410524dc8bbff1bc804a5fe01e5df0dcb6b54a7df097eba00cfff68b1a6aa7c853460fa
7
- data.tar.gz: d85af1d1b0281e185c3ac15b1e9495785be96e2f351e801ea95b108d41d3d4b188efb4da25150a771ba0f9d3a7ede38b2ad7eca0f15147f3803ad670e913ade6
6
+ metadata.gz: bc56b9eff065ad14f45f3ad5711e8cf1a6a5b0c8305e587454c3ed0c4ac749e9cedb668329ff84c66596f49cffa1e50bce12d2b0af7889c939e1bc49f87c6b52
7
+ data.tar.gz: 61bccdfb975cd969708c6729066408476b70ccd79f7df844c87fbb32ac67374725e3aff811d8e7fbc8ef002f913de8184434df30b73f7d036502ae1901ddeb2e
data/lib/cafe_buy.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' => 'gpt-4',
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
- answer = "오류가 발생했습니다."
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' => 'gpt-4',
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
- answer = "오류가 발생했습니다."
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' => 'gpt-4',
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
- answer = "오류가 발생했습니다."
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
@@ -2333,84 +2366,112 @@ class Wordpress
2333
2366
 
2334
2367
 
2335
2368
 
2369
+ def crop_image_height_under_width(path, min_crop_ratio = 0.625)
2370
+ img = Magick::Image.read(path).first
2371
+ width = img.columns
2372
+ height = img.rows
2373
+
2374
+
2375
+
2376
+ if height > width
2377
+ min_height = (width * min_crop_ratio).to_i
2378
+ new_height = rand(min_height..width)
2379
+ crop_top = ((height - new_height) / 2.0).round
2380
+
2381
+ cropped = img.crop(0, crop_top, width, new_height, true)
2382
+ cropped.write(path)
2383
+
2384
+
2385
+ else
2386
+
2387
+ end
2388
+ end
2389
+
2336
2390
  def auto_image(keyword = nil)
2337
- keyword ||= @keyword
2338
- puts "키워드: #{keyword}"
2339
-
2340
- client = HTTPClient.new
2341
- client.default_header = {
2342
- 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2343
- '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2344
- 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2345
- 'Accept-Language' => 'en-US,en;q=0.9',
2346
- 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2347
- 'X-Requested-With' => 'XMLHttpRequest'
2348
- }
2391
+ # auto_image 내부에서만 crop 호출
2392
+ keyword ||= @keyword
2393
+ puts "키워드: #{keyword}"
2394
+
2395
+ client = HTTPClient.new
2396
+ client.default_header = {
2397
+ 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '\
2398
+ '(KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
2399
+ 'Accept' => 'application/json, text/javascript, */*; q=0.01',
2400
+ 'Accept-Language' => 'en-US,en;q=0.9',
2401
+ 'Referer' => "https://unsplash.com/s/photos/#{URI.encode_www_form_component(keyword)}",
2402
+ 'X-Requested-With' => 'XMLHttpRequest'
2403
+ }
2404
+
2405
+ retry_count = 0
2406
+ max_retries = 10
2407
+ results = []
2349
2408
 
2350
- retry_count = 0
2351
- max_retries = 10
2352
- results = []
2409
+ begin
2410
+ page = rand(1..15)
2411
+ url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2412
+ puts "Request URL: #{url}"
2413
+ res = client.get(url)
2414
+
2415
+ unless res.status == 200
2416
+ puts "HTTP Error: #{res.status}"
2417
+ raise "HTTP Error"
2418
+ end
2353
2419
 
2354
- begin
2355
- page = rand(1..15)
2356
- url = "https://unsplash.com/napi/search/photos?query=#{URI.encode_www_form_component(keyword)}&page=#{page}&per_page=20"
2357
- puts "Request URL: #{url}"
2358
- res = client.get(url)
2359
-
2360
- unless res.status == 200
2361
- puts "HTTP Error: #{res.status}"
2362
- raise "HTTP Error"
2363
- end
2420
+ json = JSON.parse(res.body)
2421
+ results = json['results']
2422
+ mm = []
2364
2423
 
2365
- json = JSON.parse(res.body)
2366
- results = json['results']
2367
- mm = []
2424
+ results.each do |photo|
2425
+ full_url = photo.dig('urls', 'full').to_s
2426
+ regular_url = photo.dig('urls', 'regular').to_s
2368
2427
 
2369
- results.each do |photo|
2370
- full_url = photo.dig('urls', 'full').to_s
2371
- regular_url = photo.dig('urls', 'regular').to_s
2428
+ if full_url.start_with?("https://images.unsplash.com/photo-") &&
2429
+ regular_url.include?("1080")
2430
+ mm << full_url
2431
+ end
2432
+ end
2372
2433
 
2373
- if full_url.start_with?("https://images.unsplash.com/photo-") &&
2374
- regular_url.include?("1080")
2375
- mm << full_url
2376
- end
2377
- end
2434
+ if mm.empty?
2435
+ raise "No matching image"
2436
+ end
2378
2437
 
2379
- if mm.empty?
2380
- raise "No matching image"
2381
- end
2438
+ selected_url = mm.sample
2439
+ destination_path = "./image/memory.png"
2440
+ Down.download(selected_url, destination: destination_path)
2441
+ puts "이미지 다운로드 완료: #{selected_url}"
2382
2442
 
2383
- selected_url = mm.sample
2384
- Down.download(selected_url, destination: "./image/memory.png")
2385
- puts "이미지 다운로드 완료: #{selected_url}"
2443
+ # 오직 auto_image에서만 자르기 호출
2444
+ crop_image_height_under_width(destination_path)
2386
2445
 
2387
- rescue => e
2388
- retry_count += 1
2389
- puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2390
- sleep(3)
2391
- if retry_count < max_retries
2392
- retry
2393
- else
2394
- puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2395
-
2396
- if results && !results.empty?
2397
- random_photo = results.sample
2398
- fallback_url = random_photo.dig('urls', 'full')
2399
- if fallback_url
2400
- Down.download(fallback_url, destination: "./image/memory.png")
2401
- puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2402
- else
2403
- puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2404
- color_image
2405
- end
2446
+ rescue => e
2447
+ retry_count += 1
2448
+ puts "auto_image 에러: #{e.message} (재시도 #{retry_count}/#{max_retries})"
2449
+ sleep(3)
2450
+ if retry_count < max_retries
2451
+ retry
2452
+ else
2453
+ puts "최대 재시도 초과. 조건 무시하고 랜덤 이미지 다운로드 시도..."
2454
+
2455
+ if results && !results.empty?
2456
+ random_photo = results.sample
2457
+ fallback_url = random_photo.dig('urls', 'full')
2458
+ if fallback_url
2459
+ Down.download(fallback_url, destination: "./image/memory.png")
2460
+ puts "랜덤 이미지 다운로드 완료: #{fallback_url}"
2461
+ crop_image_height_under_width("./image/memory.png")
2406
2462
  else
2407
- puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2408
- color_image
2409
- end
2463
+ puts "랜덤 이미지 URL을 찾을 수 없습니다. 단색 배경 이미지 생성합니다."
2464
+ color_image
2410
2465
  end
2466
+ else
2467
+ puts "이미지 결과가 없어 다운로드할 수 없습니다. 단색 배경 이미지 생성합니다."
2468
+ color_image
2411
2469
  end
2470
+ end
2471
+ end
2412
2472
  end
2413
2473
 
2474
+
2414
2475
  def color_image
2415
2476
  color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2416
2477
  image = Magick::Image.new(740, 740) { |k| k.background_color = color.sample }
@@ -2503,57 +2564,104 @@ class Wordpress
2503
2564
  end
2504
2565
 
2505
2566
 
2506
- def image_text(text1, text2)
2567
+ def image_text(text1, text2)
2568
+ begin
2569
+ color = File.open('./color.ini', 'r', encoding: 'utf-8').read.split("\n").map(&:strip).reject(&:empty?)
2570
+ font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2571
+ font2 = './fonts/' + font_files.sample
2572
+
2573
+ # 랜덤 글자색 선택
2574
+ color2 = color.sample
2575
+
2576
+ # 헬퍼 함수: 색상 문자열 '#RRGGBB' -> [R,G,B] 배열로 변환
2577
+ def hex_to_rgb(hex)
2578
+ hex = hex.delete('#')
2579
+ [hex[0..1], hex[2..3], hex[4..5]].map { |c| c.to_i(16) }
2580
+ end
2581
+
2582
+ # 헬퍼 함수: 두 RGB 색상의 차이 계산 (간단한 유클리드 거리)
2583
+ def color_distance(c1, c2)
2584
+ Math.sqrt(
2585
+ (c1[0] - c2[0])**2 +
2586
+ (c1[1] - c2[1])**2 +
2587
+ (c1[2] - c2[2])**2
2588
+ )
2589
+ end
2590
+
2591
+ # 대비가 충분히 되는 테두리 색상 선택
2592
+ max_attempts = 10
2593
+ stroke_color = nil
2594
+ base_rgb = hex_to_rgb(color2)
2595
+
2596
+ max_attempts.times do
2597
+ candidate = color.sample
2598
+ candidate_rgb = hex_to_rgb(candidate)
2599
+ dist = color_distance(base_rgb, candidate_rgb)
2600
+
2601
+ # 거리(차이) 임계값 100 (0~441 범위) — 필요시 조절 가능
2602
+ if dist > 100
2603
+ stroke_color = candidate
2604
+ break
2605
+ end
2606
+ end
2607
+ stroke_color ||= '#000000' # 만약 충분히 다른 색 없으면 검정색 기본값
2608
+
2609
+ img = Magick::Image.read('./image/memory.png').first
2610
+ draw = Magick::Draw.new
2611
+
2612
+ raw_message = "#{text1}\n#{text2}".strip
2613
+ max_width = img.columns * 0.85
2614
+ max_height = img.rows * 0.6
2615
+
2507
2616
  begin
2508
- color = File.open('./color.ini', 'r', :encoding => 'utf-8').read().split("\n")
2509
- font_files = Dir.entries('./fonts').select { |f| f.downcase.end_with?('.ttf') }
2510
- font2 = './fonts/' + font_files.sample
2511
- color2 = color.sample
2512
-
2513
- img = Magick::Image.read('./image/memory.png').first
2514
- draw = Magick::Draw.new
2515
-
2516
- raw_message = "#{text1}\n#{text2}".strip
2517
- max_width = img.columns * 0.85
2518
- max_height = img.rows * 0.6
2519
-
2520
- begin
2521
- size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2522
- rescue
2523
- size = 30
2524
- end
2525
-
2526
- wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2527
-
2528
- if @data['이미지설정']['글자그림자'].checked?
2529
- img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2530
- draw.gravity = Magick::CenterGravity
2531
- draw.pointsize = adjusted_size
2532
- draw.fill = '#000000'
2533
- draw.font = font2
2534
- end
2535
- end
2536
-
2537
- draw2 = Magick::Draw.new
2538
- img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2539
- draw2.gravity = Magick::CenterGravity
2540
- draw2.pointsize = adjusted_size
2541
- draw2.fill = color2
2542
- draw2.font = font2
2543
- if @data['이미지설정']['글자테두리'].checked?
2544
- draw2.stroke_width = 2
2545
- draw2.stroke = '#000000'
2546
- end
2547
- end
2548
-
2549
- img.write('./image/memory.png')
2617
+ size = rand(@data['이미지설정']['이미지글자1크기1'].text.to_i..@data['이미지설정']['이미지글자1크기2'].text.to_i)
2550
2618
  rescue
2551
- puts '이미지 폰트 불러오기 오류 재시도...'
2552
- sleep(3)
2553
- retry
2619
+ size = 30
2620
+ end
2621
+
2622
+ wrapped_message, adjusted_size = wrap_text_to_fit(draw, raw_message, max_width, max_height, font2, size)
2623
+
2624
+ if @data['이미지설정']['글자그림자'].checked?
2625
+ img.annotate(draw, 0, 0, 2, 2, wrapped_message) do
2626
+ draw.gravity = Magick::CenterGravity
2627
+ draw.pointsize = adjusted_size
2628
+ draw.fill = '#000000'
2629
+ draw.font = font2
2630
+ end
2631
+ end
2632
+
2633
+ if @data['이미지설정']['글자테두리'].checked?
2634
+ draw_stroke = Magick::Draw.new
2635
+ img.annotate(draw_stroke, 0, 0, 0, 0, wrapped_message) do
2636
+ draw_stroke.gravity = Magick::CenterGravity
2637
+ draw_stroke.pointsize = adjusted_size
2638
+ draw_stroke.fill = 'none'
2639
+ draw_stroke.stroke = stroke_color
2640
+ draw_stroke.stroke_width = rand(5..10)
2641
+ draw_stroke.font = font2
2642
+ end
2643
+ end
2644
+
2645
+ draw2 = Magick::Draw.new
2646
+ img.annotate(draw2, 0, 0, 0, 0, wrapped_message) do
2647
+ draw2.gravity = Magick::CenterGravity
2648
+ draw2.pointsize = adjusted_size
2649
+ draw2.fill = color2
2650
+ draw2.stroke = 'none'
2651
+ draw2.font = font2
2554
2652
  end
2653
+
2654
+ img.write('./image/memory.png')
2655
+
2656
+ rescue => e
2657
+ puts "이미지 폰트 불러오기 오류 재시도... (#{e.message})"
2658
+ sleep(3)
2659
+ retry
2660
+ end
2555
2661
  end
2556
2662
 
2663
+
2664
+
2557
2665
  def border()
2558
2666
  color = File.open('./color.ini', 'r',:encoding => 'utf-8').read().split("\n")
2559
2667
  img = Magick::Image.read('./image/memory.png').first
@@ -2848,7 +2956,20 @@ class Wordpress
2848
2956
  end
2849
2957
  end
2850
2958
  end
2959
+
2960
+ if @data['포스트설정']['gpt35'].checked? || @data['포스트설정']['gpt4turbo'].checked? || @data['포스트설정']['gpt4'].checked?
2961
+ gpt_model = if @data['포스트설정']['gpt35'].checked?
2962
+ 'gpt-3.5-turbo'
2963
+ elsif @data['포스트설정']['gpt4turbo'].checked?
2964
+ 'gpt-4-turbo'
2965
+ elsif @data['포스트설정']['gpt4'].checked?
2966
+ 'gpt-4'
2967
+ end
2968
+ puts "선택 된 GPT model: #{gpt_model}".green
2969
+ else
2851
2970
 
2971
+ end
2972
+
2852
2973
  if @data['포스트설정']['gpt제목'].checked?
2853
2974
  gpt_title_prompt = @data['포스트설정']['gpt제목_프롬프트'].text.to_s.force_encoding('utf-8')
2854
2975
 
@@ -2856,7 +2977,7 @@ class Wordpress
2856
2977
  gpt_title_prompt_sample = gpt_title_prompt.strip.empty? ? "프롬프트: 문장을 비슷한 길이로 ChatGPT의 멘트는 빼고 표현을 더 추가해서 하나만 만들어줘." : gpt_title_prompt
2857
2978
 
2858
2979
  # gpt_title_prompt_sample을 Chat_title 객체에 전달
2859
- chat = Chat_title.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_title_prompt_sample)
2980
+ chat = Chat_title.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_title_prompt_sample, gpt_model)
2860
2981
 
2861
2982
  # 메시지 요청 후 title에 저장
2862
2983
  gpt_text1 = chat.message(title)
@@ -2910,7 +3031,7 @@ class Wordpress
2910
3031
  gpt_content_prompt_sample = gpt_content_prompt.strip.empty? ? "프롬프트:ChatGPT의 멘트는 빼고 위 전체적인 내용의 형식을 똑같이 표현을 더 추가하고 유사어로 변경하여 하나 만들어줘! 전화번호,연락처,가격,홈페이지안내 ,상담안내 관련 문구는 유지해야해" : gpt_content_prompt
2911
3032
 
2912
3033
  # Chat_content 객체 생성 시 api_key와 gpt_content_prompt_sample을 두 개의 인자로 전달
2913
- chat = Chat_content.new(api_key, gpt_content_prompt_sample)
3034
+ chat = Chat_content.new(api_key, gpt_content_prompt_sample, gpt_model)
2914
3035
 
2915
3036
  # 메시지 요청 후 content에 저장
2916
3037
  gpt_text3 = chat.message(content)
@@ -3058,7 +3179,7 @@ class Wordpress
3058
3179
  if @data['포스트설정']['gpt키워드'].checked?
3059
3180
  gpt_keyword_prompt = @data['포스트설정']['gpt키워드_프롬프트'].text.to_s.force_encoding('utf-8')
3060
3181
  gpt_keyword_prompt_sample = gpt_keyword_prompt.strip.empty? ? "프롬프트: 관련된 글을 1500자에서 2500자 사이로 만들어줘" : gpt_keyword_prompt
3061
- chat = Chat.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_keyword_prompt)
3182
+ chat = Chat.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_keyword_prompt, gpt_model)
3062
3183
  gpt_text = chat.message(keyword)
3063
3184
  #content = content.to_s + "\n(자동생성글)\n" + gpt_text.to_s
3064
3185
  content = content.to_s + "(자동생성글)" + gpt_text.to_s
@@ -5415,17 +5536,49 @@ class Wordpress
5415
5536
  top 15+ aa1
5416
5537
  left 0
5417
5538
  }
5418
-
5419
- @data['포스트설정']['ChatGPT사용'] = checkbox('Chat GPT 사용하기'){
5420
- top 16+ aa1
5539
+ }
5540
+ grid{
5541
+ stretchy false
5542
+ @data['포스트설정']['ChatGPT사용'] = checkbox('Chat GPT 사용하기             '){
5543
+ top 1
5421
5544
  left 0
5422
5545
  }
5423
-
5546
+
5424
5547
  @data['포스트설정']['api_key'] = entry(){
5425
- top 16+ aa1
5548
+ top 1
5426
5549
  left 1
5427
- text 'api key 입력 필수!!'
5550
+ text 'api key 입력'
5428
5551
  }
5552
+ @data['포스트설정']['gpt35'] = checkbox('GPT 3.5-turbo'){
5553
+ top 1
5554
+ left 2
5555
+ on_toggled {
5556
+ if @data['포스트설정']['gpt35'].checked?
5557
+ @data['포스트설정']['gpt4'].checked = false
5558
+ @data['포스트설정']['gpt4turbo'].checked = false
5559
+ end
5560
+ }
5561
+ }
5562
+ @data['포스트설정']['gpt4'] = checkbox('GPT 4'){
5563
+ top 1
5564
+ left 3
5565
+ on_toggled {
5566
+ if @data['포스트설정']['gpt4'].checked?
5567
+ @data['포스트설정']['gpt35'].checked = false
5568
+ @data['포스트설정']['gpt4turbo'].checked = false
5569
+ end
5570
+ }
5571
+ }
5572
+ @data['포스트설정']['gpt4turbo'] = checkbox('GPT 4-turbo'){
5573
+ top 1
5574
+ left 4
5575
+ on_toggled {
5576
+ if @data['포스트설정']['gpt4turbo'].checked?
5577
+ @data['포스트설정']['gpt35'].checked = false
5578
+ @data['포스트설정']['gpt4'].checked = false
5579
+ end
5580
+ }
5581
+ }
5429
5582
  }
5430
5583
  }
5431
5584
 
@@ -6151,7 +6304,7 @@ class Wordpress
6151
6304
  @data['포스트설정']['CCL사용'].checked = false
6152
6305
  @data['포스트설정']['인용구랜덤'].checked = true
6153
6306
  @data['이미지설정']['글자순서'].checked = true
6154
-
6307
+ @data['포스트설정']['gpt35'].checked = true
6155
6308
  }.show
6156
6309
  end
6157
6310
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cafe_buy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.50
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-05-30 00:00:00.000000000 Z
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