wco_models 3.1.0.83 → 3.1.0.86

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 136fd63ec2289135d50625c8ee250e34de0ba12757cec2a0d535264d8b3af9b4
4
- data.tar.gz: f696b308e67bd35b454f11880fbf876d378c603983ae941396605ba0ca8e5a4a
3
+ metadata.gz: b766aa1273a9c863ee71e44e96308ac8ff2de76e4a29079bcf58a23cdc50298b
4
+ data.tar.gz: 5c032aa7fac857e68baf760863d0d3de1831de98e1cbf52397c117fa2db41454
5
5
  SHA512:
6
- metadata.gz: 125155b3a50dc0c7ae25c9dcb0f642ef3127bf13a3fa11040c91240deab4ef7bfd787d0ec73065b6c31f25a111c524637822d45bc0c6739ab8676833e826cd9d
7
- data.tar.gz: e8c8f58699d02a209e9be4bfa177a987e40d67daa22db0535ade103f55dc4874ef8fb45c412ab1da49b5723996b4c734ce5cec1f48172bb6a41a22b5b73c2bae
6
+ metadata.gz: 0f539fda62b5de3856bc7fab46585ad1ffe13be1a9f8285e70d11b2bf327d3887a2f5e63815887abb5ea79164ffc733392f6fa69d9931882428f74cacbed2dbc
7
+ data.tar.gz: 98d693ef2b7b0b762b6677e42f1ba2c414f3195b1ea00f009bf55b09e1a03618bf1164e4cef342dca3032baa34294a1c29dacc511c9595ac0b866d510924ba03
@@ -1,7 +1,4 @@
1
1
 
2
- OAT = Wco::OfficeActionTemplate
3
- OATT = Wco::OfficeActionTemplateTie
4
-
5
2
  class Wco::OfficeActionTemplatesController < Wco::ApplicationController
6
3
 
7
4
  before_action :set_lists
@@ -1,7 +1,4 @@
1
1
 
2
- OAT = Wco::OfficeActionTemplate
3
- OA = Wco::OfficeAction
4
-
5
2
  class Wco::OfficeActionsController < Wco::ApplicationController
6
3
 
7
4
  before_action :set_lists
@@ -12,7 +12,8 @@ class Wco::Headline
12
12
  field :name
13
13
  validates :name, presence: true, uniqueness: true
14
14
 
15
- belongs_to :site, class_name: 'Wco::Site'
15
+ ## @TODO: remove this entirely. 2024-01-16
16
+ belongs_to :site, class_name: 'Wco::Site', optional: true
16
17
 
17
18
  has_and_belongs_to_many :tags, class_name: 'Wco::Tag'
18
19
 
@@ -23,9 +23,25 @@ class Wco::OfficeAction
23
23
 
24
24
  field :perform_at, type: :time
25
25
 
26
+ def do_run
27
+ sch = self
28
+ sch.update!({ status: STATUS_INACTIVE })
29
+
30
+ eval( sch.tmpl.action_exe )
31
+
32
+ # schedule next actions & update the action
33
+ sch.tmpl.ties.each do |tie|
34
+ next_sch = self.class.find_or_initialize_by({
35
+ office_action_template_id: tie.next_tmpl.id,
36
+ })
37
+ next_sch.perform_at = eval(tie.next_at_exe)
38
+ next_sch.status = STATUS_ACTIVE
39
+ next_sch.save!
40
+ end
41
+ end
42
+
26
43
  def to_s
27
44
  slug
28
45
  end
29
-
30
46
  end
31
-
47
+ OA ||= Wco::OfficeAction
@@ -38,4 +38,4 @@ class Wco::OfficeActionTemplate
38
38
  end
39
39
 
40
40
  end
41
- OAT = Wco::OfficeActionTemplate
41
+ OAT ||= Wco::OfficeActionTemplate
@@ -7,10 +7,10 @@ class Wco::OfficeActionTemplateTie
7
7
  attr_accessor :to_delete
8
8
 
9
9
  belongs_to :office_action_template, class_name: 'OfficeActionTemplate', inverse_of: :ties
