quivr/backend/repository/user_identity/get_user_identity.py
Zineb El Bachiri 9aaedcff51
Fix/requests limiting (#980)
* 🗃️ 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
2023-08-21 14:05:13 +02:00

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)