2023-04-26 11:44:29 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AiApiAuditLog < ActiveRecord::Base
|
2024-04-15 23:22:06 +10:00
|
|
|
belongs_to :post
|
|
|
|
belongs_to :topic
|
2024-11-29 06:26:48 +11:00
|
|
|
belongs_to :user
|
2024-04-15 23:22:06 +10:00
|
|
|
|
2023-04-26 11:44:29 +10:00
|
|
|
module Provider
|
|
|
|
OpenAI = 1
|
2023-05-11 10:03:03 -03:00
|
|
|
Anthropic = 2
|
2023-07-27 13:55:32 -03:00
|
|
|
HuggingFaceTextGeneration = 3
|
2023-12-15 14:32:01 -03:00
|
|
|
Gemini = 4
|
2023-12-26 14:49:55 -03:00
|
|
|
Vllm = 5
|
2024-04-11 07:24:17 +10:00
|
|
|
Cohere = 6
|
2024-05-07 10:02:16 -03:00
|
|
|
Ollama = 7
|
2024-09-12 11:28:08 +10:00
|
|
|
SambaNova = 8
|
2024-11-19 17:28:09 +11:00
|
|
|
Mistral = 9
|
2023-04-26 11:44:29 +10:00
|
|
|
end
|
2024-11-12 08:14:30 +11:00
|
|
|
|
|
|
|
def next_log_id
|
|
|
|
self.class.where("id > ?", id).where(topic_id: topic_id).order(id: :asc).pluck(:id).first
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_log_id
|
|
|
|
self.class.where("id < ?", id).where(topic_id: topic_id).order(id: :desc).pluck(:id).first
|
|
|
|
end
|
2023-04-26 11:44:29 +10:00
|
|
|
end
|
2023-05-11 10:03:03 -03:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: ai_api_audit_logs
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# provider_id :integer not null
|
|
|
|
# user_id :integer
|
|
|
|
# request_tokens :integer
|
|
|
|
# response_tokens :integer
|
|
|
|
# raw_request_payload :string
|
|
|
|
# raw_response_payload :string
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
2024-05-14 13:28:46 +10:00
|
|
|
# topic_id :integer
|
|
|
|
# post_id :integer
|
|
|
|
# feature_name :string(255)
|
2024-05-27 16:46:01 +10:00
|
|
|
# language_model :string(255)
|
2024-10-23 16:49:56 +11:00
|
|
|
# feature_context :jsonb
|
2024-11-29 06:26:48 +11:00
|
|
|
# cached_tokens :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_ai_api_audit_logs_on_created_at_and_feature_name (created_at,feature_name)
|
|
|
|
# index_ai_api_audit_logs_on_created_at_and_language_model (created_at,language_model)
|
|
|
|
#
|