-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix curator default persona editing #4158
Merged
+20
−6
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -209,13 +209,21 @@ def create_update_persona( | |
if not all_prompt_ids: | ||
raise ValueError("No prompt IDs provided") | ||
|
||
is_default_persona: bool | None = create_persona_request.is_default_persona | ||
# Default persona validation | ||
if create_persona_request.is_default_persona: | ||
if not create_persona_request.is_public: | ||
raise ValueError("Cannot make a default persona non public") | ||
|
||
if user and user.role != UserRole.ADMIN: | ||
raise ValueError("Only admins can make a default persona") | ||
if user: | ||
# Curators can edit default personas, but not make them | ||
if ( | ||
user.role == UserRole.CURATOR | ||
or user.role == UserRole.GLOBAL_CURATOR | ||
): | ||
is_default_persona = None | ||
elif user.role != UserRole.ADMIN: | ||
raise ValueError("Only admins can make a default persona") | ||
|
||
persona = upsert_persona( | ||
persona_id=persona_id, | ||
|
@@ -241,7 +249,7 @@ def create_update_persona( | |
num_chunks=create_persona_request.num_chunks, | ||
llm_relevance_filter=create_persona_request.llm_relevance_filter, | ||
llm_filter_extraction=create_persona_request.llm_filter_extraction, | ||
is_default_persona=create_persona_request.is_default_persona, | ||
is_default_persona=is_default_persona, | ||
) | ||
|
||
versioned_make_persona_private = fetch_versioned_implementation( | ||
|
@@ -428,7 +436,7 @@ def upsert_persona( | |
remove_image: bool | None = None, | ||
search_start_date: datetime | None = None, | ||
builtin_persona: bool = False, | ||
is_default_persona: bool = False, | ||
is_default_persona: bool | None = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having persona in the parameter name seems redundant but i suppose this is propagating from other variable names? |
||
label_ids: list[int] | None = None, | ||
chunks_above: int = CONTEXT_CHUNKS_ABOVE, | ||
chunks_below: int = CONTEXT_CHUNKS_BELOW, | ||
|
@@ -523,7 +531,11 @@ def upsert_persona( | |
existing_persona.is_visible = is_visible | ||
existing_persona.search_start_date = search_start_date | ||
existing_persona.labels = labels or [] | ||
existing_persona.is_default_persona = is_default_persona | ||
existing_persona.is_default_persona = ( | ||
is_default_persona | ||
if is_default_persona is not None | ||
else existing_persona.is_default_persona | ||
) | ||
# Do not delete any associations manually added unless | ||
# a new updated list is provided | ||
if document_sets is not None: | ||
|
@@ -575,7 +587,9 @@ def upsert_persona( | |
display_priority=display_priority, | ||
is_visible=is_visible, | ||
search_start_date=search_start_date, | ||
is_default_persona=is_default_persona, | ||
is_default_persona=is_default_persona | ||
if is_default_persona is not None | ||
else False, | ||
labels=labels or [], | ||
) | ||
db_session.add(new_persona) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it feels like we should have a curator class with behavior like this stored inside instead of trying to reason out the behavior in a bunch of disparate functions.