-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59db142
commit 0e55aa1
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from functools import wraps | ||
|
||
from django_ai_assistant.helpers.formatters import cast_id | ||
from django_ai_assistant.models import Message, Thread | ||
|
||
|
||
def with_cast_id(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
thread_id = kwargs.get("thread_id") | ||
message_id = kwargs.get("message_id") | ||
|
||
if thread_id: | ||
thread_id = cast_id(thread_id, Thread) | ||
kwargs["thread_id"] = thread_id | ||
|
||
if message_id: | ||
message_id = cast_id(message_id, Message) | ||
kwargs["message_id"] = message_id | ||
|
||
return func(*args, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import uuid | ||
|
||
|
||
def format_id(item_id, model): | ||
def cast_id(item_id, model): | ||
if isinstance(item_id, str) and "UUID" in model._meta.pk.get_internal_type(): | ||
return uuid.UUID(item_id) | ||
return item_id |