yta-fastapi-docker-api 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yta_fastapi_docker_api/__init__.py +5 -0
- yta_fastapi_docker_api/app/__init__.py +0 -0
- yta_fastapi_docker_api/app/main.py +12 -0
- yta_fastapi_docker_api/app/routers/__init__.py +20 -0
- yta_fastapi_docker_api/app/routers/ollama.py +63 -0
- yta_fastapi_docker_api/app/routers/youtube.py +33 -0
- yta_fastapi_docker_api-0.0.1.dist-info/METADATA +72 -0
- yta_fastapi_docker_api-0.0.1.dist-info/RECORD +10 -0
- yta_fastapi_docker_api-0.0.1.dist-info/WHEEL +4 -0
- yta_fastapi_docker_api-0.0.1.dist-info/licenses/LICENSE +19 -0
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from yta_fastapi_docker_api.app.routers import router as general_router
|
|
2
|
+
from yta_fastapi_docker_api.app.routers.youtube import router as youtube_router
|
|
3
|
+
from yta_fastapi_docker_api.app.routers.ollama import router as ollama_router
|
|
4
|
+
from fastapi import FastAPI
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
app = FastAPI()
|
|
8
|
+
|
|
9
|
+
# Include all the routers we have
|
|
10
|
+
app.include_router(general_router)
|
|
11
|
+
app.include_router(youtube_router)
|
|
12
|
+
app.include_router(ollama_router)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from fastapi import APIRouter
|
|
2
|
+
from fastapi.responses import JSONResponse
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
PREFIX = f''
|
|
6
|
+
|
|
7
|
+
router = APIRouter(
|
|
8
|
+
prefix = PREFIX
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
@router.get('/check-status')
|
|
12
|
+
def route_check_status(
|
|
13
|
+
) -> JSONResponse:
|
|
14
|
+
return JSONResponse(
|
|
15
|
+
{
|
|
16
|
+
'error': False,
|
|
17
|
+
'message': 'Hello World!'
|
|
18
|
+
},
|
|
19
|
+
status_code = 200
|
|
20
|
+
)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from fastapi import APIRouter, Body
|
|
2
|
+
from fastapi.responses import JSONResponse, Response
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# TODO: Get this from a .env, should point to the container
|
|
8
|
+
OLLAMA_URL = 'http://yta_fastapi_docker_ollama:8000'
|
|
9
|
+
|
|
10
|
+
PREFIX = f'/ollama'
|
|
11
|
+
|
|
12
|
+
router = APIRouter(
|
|
13
|
+
prefix = PREFIX
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
TODO: The 'prompt' is a class in the 'yta_fastapi_docker_ollama'
|
|
18
|
+
but I don't want to duplicate code and I'm not importing
|
|
19
|
+
any module to be able to bring it here...
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
@router.post('/agents/transcription-cleaner')
|
|
23
|
+
def get_agents_transcription_cleaner(
|
|
24
|
+
# prompt: Prompt
|
|
25
|
+
# prompt: str
|
|
26
|
+
payload: dict = Body(...)
|
|
27
|
+
) -> JSONResponse:
|
|
28
|
+
print('---')
|
|
29
|
+
print(payload)
|
|
30
|
+
print('---')
|
|
31
|
+
response = requests.post(
|
|
32
|
+
url = f'{OLLAMA_URL}/ollama/agents/transcription-cleaner',
|
|
33
|
+
json = payload
|
|
34
|
+
)
|
|
35
|
+
print('@@@')
|
|
36
|
+
print(response)
|
|
37
|
+
print('@@@')
|
|
38
|
+
|
|
39
|
+
content_type = response.headers.get("content-type", "")
|
|
40
|
+
|
|
41
|
+
if "application/json" in content_type:
|
|
42
|
+
return JSONResponse(
|
|
43
|
+
content = response.json(),
|
|
44
|
+
status_code = response.status_code
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
If I don't have the model it is just returning an
|
|
49
|
+
'Internal Server Error' message, but not that we
|
|
50
|
+
don't have the specific model...
|
|
51
|
+
"""
|
|
52
|
+
# TODO:
|
|
53
|
+
return Response(
|
|
54
|
+
# bytes (?)
|
|
55
|
+
content = response.content,
|
|
56
|
+
status_code = response.status_code,
|
|
57
|
+
media_type = response.headers.get("content-type")
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
return JSONResponse(
|
|
61
|
+
content = response.json(),
|
|
62
|
+
status_code = response.status_code
|
|
63
|
+
)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from fastapi import APIRouter
|
|
2
|
+
from fastapi.responses import JSONResponse
|
|
3
|
+
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# TODO: Get this from a .env, should point to the container
|
|
8
|
+
YOUTUBE_URL = 'http://yta_fastapi_docker_youtube:8000'
|
|
9
|
+
|
|
10
|
+
PREFIX = f'/youtube'
|
|
11
|
+
|
|
12
|
+
router = APIRouter(
|
|
13
|
+
prefix = PREFIX
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
@router.get('/videos/{id_video}')
|
|
17
|
+
def get_video(
|
|
18
|
+
id_video: str
|
|
19
|
+
) -> JSONResponse:
|
|
20
|
+
response = requests.get(f'{YOUTUBE_URL}/youtube/videos/{id_video}')
|
|
21
|
+
|
|
22
|
+
return JSONResponse(
|
|
23
|
+
content = response.json(),
|
|
24
|
+
status_code = response.status_code
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
return JSONResponse(
|
|
28
|
+
{
|
|
29
|
+
'error': False,
|
|
30
|
+
'data': data
|
|
31
|
+
},
|
|
32
|
+
status_code = 200
|
|
33
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yta-fastapi-docker-api
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Youtube Autonomous FastAPI Docker API Module
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: danialcala94
|
|
7
|
+
Author-email: danielalcalavalera@gmail.com
|
|
8
|
+
Requires-Python: ==3.12.*
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Requires-Dist: fastapi (>=0.0.1,<9999.0.0)
|
|
12
|
+
Requires-Dist: requests (>=0.0.1,<9999.0.0)
|
|
13
|
+
Requires-Dist: uvicorn (>=0.0.1,<9999.0.0)
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Youtube Autonomous FastAPI Docker API Module
|
|
17
|
+
|
|
18
|
+
The module that is handled by a docker container to isolate the environment we need for each purpose, exposed by a FastAPI that allows asking for the specific resources.
|
|
19
|
+
|
|
20
|
+
This project is using `poetry` to handle the dependencies and the virtual environment, and `docker` to manage the specific python version and all the code with the app to be executed.
|
|
21
|
+
|
|
22
|
+
This is the entry point API for all the functionality our Youtube Autonomous system is providing. This API will delegate in other API-containers to get what is needed.
|
|
23
|
+
|
|
24
|
+
The module that is providing the functionality related to the Youtube platform (downloading, getting metadata, etc.) through a FastAPI that is included and isolated in a Docker container but exposed to the internal and general FastAPI.
|
|
25
|
+
|
|
26
|
+
## Endpoints
|
|
27
|
+
|
|
28
|
+
### Youtube
|
|
29
|
+
|
|
30
|
+
#### GET
|
|
31
|
+
- `/youtube/videos/{id_video}`
|
|
32
|
+
- `/youtube/videos/{id_video}/data`
|
|
33
|
+
- `/youtube/videos/{id_video}/download-best-quality`
|
|
34
|
+
- `/youtube/videos/{id_video}/download-lowest-quality`
|
|
35
|
+
- `/youtube/videos/{id_video}/download-1080`
|
|
36
|
+
|
|
37
|
+
You can replace the `{id_video}` with this id `e_YBmIxeyUg` for testing.
|
|
38
|
+
|
|
39
|
+
#### POST
|
|
40
|
+
No hay endpoints por el momento
|
|
41
|
+
|
|
42
|
+
### Ollama
|
|
43
|
+
|
|
44
|
+
#### GET
|
|
45
|
+
No hay endpoints por el momento
|
|
46
|
+
|
|
47
|
+
#### POST
|
|
48
|
+
No hay endpoints por el momento
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Other Instructions
|
|
55
|
+
#### Generate the image
|
|
56
|
+
We need to generate the docker image with all the things we need to be able to run the app inside.
|
|
57
|
+
- Use the `$ docker build --no-cache -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file and ignoring the caché. This will download the `python 3.12.x` version, install the dependencies and copy the code. Use this if any dependency has changed since the last time. If you are just updating the code, you can use the following instead.
|
|
58
|
+
- Use the `$ docker build -t {LIBRARY_NAME} .` command to generate the Docker image by using the `dockerfile` file. It will download the `python 3.12.x` version, install the dependencies and copy the code, each of these steps only if needed (the cache will make it be ignore if it didn't change).
|
|
59
|
+
|
|
60
|
+
#### Run the container
|
|
61
|
+
We need to run the container, so it will be mounted and the app will be runing and ready to use.
|
|
62
|
+
- Use the command `$ docker rm -f {LIBRARY_NAME} 2>nul` to remove the previous container if existing, so we are able to mount it again from zero.
|
|
63
|
+
- Use the command `$ docker run -d -p "%port%":8000 --name {LIBRARY_NAME} {LIBRARY_NAME}` to run and mount the container and make the app be ready to use.
|
|
64
|
+
|
|
65
|
+
You can also execute the `run_server_docker.bat` to do all together using the caché (faster).
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
The docker will run uvicorn in the port 8000 internally, but our navigator will redirect the 8001 to that one, so we can have different docker containers working at the same time to provide different services using the same base (uvicorn + fastapi).
|
|
70
|
+
|
|
71
|
+
### Other details
|
|
72
|
+
- To run the project locally, execute the `run_server.bat` file or use `$ poetry run uvicorn yta_fastapi_docker_base.app.main:app --reload` directly.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
yta_fastapi_docker_api/__init__.py,sha256=DP97Xz231mbKJQ_2tCXbGqFhkVKepx70UXIv2oQHjtE,114
|
|
2
|
+
yta_fastapi_docker_api/app/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
yta_fastapi_docker_api/app/main.py,sha256=xj1sfFMHHSUPeKvX8Zl_dwWtc4zpkLnsnWUhmVzpYwE,425
|
|
4
|
+
yta_fastapi_docker_api/app/routers/__init__.py,sha256=Gk_zSXCXfrCScCFxHCgTOZ8tyLK-d0t5hv5x9v2kmTY,366
|
|
5
|
+
yta_fastapi_docker_api/app/routers/ollama.py,sha256=E9HIAPCKLK7ayXwDg5KANbzqtACl2D9vNJemLHPk93U,1627
|
|
6
|
+
yta_fastapi_docker_api/app/routers/youtube.py,sha256=uLt9JDaEa2hTzYew3YoCXD6HQLaJn65Vip_lxCKpBUU,706
|
|
7
|
+
yta_fastapi_docker_api-0.0.1.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
|
8
|
+
yta_fastapi_docker_api-0.0.1.dist-info/METADATA,sha256=pFKGZv8DKJs9WjI3lGqaUiwa17Qzc6Onb4qZvHw0pes,3550
|
|
9
|
+
yta_fastapi_docker_api-0.0.1.dist-info/WHEEL,sha256=M5asmiAlL6HEcOq52Yi5mmk9KmTVjY2RDPtO4p9DMrc,88
|
|
10
|
+
yta_fastapi_docker_api-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|