Updated

app/models/apps / ai_assistent.rb

A
31 lines of codes
2 methods
8.8 complexity/method
2 churn
17.52 complexity
0 duplications
# frozen_string_literal: true # == Schema Information # # Table name: apps_ai_assistents # # id :bigint not null, primary key # api_key :string default(""), not null # auto_reply :boolean default(FALSE), not null # enabled :boolean default(FALSE), not null # model :string default("gpt-4o"), not null # usage :jsonb not null # created_at :datetime not null # updated_at :datetime not null # class Apps::AiAssistent < ApplicationRecord validates :model, presence: true validates :api_key, presence: true, if: :enabled? after_update :embed_company_site, if: -> { saved_change_to_enabled? || saved_change_to_api_key? } def embed_company_site Accounts::Create::EmbedCompanySiteJob.perform_later(id) if Current.account.site_url.present? && enabled? end def exceeded_usage_limit? return false if usage['limit'].blank?
  1. Apps::AiAssistent#exceeded_usage_limit? calls 'usage['limit']' 2 times Locations: 0 1
usage['tokens'] >= usage['limit']
  1. Apps::AiAssistent#exceeded_usage_limit? calls 'usage['limit']' 2 times Locations: 0 1
end end