cafe_buy 0.1.50 → 0.1.51
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_buy.rb +116 -38
- 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: 49bc96011f8df8c2209b64a155ab446ff9a41e7d78c33aa36ed16f7217591e1e
|
4
|
+
data.tar.gz: 1f636c13ada4859c45d82846ab8f26f3c5f54779cab00da079a65afd2209fc34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d43ba14d30b1fa8c51b0b726a84ff4a07482c42643da46c41745253737ac917290b8ab9b5ec31b3f4fcbb6b5281c20f4007c7b3b687261b94b653d29b7aef6bc
|
7
|
+
data.tar.gz: e27a3c4ffa964422aff1cf95bb2a738ce26751210d8516a2f3cbee3dcad84a3726098321e28e21e77e5980dfba764daa9c6399c035f908ff15eda97caf7a8fab
|
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' =>
|
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
|
@@ -2848,7 +2881,20 @@ class Wordpress
|
|
2848
2881
|
end
|
2849
2882
|
end
|
2850
2883
|
end
|
2884
|
+
|
2885
|
+
if @data['포스트설정']['gpt35'].checked? || @data['포스트설정']['gpt4turbo'].checked? || @data['포스트설정']['gpt4'].checked?
|
2886
|
+
gpt_model = if @data['포스트설정']['gpt35'].checked?
|
2887
|
+
'gpt-3.5-turbo'
|
2888
|
+
elsif @data['포스트설정']['gpt4turbo'].checked?
|
2889
|
+
'gpt-4-turbo'
|
2890
|
+
elsif @data['포스트설정']['gpt4'].checked?
|
2891
|
+
'gpt-4'
|
2892
|
+
end
|
2893
|
+
puts "선택 된 GPT model: #{gpt_model}".green
|
2894
|
+
else
|
2851
2895
|
|
2896
|
+
end
|
2897
|
+
|
2852
2898
|
if @data['포스트설정']['gpt제목'].checked?
|
2853
2899
|
gpt_title_prompt = @data['포스트설정']['gpt제목_프롬프트'].text.to_s.force_encoding('utf-8')
|
2854
2900
|
|
@@ -2856,7 +2902,7 @@ class Wordpress
|
|
2856
2902
|
gpt_title_prompt_sample = gpt_title_prompt.strip.empty? ? "프롬프트: 문장을 비슷한 길이로 ChatGPT의 멘트는 빼고 표현을 더 추가해서 하나만 만들어줘." : gpt_title_prompt
|
2857
2903
|
|
2858
2904
|
# 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)
|
2905
|
+
chat = Chat_title.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_title_prompt_sample, gpt_model)
|
2860
2906
|
|
2861
2907
|
# 메시지 요청 후 title에 저장
|
2862
2908
|
gpt_text1 = chat.message(title)
|
@@ -2910,7 +2956,7 @@ class Wordpress
|
|
2910
2956
|
gpt_content_prompt_sample = gpt_content_prompt.strip.empty? ? "프롬프트:ChatGPT의 멘트는 빼고 위 전체적인 내용의 형식을 똑같이 표현을 더 추가하고 유사어로 변경하여 하나 만들어줘! 전화번호,연락처,가격,홈페이지안내 ,상담안내 관련 문구는 유지해야해" : gpt_content_prompt
|
2911
2957
|
|
2912
2958
|
# Chat_content 객체 생성 시 api_key와 gpt_content_prompt_sample을 두 개의 인자로 전달
|
2913
|
-
chat = Chat_content.new(api_key, gpt_content_prompt_sample)
|
2959
|
+
chat = Chat_content.new(api_key, gpt_content_prompt_sample, gpt_model)
|
2914
2960
|
|
2915
2961
|
# 메시지 요청 후 content에 저장
|
2916
2962
|
gpt_text3 = chat.message(content)
|
@@ -3058,7 +3104,7 @@ class Wordpress
|
|
3058
3104
|
if @data['포스트설정']['gpt키워드'].checked?
|
3059
3105
|
gpt_keyword_prompt = @data['포스트설정']['gpt키워드_프롬프트'].text.to_s.force_encoding('utf-8')
|
3060
3106
|
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)
|
3107
|
+
chat = Chat.new(@data['포스트설정']['api_key'].text.to_s.force_encoding('utf-8'), gpt_keyword_prompt, gpt_model)
|
3062
3108
|
gpt_text = chat.message(keyword)
|
3063
3109
|
#content = content.to_s + "\n(자동생성글)\n" + gpt_text.to_s
|
3064
3110
|
content = content.to_s + "(자동생성글)" + gpt_text.to_s
|
@@ -5415,17 +5461,49 @@ class Wordpress
|
|
5415
5461
|
top 15+ aa1
|
5416
5462
|
left 0
|
5417
5463
|
}
|
5418
|
-
|
5419
|
-
|
5420
|
-
|
5464
|
+
}
|
5465
|
+
grid{
|
5466
|
+
stretchy false
|
5467
|
+
@data['포스트설정']['ChatGPT사용'] = checkbox('Chat GPT 사용하기 '){
|
5468
|
+
top 1
|
5421
5469
|
left 0
|
5422
5470
|
}
|
5423
|
-
|
5471
|
+
|
5424
5472
|
@data['포스트설정']['api_key'] = entry(){
|
5425
|
-
top
|
5473
|
+
top 1
|
5426
5474
|
left 1
|
5427
|
-
text 'api key 입력
|
5475
|
+
text 'api key 입력'
|
5428
5476
|
}
|
5477
|
+
@data['포스트설정']['gpt35'] = checkbox('GPT 3.5-turbo'){
|
5478
|
+
top 1
|
5479
|
+
left 2
|
5480
|
+
on_toggled {
|
5481
|
+
if @data['포스트설정']['gpt35'].checked?
|
5482
|
+
@data['포스트설정']['gpt4'].checked = false
|
5483
|
+
@data['포스트설정']['gpt4turbo'].checked = false
|
5484
|
+
end
|
5485
|
+
}
|
5486
|
+
}
|
5487
|
+
@data['포스트설정']['gpt4'] = checkbox('GPT 4'){
|
5488
|
+
top 1
|
5489
|
+
left 3
|
5490
|
+
on_toggled {
|
5491
|
+
if @data['포스트설정']['gpt4'].checked?
|
5492
|
+
@data['포스트설정']['gpt35'].checked = false
|
5493
|
+
@data['포스트설정']['gpt4turbo'].checked = false
|
5494
|
+
end
|
5495
|
+
}
|
5496
|
+
}
|
5497
|
+
@data['포스트설정']['gpt4turbo'] = checkbox('GPT 4-turbo'){
|
5498
|
+
top 1
|
5499
|
+
left 4
|
5500
|
+
on_toggled {
|
5501
|
+
if @data['포스트설정']['gpt4turbo'].checked?
|
5502
|
+
@data['포스트설정']['gpt35'].checked = false
|
5503
|
+
@data['포스트설정']['gpt4'].checked = false
|
5504
|
+
end
|
5505
|
+
}
|
5506
|
+
}
|
5429
5507
|
}
|
5430
5508
|
}
|
5431
5509
|
|
@@ -6151,7 +6229,7 @@ class Wordpress
|
|
6151
6229
|
@data['포스트설정']['CCL사용'].checked = false
|
6152
6230
|
@data['포스트설정']['인용구랜덤'].checked = true
|
6153
6231
|
@data['이미지설정']['글자순서'].checked = true
|
6154
|
-
|
6232
|
+
@data['포스트설정']['gpt35'].checked = true
|
6155
6233
|
}.show
|
6156
6234
|
end
|
6157
6235
|
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.
|
4
|
+
version: 0.1.51
|
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-25 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: File to Clipboard gem
|
13
13
|
email: mymin26@naver.com
|