wco_models 3.1.0.297 → 3.1.0.298
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/app/models/wco/ai_writer.rb +33 -0
- data/app/models/wco_email/email_template.rb +1 -1
- data/app/models/wco_email/message.rb +3 -0
- data/lib/wco_models.rb +0 -1
- metadata +2 -2
- data/lib/wco/ai_writer.rb +0 -56
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f62722438c3c27dc721d00215ab4d75ba6472cab9da0c6eb115c79c581f4414
|
|
4
|
+
data.tar.gz: 330e5c51f4223182e51c7119a26df6e040e82de2cca3f6f0b9b36bed09cd8a2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b55f74ab8ad041ab43d7b9345ba6263cd37f05d550038a4553c1dbff371226fc7e260131dff46a31963ff19539ba2190572e778986d87440417a13f8ce50180e
|
|
7
|
+
data.tar.gz: 61df52c01b5db521d013999f458a4c07ec344a307b8a52da50c32ed4e0ec2748f0c0fcaedf0f175c7d51dfc5d7eed472cd42b60370b0663ff10a50c9106cf038
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
require "httparty"
|
|
3
|
+
|
|
4
|
+
class Wco::AiWriter
|
|
5
|
+
include ::HTTParty
|
|
6
|
+
|
|
7
|
+
base_uri "https://api.openai.com"
|
|
8
|
+
|
|
9
|
+
def self.do_call(task, content)
|
|
10
|
+
response = post(
|
|
11
|
+
"/v1/chat/completions",
|
|
12
|
+
headers: {
|
|
13
|
+
"Authorization" => "Bearer #{OPENAI_API_KEY}",
|
|
14
|
+
"Content-Type" => "application/json"
|
|
15
|
+
},
|
|
16
|
+
body: {
|
|
17
|
+
model: "gpt-4o",
|
|
18
|
+
messages: [
|
|
19
|
+
{
|
|
20
|
+
role: "system",
|
|
21
|
+
content: task
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
role: "user",
|
|
25
|
+
content: content
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}.to_json
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
response.dig("choices", 0, "message", "content")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -137,7 +137,7 @@ class WcoEmail::EmailTemplate
|
|
|
137
137
|
|
|
138
138
|
SLUG_BLANK = 'blank'
|
|
139
139
|
def self.blank_template
|
|
140
|
-
out =
|
|
140
|
+
out = self.find_or_create_by({ slug: SLUG_BLANK })
|
|
141
141
|
end
|
|
142
142
|
def self.blank; self.blank_template; end
|
|
143
143
|
|
data/lib/wco_models.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wco_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.0.
|
|
4
|
+
version: 3.1.0.298
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Pudeyev
|
|
@@ -484,6 +484,7 @@ files:
|
|
|
484
484
|
- app/models/tda/option.rb
|
|
485
485
|
- app/models/tda/order.rb
|
|
486
486
|
- app/models/tda/stock.rb
|
|
487
|
+
- app/models/wco/ai_writer.rb
|
|
487
488
|
- app/models/wco/asset.rb
|
|
488
489
|
- app/models/wco/gallery.rb
|
|
489
490
|
- app/models/wco/headline.rb
|
|
@@ -778,7 +779,6 @@ files:
|
|
|
778
779
|
- lib/tasks/migrate_tasks.rake
|
|
779
780
|
- lib/tasks/office_tasks.rake
|
|
780
781
|
- lib/tasks/wp_tasks.rake
|
|
781
|
-
- lib/wco/ai_writer.rb
|
|
782
782
|
- lib/wco/engine.rb
|
|
783
783
|
- lib/wco/facebook_poster.rb
|
|
784
784
|
- lib/wco/office_worker.rb
|
data/lib/wco/ai_writer.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
# require 'httparty'
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
## OpenAI GPT3 GPT3.5 GPT4
|
|
6
|
-
##
|
|
7
|
-
class Wco::AiWriter
|
|
8
|
-
|
|
9
|
-
def self.run_prompt prompt
|
|
10
|
-
out = HTTParty.post("https://api.openai.com/v1/chat/completions", {
|
|
11
|
-
headers: {
|
|
12
|
-
"Content-Type": "application/json",
|
|
13
|
-
"Authorization": "Bearer #{OPENAI_API_KEY}",
|
|
14
|
-
},
|
|
15
|
-
body: {
|
|
16
|
-
model: 'gpt-3.5-turbo',
|
|
17
|
-
messages: [
|
|
18
|
-
{ role: "system", content: "You are a knowledgable office assistant." },
|
|
19
|
-
{ role: 'user', content: prompt },
|
|
20
|
-
] }.to_json
|
|
21
|
-
})
|
|
22
|
-
out = JSON.parse out.response.body
|
|
23
|
-
out.deep_symbolize_keys!
|
|
24
|
-
puts! out, 'chatgpt response'
|
|
25
|
-
out = out[:choices][0][:message][:content]
|
|
26
|
-
return out
|
|
27
|
-
end
|
|
28
|
-
def run_prompt p; self.class.run_prompt p; end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def self.run_headline headline
|
|
32
|
-
prompt = "Rephrase the following article title using less than 250 characters: #{headline.name}"
|
|
33
|
-
new_title = self.run_prompt prompt
|
|
34
|
-
new_title = new_title[0..255]
|
|
35
|
-
# puts! new_title, 'new_title'
|
|
36
|
-
|
|
37
|
-
prompt = "Write an article about the following topic: #{headline.name}"
|
|
38
|
-
new_body = self.run_prompt prompt
|
|
39
|
-
new_body.gsub!("\r", '')
|
|
40
|
-
new_body = new_body.split("\n\n").map { |ppp| "<p>#{ppp}</p>" }.join
|
|
41
|
-
new_body = new_body.gsub("\n", "<br />")
|
|
42
|
-
# puts! new_body[0...200], 'new_body'
|
|
43
|
-
|
|
44
|
-
report = Wco::Report.create!({
|
|
45
|
-
title: new_title,
|
|
46
|
-
# slug: new_title,
|
|
47
|
-
body: new_body,
|
|
48
|
-
author: Wco::Profile.ai_writer,
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
return report
|
|
52
|
-
end
|
|
53
|
-
def run_headline h; self.class.run_headline h; end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|