10
- def oat; office_action_template; end
10
+ def tmpl; office_action_template; end
11
11
 
12
12
  belongs_to :next_office_action_template, class_name: 'OfficeActionTemplate', inverse_of: :prev_ties
13
- def next_oat; next_office_action_template; end
13
+ def next_tmpl; next_office_action_template; end
14
14
  # def tmpl; next_office_action_template; end
15
15
 
16
16
 
@@ -18,3 +18,4 @@ class Wco::OfficeActionTemplateTie
18
18
  validates :next_at_exe, presence: true
19
19
 
20
20
  end
21
+ OATT ||= Wco::OfficeActionTemplateTie
@@ -28,6 +28,7 @@ class Wco::Publisher
28
28
  @headers = {}
29
29
  @ctx = OpenStruct.new
30
30
 
31
+ puts! context_eval, 'context_eval'
31
32
  eval( context_eval )
32
33
  puts! @ctx, '@ctx'
33
34
 
@@ -38,11 +39,14 @@ class Wco::Publisher
38
39
  out = Wco::HTTParty.post( "#{@site.origin}#{post_path}", {
39
40
  body: body.to_json,
40
41
  headers: @headers,
41
- basic_auth: { username: site.username, password: site.password },
42
+ basic_auth: { username: @site.username, password: @site.password },
42
43
  })
43
44
  puts! out.response, 'out'
45
+ if out.code != 201
46
+ raise "#do_run exception: #{out.body}"
47
+ end
44
48
 
45
- eval( after_eval )
49
+ eval( after_eval ) if after_eval.present?
46
50
  end
47
51
 
48
52
 
@@ -1,9 +1,7 @@
1
1
 
2
2
  ##
3
+ ## @report.body.split("\n\n").map { |ttt| "<p>#{ttt}</p>" }.join
3
4
  ##
4
- ##
5
- # @report.body.split("\n\n").map { |ttt| "<p>#{ttt}</p>" }.join
6
- #
7
5
  class Wco::Report
8
6
  include Mongoid::Document
9
7
  include Mongoid::Timestamps
@@ -21,19 +19,10 @@ class Wco::Report
21
19
  field :slug
22
20
  validates :slug, presence: true, uniqueness: true
23
21
  index({ :slug => 1 }, { :unique => true })
24
- before_validation :set_slug, :on => :create
22
+ before_validation :set_slug, on: :create
25
23
 
26
24
  field :body
27
25
 
28
- # field :raw_json, type: :object, default: '{}'
29
-
30
- # field :is_trash, :type => Boolean, :default => false
31
- # index({ :is_trash => 1, :is_public => 1 })
32
-
33
- # field :is_public, :type => Boolean, :default => true
34
- # index({ :is_public => 1 })
35
- # scope :public, ->{ where({ is_public: true }) }
36
-
37
26
  field :x, :type => Float
38
27
  field :y, :type => Float
39
28
  field :z, :type => Float
@@ -1,5 +1,5 @@
1
1
 
2
- - oat ||= nil
2
+ - tmpl ||= nil
3
3
  - depth ||= 5
4
4
  - depth = depth - 1
5
5
 
@@ -10,9 +10,9 @@
10
10
  %li
11
11
  = tie.next_at_exe
12
12
  %br
13
- = link_to '[~]', edit_office_action_template_path(tie.next_oat)
14
- = link_to tie.next_oat, office_action_template_path(tie.next_oat)
15
- - if tie.next_oat == oat
13
+ = link_to '[~]', edit_office_action_template_path(tie.next_tmpl)
14
+ = link_to tie.next_tmpl, office_action_template_path(tie.next_tmpl)
15
+ - if tie.next_tmpl == tmpl
16
16
  <b>[Same]</b>
17
- - elsif tie.next_oat.ties.present?
18
- = render '/wco/office_action_templates/ties', ties: tie.next_oat.ties, depth: depth, oat: tie.next_oat
17
+ - elsif tie.next_tmpl.ties.present?
18
+ = render '/wco/office_action_templates/ties', ties: tie.next_tmpl.ties, depth: depth, tmpl: tie.next_tmpl
@@ -7,6 +7,8 @@
7
7
  &nbsp;
