This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move api v0 functionality to v1 (#168)
# Description Feature branch for migrating API endpoints from v0 to v1. Refs argilla-io/argilla#4773 **Type of change** (Please delete options that are not relevant. Remember to title the PR according to the type of change) - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactor (change restructuring the codebase without changing functionality) - [ ] Improvement (change adding some improvement to an existing functionality) - [ ] Documentation update **How Has This Been Tested** - [x] Adding new tests. **Checklist** - [ ] I added relevant documentation - [ ] follows the style guidelines of this project - [ ] I did a self-review of my code - [ ] I made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK) (see text above) - [ ] I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)
- Loading branch information
Showing
39 changed files
with
1,909 additions
and
59 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Annotated | ||
|
||
from fastapi import APIRouter, Depends, Form, status | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from argilla_server.contexts import accounts | ||
from argilla_server.database import get_async_db | ||
from argilla_server.errors import UnauthorizedError | ||
from argilla_server.schemas.v1.oauth2 import Token | ||
|
||
router = APIRouter(tags=["Authentication"]) | ||
|
||
|
||
@router.post("/token", status_code=status.HTTP_201_CREATED, response_model=Token) | ||
async def create_token( | ||
*, | ||
db: AsyncSession = Depends(get_async_db), | ||
username: Annotated[str, Form()], | ||
password: Annotated[str, Form()], | ||
): | ||
user = await accounts.authenticate_user(db, username, password) | ||
if not user: | ||
raise UnauthorizedError() | ||
|
||
return Token(access_token=accounts.generate_user_token(user)) |
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,35 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from fastapi import APIRouter, Depends | ||
|
||
from argilla_server.contexts import info | ||
from argilla_server.schemas.v1.info import Status, Version | ||
from argilla_server.search_engine import SearchEngine, get_search_engine | ||
|
||
router = APIRouter(tags=["info"]) | ||
|
||
|
||
@router.get("/version", response_model=Version) | ||
async def get_version(): | ||
return Version(version=info.argilla_version()) | ||
|
||
|
||
@router.get("/status", response_model=Status) | ||
async def get_status(search_engine: SearchEngine = Depends(get_search_engine)): | ||
return Status( | ||
version=info.argilla_version(), | ||
search_engine=await search_engine.info(), | ||
memory=info.memory_status(), | ||
) |
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.