-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add owner_id to extractors #44
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
db1451e
add owner_id to extractor
ccurme c4b6a84
update test
ccurme 79dfe4f
make owner_id required and don't return on get request
ccurme 8c48d29
format
ccurme 62203e5
fix unrelated bug
ccurme f17f3cb
update notebooks
ccurme ded0007
use cookies
ccurme ed58999
format
ccurme ebdc085
add cookies to extract
ccurme 7929f61
format
ccurme fc599bd
fix example endpoints
ccurme a54fa53
update
ccurme a874838
update
ccurme 53796dd
format
ccurme 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
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 |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
from typing import Any, List | ||
from uuid import UUID | ||
|
||
from fastapi import APIRouter, Depends | ||
from fastapi import APIRouter, Cookie, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from typing_extensions import Annotated, TypedDict | ||
|
||
from db.models import Example, get_session | ||
from db.models import Example, get_session, validate_extractor_owner | ||
|
||
router = APIRouter( | ||
prefix="/examples", | ||
|
@@ -36,8 +36,12 @@ def create( | |
create_request: CreateExample, | ||
*, | ||
session: Session = Depends(get_session), | ||
owner_id: UUID = Cookie(...), | ||
) -> CreateExampleResponse: | ||
"""Endpoint to create an example.""" | ||
if not validate_extractor_owner(session, create_request["extractor_id"], owner_id): | ||
raise HTTPException(status_code=404, detail="Extractor not found for owner.") | ||
|
||
instance = Example( | ||
extractor_id=create_request["extractor_id"], | ||
content=create_request["content"], | ||
|
@@ -55,8 +59,11 @@ def list( | |
limit: int = 10, | ||
offset: int = 0, | ||
session=Depends(get_session), | ||
owner_id: UUID = Cookie(...), | ||
) -> List[Any]: | ||
"""Endpoint to get all examples.""" | ||
if not validate_extractor_owner(session, extractor_id, owner_id): | ||
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. This works |
||
raise HTTPException(status_code=404, detail="Extractor not found for owner.") | ||
return ( | ||
session.query(Example) | ||
.filter(Example.extractor_id == extractor_id) | ||
|
@@ -68,7 +75,12 @@ def list( | |
|
||
|
||
@router.delete("/{uuid}") | ||
def delete(uuid: UUID, *, session: Session = Depends(get_session)) -> None: | ||
def delete( | ||
uuid: UUID, *, session: Session = Depends(get_session), owner_id: UUID = Cookie(...) | ||
) -> None: | ||
"""Endpoint to delete an example.""" | ||
session.query(Example).filter(Example.uuid == str(uuid)).delete() | ||
extractor_id = session.query(Example).filter_by(uuid=str(uuid)).first().extractor_id | ||
if not validate_extractor_owner(session, extractor_id, owner_id): | ||
raise HTTPException(status_code=404, detail="Extractor not found for owner.") | ||
session.query(Example).filter_by(uuid=str(uuid)).delete() | ||
session.commit() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
from db.models import Example, Extractor | ||
from extraction.utils import update_json_schema | ||
from server.models import get_chunk_size, get_model | ||
from server.models import DEFAULT_MODEL, get_chunk_size, get_model | ||
from server.validators import validate_json_schema | ||
|
||
|
||
|
@@ -188,7 +188,7 @@ async def extract_entire_document( | |
text_splitter = TokenTextSplitter( | ||
chunk_size=get_chunk_size(model_name), | ||
chunk_overlap=20, | ||
model_name=model_name, | ||
model_name=DEFAULT_MODEL, | ||
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. unrelated bug. for now we'll use gpt 3.5 tokenizer everywhere. |
||
) | ||
texts = text_splitter.split_text(content) | ||
extraction_requests = [ | ||
|
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.
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.
.first() -> should usually be .scalar() or .one() if there are unique constraints