8
8
  = link_to oa.slug, office_action_path(oa)
9
9
  %ul
10
+ %li
11
+ .gray.mini= oa.id
10
12
  %li <b>status:</b> #{oa.status}
11
13
  %li
12
14
  <b>tmpl:</b>
@@ -2,34 +2,26 @@
2
2
  require 'business_time'
3
3
  require 'httparty'
4
4
 
5
- namespace :office do
5
+ namespace :wco do
6
6
 
7
- desc 'run_office_actions'
7
+
8
+ desc 'run office actions'
8
9
  task run_office_actions: :environment do
10
+ puts! "Starting wco_email:run_office_actions..."
9
11
  while true do
10
12
 
11
- OA = Wco::OfficeAction
12
- OAT = Wco::OfficeActionTemplate
13
-
14
- OA.active.where( :perform_at.lte => Time.now ).each do |oa|
15
- puts "+++ +++ Office Action: #{oa}"
13
+ schs = Wco::OfficeAction.active.where({ :perform_at.lte => Time.now })
14
+ print "[#{schs.length}]" if schs.length != 0
15
+ schs.each do |sch|
16
16
 
17
- oa.update({ status: INACTIVE })
18
- oa.tmpl.do_run
19
- oa.tmpl.ties.each do |tie|
20
- next_oa = OA.find_or_initialize_by({
21
- office_action_template_id: tie.next_oat.id,
22
- })
23
- next_oa.perform_at = eval( tie.next_at_exe )
24
- next_oa.status = ACTIVE
25
- next_oa.save!
26
- end
17
+ sch.do_run
27
18
 
28
- print '^'
19
+ print "[#{sch.id}]^"
20
+ sleep 15
29
21
  end
30
22
 
31
23
  print '.'
32
- sleep Rails.env.production? ? 60 : 5 # seconds
24
+ sleep 15
33
25
  end
34
26
  end
35
27
 
data/lib/wco/ai_writer.rb CHANGED
@@ -21,6 +21,7 @@ class Wco::AiWriter
21
21
  })
22
22
  out = JSON.parse out.response.body
23
23
  out.deep_symbolize_keys!
24
+ puts! out, 'chatgpt response'
24
25
  out = out[:choices][0][:message][:content]
25
26
  return out
26
27
  end
@@ -28,25 +29,24 @@ class Wco::AiWriter
28
29
 
29
30
 
30
31
  def self.run_headline headline
31
- prompt = "Rephrase the following article title using one sentence: #{headline.name}"
32
+ prompt = "Rephrase the following article title using less than 250 characters: #{headline.name}"
32
33
  new_title = self.run_prompt prompt
33
- puts! new_title, 'new_title'
34
+ new_title = new_title[0..255]
35
+ # puts! new_title, 'new_title'
34
36
 
35
37
  prompt = "Write an article about the following topic: #{headline.name}"
36
38
  new_body = self.run_prompt prompt
37
39
  new_body.gsub!("\r", '')
38
40
  new_body = new_body.split("\n\n").map { |ppp| "<p>#{ppp}</p>" }.join
39
41
  new_body = new_body.gsub("\n", "<br />")
40
- puts! new_body[0...200], 'new_body'
42
+ # puts! new_body[0...200], 'new_body'
41
43
 
42
44
  report = Wco::Report.create!({
43
45
  title: new_title,
44
- slug: new_title,
46
+ # slug: new_title,
45
47
  body: new_body,
46
48
  })
47
49
 
48
- # headline.delete
49
-
50
50
  return report
51
51
  end
52
52
  def run_headline h; self.class.run_headline h; end
data/lib/wco_models.rb CHANGED
@@ -24,6 +24,7 @@ require 'sass-rails'
24
24
  require 'stripe'
25
25
 
26
26
  require "wco/engine"
27
+ require 'wco/ai_writer'
27
28
 
28
29
  ACTIVE = 'active'
29
30
  INACTIVE = 'inactive'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wco_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.83
4
+ version: 3.1.0.86
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pudeyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-16 00:00:00.000000000 Z
11
+ date: 2024-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3