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 #[sea_orm(has_many = "super::billing_event::Entity")]
33 BillingEvents,
34}
35
36impl Related<super::provider::Entity> for Entity {
37 fn to() -> RelationDef {
38 Relation::Provider.def()
39 }
40}
41
42impl Related<super::usage::Entity> for Entity {
43 fn to() -> RelationDef {
44 Relation::Usages.def()
45 }
46}
47
48impl Related<super::billing_event::Entity> for Entity {
49 fn to() -> RelationDef {
50 Relation::BillingEvents.def()
51 }
52}
53
54impl ActiveModelBehavior for ActiveModel {}