model.rs

 1use sea_orm::entity::prelude::*;
 2
 3use crate::llm::db::{ModelId, ProviderId};
 4
 5/// An LLM model.
 6#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
 7#[sea_orm(table_name = "models")]
 8pub struct Model {
 9    #[sea_orm(primary_key)]
10    pub id: ModelId,
11    pub provider_id: ProviderId,
12    pub name: String,
13    pub max_requests_per_minute: i64,
14    pub max_tokens_per_minute: i64,
15    pub max_tokens_per_day: i64,
16    pub price_per_million_input_tokens: i32,
17    pub price_per_million_output_tokens: i32,
18}
19
20#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21pub enum Relation {
22    #[sea_orm(
23        belongs_to = "super::provider::Entity",
24        from = "Column::ProviderId",
25        to = "super::provider::Column::Id"
26    )]
27    Provider,
28    #[sea_orm(has_many = "super::usage::Entity")]
29    Usages,
30}
31
32impl Related<super::provider::Entity> for Entity {
33    fn to() -> RelationDef {
34        Relation::Provider.def()
35    }
36}
37
38impl Related<super::usage::Entity> for Entity {
39    fn to() -> RelationDef {
40        Relation::Usages.def()
41    }
42}
43
44impl ActiveModelBehavior for ActiveModel {}