-
Notifications
You must be signed in to change notification settings - Fork 1
Question Playground #152
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
Merged
Merged
Question Playground #152
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
23012d4
Add initial table
anmarhindi 3587c7d
Add evaluation models
anmarhindi 1654d71
add evaluation set accessors
anmarhindi 0a4cbd8
add evaluation group accessors
anmarhindi d7a1401
add eval run bobj
anmarhindi 74e3e05
add update bobj
anmarhindi 18b7d0a
by group id
LennartSchmidtKern f52dc80
deletion
LennartSchmidtKern ccf85a6
Delete evaluation runs
lumburovskalina 1749dd6
Add playground question model
anmarhindi 2b1f7ed
Add limit check for questions per project
anmarhindi d021d5a
Remove unused import
anmarhindi 59cbf48
Remove unused fields
anmarhindi 4d1929b
Remove unused import
anmarhindi c2acd12
Change model fields
anmarhindi 2ff8904
Remove ifs during eval run create
anmarhindi 89bda2c
Add optional state param
anmarhindi 85f761b
Add flush_or_commit
anmarhindi 77f856a
Rename to ids for readability
anmarhindi 2f3646b
Rename delete_all func param to ids for readability
anmarhindi 86743c4
Add comment in PlaygroundQuestion model for extension properties
anmarhindi 5711968
join query for eval group
anmarhindi 565c229
Add join query for eval group id
anmarhindi dc4f3d8
Add check for duplicate questions
anmarhindi 0eeed19
Deleting questions and order desc
lumburovskalina 80a3a37
Add question check
anmarhindi 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 hidden or 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,49 @@ | ||
from typing import List | ||
|
||
from ..models import EvaluationGroup | ||
from ..session import session | ||
from . import general | ||
|
||
|
||
def get(project_id: str, evaluation_group_id: str) -> EvaluationGroup: | ||
query = session.query(EvaluationGroup).filter( | ||
EvaluationGroup.project_id == project_id, | ||
EvaluationGroup.id == evaluation_group_id, | ||
) | ||
return query.first() | ||
|
||
|
||
def get_all(project_id: str) -> List[EvaluationGroup]: | ||
query = session.query(EvaluationGroup).filter( | ||
EvaluationGroup.project_id == project_id, | ||
) | ||
query = query.order_by(EvaluationGroup.name) | ||
return query.all() | ||
|
||
|
||
def create( | ||
project_id: str, | ||
name: str, | ||
created_by: str, | ||
evaluation_set_ids: List[str], | ||
with_commit: bool = False, | ||
) -> EvaluationGroup: | ||
eval_group = EvaluationGroup( | ||
project_id=project_id, | ||
name=name, | ||
created_by=created_by, | ||
evaluation_set_ids=evaluation_set_ids, | ||
) | ||
|
||
general.add(eval_group, with_commit) | ||
|
||
return eval_group | ||
|
||
|
||
def delete_all(project_id: str, group_ids: str, with_commit: bool = False): | ||
query = session.query(EvaluationGroup).filter( | ||
EvaluationGroup.project_id == project_id, | ||
EvaluationGroup.id.in_(group_ids), | ||
) | ||
query.delete(synchronize_session=False) | ||
general.flush_or_commit(with_commit) |
This file contains hidden or 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,97 @@ | ||
from typing import List, Optional | ||
|
||
from submodules.model.enums import EvaluationRunState | ||
|
||
from ..models import EvaluationRun | ||
from ..session import session | ||
from . import general | ||
|
||
|
||
def get(project_id: str, evaluation_run_id: str) -> EvaluationRun: | ||
query = session.query(EvaluationRun).filter( | ||
EvaluationRun.project_id == project_id, | ||
EvaluationRun.id == evaluation_run_id, | ||
) | ||
return query.first() | ||
|
||
|
||
def get_all_by_embedding_id(project_id: str, embedding_id: str) -> EvaluationRun: | ||
query = session.query(EvaluationRun).filter( | ||
EvaluationRun.project_id == project_id, | ||
EvaluationRun.embedding_id == embedding_id, | ||
) | ||
query = query.order_by(EvaluationRun.created_at.asc()) | ||
return query.all() | ||
|
||
|
||
def get_all_by_evaluation_group_id( | ||
project_id: str, evaluation_group_id: str | ||
) -> EvaluationRun: | ||
query = session.query(EvaluationRun).filter( | ||
EvaluationRun.project_id == project_id, | ||
EvaluationRun.evaluation_group_id == evaluation_group_id, | ||
) | ||
query = query.order_by(EvaluationRun.created_at.asc()) | ||
return query.all() | ||
|
||
|
||
def get_all(project_id: str) -> List[EvaluationRun]: | ||
query = session.query(EvaluationRun).filter( | ||
EvaluationRun.project_id == project_id, | ||
) | ||
query = query.order_by(EvaluationRun.created_at.asc()) | ||
return query.all() | ||
|
||
|
||
def create( | ||
project_id: str, | ||
evaluation_group_id: str, | ||
created_by: str, | ||
embedding_id: str, | ||
state: EvaluationRunState, | ||
results: Optional[str] = None, | ||
meta_info: Optional[str] = None, | ||
with_commit: bool = False, | ||
) -> EvaluationRun: | ||
eval_run = EvaluationRun( | ||
evaluation_group_id=evaluation_group_id, | ||
created_by=created_by, | ||
project_id=project_id, | ||
embedding_id=embedding_id, | ||
state=state, | ||
results=results, | ||
meta_info=meta_info, | ||
) | ||
|
||
general.add(eval_run, with_commit) | ||
|
||
return eval_run | ||
|
||
|
||
def update( | ||
project_id: str, | ||
evaluation_run_id: str, | ||
state: Optional[EvaluationRunState] = None, | ||
results: Optional[str] = None, | ||
meta_info: Optional[str] = None, | ||
with_commit: bool = False, | ||
) -> EvaluationRun: | ||
eval_run: EvaluationRun = get(project_id, evaluation_run_id) | ||
if state is not None: | ||
eval_run.state = state | ||
if results is not None: | ||
eval_run.results = results | ||
if meta_info is not None: | ||
eval_run.meta_info = meta_info | ||
|
||
general.flush_or_commit(with_commit) | ||
return eval_run | ||
|
||
|
||
def delete_all(project_id: str, run_ids: str, with_commit: bool = False): | ||
query = session.query(EvaluationRun).filter( | ||
EvaluationRun.project_id == project_id, | ||
EvaluationRun.id.in_(run_ids), | ||
) | ||
query.delete(synchronize_session=False) | ||
general.flush_or_commit(with_commit) |
This file contains hidden or 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,70 @@ | ||
from typing import List | ||
|
||
from submodules.model.util import prevent_sql_injection | ||
|
||
from ..models import EvaluationSet | ||
from ..session import session | ||
from . import general | ||
|
||
|
||
def get(project_id: str, evaluation_set_id: str) -> EvaluationSet: | ||
query = session.query(EvaluationSet).filter( | ||
EvaluationSet.project_id == project_id, | ||
EvaluationSet.id == evaluation_set_id, | ||
) | ||
return query.first() | ||
|
||
|
||
def get_all(project_id: str) -> List[EvaluationSet]: | ||
query = session.query(EvaluationSet).filter( | ||
EvaluationSet.project_id == project_id, | ||
) | ||
query = query.order_by(EvaluationSet.question) | ||
return query.all() | ||
|
||
|
||
def get_by_evaluation_group_id( | ||
project_id: str, evaluation_group_id: str | ||
) -> List[EvaluationSet]: | ||
project_id = prevent_sql_injection(project_id, isinstance(project_id, str)) | ||
evaluation_group_id = prevent_sql_injection( | ||
evaluation_group_id, isinstance(evaluation_group_id, str) | ||
) | ||
|
||
query = f""" | ||
SELECT es.* | ||
FROM evaluation_group eg | ||
JOIN LATERAL jsonb_array_elements_text(eg.evaluation_set_ids::jsonb) AS elem(evaluation_set_id) ON TRUE | ||
JOIN evaluation_set es ON es.id = elem.evaluation_set_id::uuid | ||
WHERE eg.project_id = '{project_id}' | ||
AND eg.id = '{evaluation_group_id}' | ||
AND es.project_id = '{project_id}' | ||
ORDER BY es.question; | ||
""" | ||
|
||
return general.execute_all(query) | ||
|
||
|
||
def create( | ||
project_id: str, | ||
question: str, | ||
created_by: str, | ||
record_ids: List[str], | ||
with_commit: bool = False, | ||
) -> EvaluationSet: | ||
eval_set = EvaluationSet( | ||
project_id=project_id, | ||
question=question, | ||
created_by=created_by, | ||
record_ids=record_ids, | ||
) | ||
general.add(eval_set, with_commit) | ||
return eval_set | ||
|
||
|
||
def delete_all(project_id: str, set_ids: List[str], with_commit: bool = False) -> None: | ||
session.query(EvaluationSet).filter( | ||
EvaluationSet.project_id == project_id, | ||
EvaluationSet.id.in_(set_ids), | ||
).delete(synchronize_session=False) | ||
general.flush_or_commit(with_commit) |
This file contains hidden or 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 hidden or 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,85 @@ | ||
from typing import Any, List | ||
|
||
from ..models import PlaygroundQuestion | ||
from ..session import session | ||
from . import general | ||
|
||
|
||
MAX_SAVED_QUESTIONS_HISTORY_PER_PROJECT = 100 | ||
|
||
|
||
def get(project_id: str, question_id: str) -> PlaygroundQuestion: | ||
query = session.query(PlaygroundQuestion).filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
PlaygroundQuestion.id == question_id, | ||
) | ||
return query.first() | ||
|
||
|
||
def get_all(project_id: str) -> List[PlaygroundQuestion]: | ||
query = session.query(PlaygroundQuestion).filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
) | ||
query = query.order_by(PlaygroundQuestion.created_at.desc()) | ||
return query.all() | ||
|
||
|
||
def create( | ||
project_id: str, | ||
question: str, | ||
with_commit: bool = False, | ||
) -> Any: | ||
|
||
current_questions = ( | ||
session.query(PlaygroundQuestion) | ||
.filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
) | ||
.all() | ||
) | ||
|
||
current_count = len(current_questions) | ||
|
||
if current_count >= MAX_SAVED_QUESTIONS_HISTORY_PER_PROJECT: | ||
oldest = ( | ||
session.query(PlaygroundQuestion) | ||
.filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
) | ||
.order_by(PlaygroundQuestion.created_at.asc()) | ||
.limit(current_count - MAX_SAVED_QUESTIONS_HISTORY_PER_PROJECT + 1) | ||
.all() | ||
) | ||
ids = [q.id for q in oldest] | ||
delete_all(project_id, ids, False) | ||
|
||
if question: | ||
current_count_question = sum( | ||
1 for q in current_questions if str(q.question).lower() == question.lower() | ||
) | ||
|
||
if current_count_question == 0: | ||
q = PlaygroundQuestion( | ||
project_id=project_id, | ||
question=question, | ||
) | ||
general.add(q, with_commit) | ||
return q | ||
|
||
return None | ||
|
||
|
||
def delete_all(project_id: str, ids: List[str], with_commit: bool = False) -> None: | ||
session.query(PlaygroundQuestion).filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
PlaygroundQuestion.id.in_(ids), | ||
).delete(synchronize_session=False) | ||
general.flush_or_commit(with_commit) | ||
|
||
|
||
def delete(project_id: str, id: str, with_commit: bool = True) -> None: | ||
session.query(PlaygroundQuestion).filter( | ||
PlaygroundQuestion.project_id == project_id, | ||
PlaygroundQuestion.id == id, | ||
).delete() | ||
general.flush_or_commit(with_commit) |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.