quivr/backend/repository/user_identity/create_user_identity.py
HamzaKhalid 024dd5a264
fix(user identity): User identity dict has no attribute user_id and open_api_key (#1351)
# Description
Trying to access access 'user identity' attributes as attribute of
dictionary which throws an error since the attributes are actually the
key in the dictionary not an attribute of the dictionary object.

## Checklist before requesting a review

Please delete options that are not relevant.

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code

## Screenshots (if appropriate):
<img width="795" alt="image"
src="https://github.com/StanGirard/quivr/assets/88370405/7db55e74-159c-43e1-b9f7-8384dad9be30">

Co-authored-by: HamzaKhalid-bboxx <127825841+HamzaKhalid-bboxx@users.noreply.github.com>
Co-authored-by: Zineb El Bachiri <100568984+gozineb@users.noreply.github.com>
2023-10-11 16:06:37 +02:00

24 lines
640 B
Python

from typing import Optional
from uuid import UUID
from models import UserIdentity, get_supabase_client
def create_user_identity(id: UUID, openai_api_key: Optional[str]) -> UserIdentity:
supabase_client = get_supabase_client()
response = (
supabase_client.from_("user_identity")
.insert(
{
"user_id": str(id),
"openai_api_key": openai_api_key,
}
)
.execute()
)
user_identity = response.data[0]
return UserIdentity(
id=user_identity.get('user_id'), openai_api_key=user_identity.get('openai_api_key') # type: ignore
)