-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Coverage count in Prompt studio (#727)
* fixed coverage count * added coverage detail to output * added coverage count support on BE * fixed coverage issue on FE * removed unwanted conditional logic * code refactor * code clean up * changed error to warning * BE code refactor * challenger fix * handled errors properly * fixed circular import error * fixed coverage count --------- Co-authored-by: Jaseem Jas <[email protected]>
- Loading branch information
1 parent
2d29154
commit 4109251
Showing
14 changed files
with
193 additions
and
27 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
46 changes: 46 additions & 0 deletions
46
backend/prompt_studio/prompt_studio_output_manager_v2/output_manager_util.py
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,46 @@ | ||
from django.db.models import Count | ||
from prompt_studio.prompt_studio_output_manager_v2.models import ( | ||
PromptStudioOutputManager, | ||
) | ||
|
||
|
||
class OutputManagerUtils: | ||
@staticmethod | ||
def get_coverage( | ||
tool_id: str, profile_manager_id: str, prompt_id: str = None | ||
) -> dict[str, int]: | ||
""" | ||
Method to fetch coverage data for given tool and profile manager. | ||
Args: | ||
tool (CustomTool): The tool instance or ID for which coverage is fetched. | ||
profile_manager_id (str): The ID of the profile manager | ||
for which coverage is calculated. | ||
prompt_id (Optional[str]): The ID of the prompt (optional). | ||
If provided, coverage is fetched for the specific prompt. | ||
Returns: | ||
dict[str, int]: A dictionary containing coverage information. | ||
Keys are formatted as "coverage_<prompt_id>_<profile_manager_id>". | ||
Values are the count of documents associated with each prompt | ||
and profile combination. | ||
""" | ||
|
||
prompt_outputs = ( | ||
PromptStudioOutputManager.objects.filter( | ||
tool_id=tool_id, | ||
profile_manager_id=profile_manager_id, | ||
**({"prompt_id": prompt_id} if prompt_id else {}), | ||
) | ||
.values("prompt_id", "profile_manager_id") | ||
.annotate(document_count=Count("document_manager_id")) | ||
) | ||
|
||
coverage = {} | ||
for prompt_output in prompt_outputs: | ||
prompt_key = str(prompt_output["prompt_id"]) | ||
profile_key = str(prompt_output["profile_manager_id"]) | ||
coverage[f"coverage_{prompt_key}_{profile_key}"] = prompt_output[ | ||
"document_count" | ||
] | ||
return coverage |
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
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
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
Oops, something went wrong.