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_cache_creation_input_tokens: i32,
18    pub price_per_million_cache_read_input_tokens: i32,
19    pub price_per_million_output_tokens: i32,
20}
21
22#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
23pub enum Relation {
24    #[sea_orm(
25        belongs_to = "super::provider::Entity",
26        from = "Column::ProviderId",
27        to = "super::provider::Column::Id"
28    )]
29    Provider,
30    #[sea_orm(has_many = "super::usage::Entity")]
31    Usages,
32}
33
34impl Related<super::provider::Entity> for Entity {
35    fn to() -> RelationDef {
36        Relation::Provider.def()
37    }
38}
39
40impl Related<super::usage::Entity> for Entity {
41    fn to() -> RelationDef {
42        Relation::Usages.def()
43    }
44}
45
46impl ActiveModelBehavior for ActiveModel {}