mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 10:02:30 +03:00
9aaedcff51
* 🗃️ Rename users table into user_daily_usage * 💥 replace User model with UserIdentity model * 🗃️ New UserDailyUsage class for database interaction * 🐛 fix daily requests rate limiting per user * 🐛 fix user stats and properties update * ✏️ add typing and linting * 🚚 rename user_dialy_usage Class into user_usage & requests_count into daily_requests_count * 🚑 fix some rebase errors
26 lines
732 B
Python
26 lines
732 B
Python
from multiprocessing import get_logger
|
|
from uuid import UUID
|
|
|
|
from models import get_supabase_client, UserIdentity
|
|
from repository.user_identity.create_user_identity import create_user_identity
|
|
|
|
logger = get_logger()
|
|
|
|
|
|
def get_user_identity(user_id: UUID) -> UserIdentity:
|
|
supabase_client = get_supabase_client()
|
|
response = (
|
|
supabase_client.from_("user_identity")
|
|
.select("*")
|
|
.filter("user_id", "eq", str(user_id))
|
|
.execute()
|
|
)
|
|
|
|
if len(response.data) == 0:
|
|
return create_user_identity(user_id, openai_api_key=None)
|
|
|
|
user_identity = response.data[0]
|
|
openai_api_key = user_identity["openai_api_key"]
|
|
|
|
return UserIdentity(id=user_id, openai_api_key=openai_api_key)
|