Skip to content

Commit

Permalink
Refactor to hana and add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Jan 19, 2024
1 parent 1370058 commit 4c2bfc9
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/propose_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
branch: dev
release_type: ${{ inputs.release_type }}
update_changelog: True
version_file: "neon_diana_utils/version.py"
version_file: "neon_hana/version.py"
on_version_change: "scripts/sync_chart_app_version.py"
pull_changes:
uses: neongeckocom/.github/.github/workflows/pull_master.yml@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- dev
paths-ignore:
- 'neon_diana_utils/version.py'
- 'neon_hana/version.py'
- '**/Chart.yaml'

jobs:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.9-slim

LABEL vendor=neon.ai \
ai.neon.name="diana-services-api"
ai.neon.name="neon-hana"

ENV OVOS_CONFIG_BASE_FOLDER neon
ENV OVOS_CONFIG_FILENAME diana.yaml
Expand All @@ -13,4 +13,4 @@ WORKDIR /app
COPY . /app
RUN pip install /app

CMD ["python3", "/app/diana_services_api/app/__main__.py"]
CMD ["python3", "/app/neon_hana/app/__main__.py"]
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Diana Services API
This package provides an HTTP front-end for accessing services in a
[Neon DIANA](https://github.com/NeonGeckoCom/neon-diana-utils) deployment. This
should generally be hosted as part of a Diana deployment to safely expose services
via HTTP.
# HANA
HANA (HTTP API for Neon Applications) provides a unified front-end for
accessing services in a [Neon DIANA](https://github.com/NeonGeckoCom/neon-diana-utils) deployment. This API should generally
be hosted as part of a Diana deployment to safely expose services to outside
traffic.

Full API documentation is automatically generated and accessible at `/docs`.

## Configuration
User configuration belongs in `diana.yaml`, mounted in the container path
`/config/neon/`. An example user configuration could be:
```yaml
MQ:
server: mq.mydomain.com
hana:
mq_default_timeout: 10
access_token_ttl: 86400 # 1 day
refresh_token_ttl: 604800 # 1 week
requests_per_minute: 60
access_token_secret: a800445648142061fc238d1f84e96200da87f4f9fa7835cac90db8b4391b117b
refresh_token_secret: 833d369ac73d883123743a44b4a7fe21203cffc956f4c8fec712e71aafa8e1aa
fastapi_title: "My HANA API Host"
fastapi_summary: "Personal HTTP API to access my DIANA backend."
disable_auth: True
```
It is recommended to generate unique values for configured tokens, these are 32
bytes in hexadecimal representation.
## Deployment
You can build a Docker container from this repository, or pull a built container
from the GitHub Container Registry. Start Hana via:
```shell
docker run -p 8080:8080 -v ~/.config/neon:/config/neon ghcr.io/neongeckocom/neon-hana
```
> This assumes you have configuration defined in `~/.config/neon/diana.yaml` and
are using the default port 8080

## Usage
Full API documentation is available at `/docs`. The `/auth/login` endpoint should
be used to generate a `client_id`, `access_token`, and `refresh_token`. The
`access_token` should be included in every request and upon expiration of the
`access_token`, a new token can be obtained from the `auth/refresh` endpoint.
8 changes: 4 additions & 4 deletions docker_overlay/etc/neon/diana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ MQ:
mq_handler:
user: neon_api_utils
password: Klatchat2021
diana_services_api:
hana:
mq_default_timeout: 10
access_token_ttl: 86400 # 1 day
refresh_token_ttl: 604800 # 1 week
requests_per_minute: 60
access_token_secret: a800445648142061fc238d1f84e96200da87f4f9f784108ac90db8b4391b117b
refresh_token_secret: 833d369ac73d883123743a44b4a7fe21203cffc956f4c8a99be6e71aafa8e1aa
server_host: "0.0.0.0"
server_port: 8080
fastapi_title: "Diana Services API"
fastapi_summary: "HTTP component of the Device Independent API for Neon Applications (DIANA)"
disable_auth: True
fastapi_title: "HANA: HTTP API for Neon Applications"
fastapi_summary: "HTTP component of the Device Independent API for Neon Applications (DIANA)"
File renamed without changes.
14 changes: 7 additions & 7 deletions diana_services_api/app/__init__.py → neon_hana/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@

from fastapi import FastAPI

from diana_services_api.app.dependencies import client_manager, jwt_bearer, mq_connector
from diana_services_api.app.routers.api_proxy import proxy_route
from diana_services_api.app.routers.llm import llm_route
from diana_services_api.app.routers.mq_backend import mq_route
from diana_services_api.app.routers.auth import auth_route
from diana_services_api.version import __version__
from neon_hana.app.dependencies import client_manager, jwt_bearer, mq_connector
from neon_hana.app.routers.api_proxy import proxy_route
from neon_hana.app.routers.llm import llm_route
from neon_hana.app.routers.mq_backend import mq_route
from neon_hana.app.routers.auth import auth_route
from neon_hana.version import __version__


def create_app(config: dict):
title = config.get('fastapi_title') or "Diana Services API"
title = config.get('fastapi_title') or "HANA: HTTP API for Neon Applications"
summary = config.get('fastapi_summary') or ""
version = __version__
app = FastAPI(title=title, summary=summary, version=version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

from ovos_config.config import Configuration

from diana_services_api.app import create_app
from neon_hana.app import create_app


def main():
config = Configuration().get("diana_services_api", {})
config = Configuration().get("hana", {})
app = create_app(config)
uvicorn.run(app, host=config.get('server_host', "0.0.0.0"),
port=config.get('port', 8080))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

from ovos_config.config import Configuration

from diana_services_api.mq_service_api import MQServiceManager
from diana_services_api.auth.client_manager import ClientManager, UserTokenAuth
from neon_hana.mq_service_api import MQServiceManager
from neon_hana.auth.client_manager import ClientManager, UserTokenAuth

config = Configuration().get("diana_services_api") or dict()
config = Configuration().get("hana") or dict()
mq_connector = MQServiceManager(config)
client_manager = ClientManager(config)
jwt_bearer = UserTokenAuth(client_manager)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from fastapi import APIRouter, Depends
from diana_services_api.schema.api_requests import *
from diana_services_api.schema.api_responses import *
from diana_services_api.app.dependencies import jwt_bearer, mq_connector
from neon_hana.schema.api_requests import *
from neon_hana.schema.api_responses import *
from neon_hana.app.dependencies import jwt_bearer, mq_connector


proxy_route = APIRouter(prefix="/proxy", tags=["backend"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

from fastapi import APIRouter

from diana_services_api.app.dependencies import client_manager
from diana_services_api.schema.auth_requests import *
from neon_hana.app.dependencies import client_manager
from neon_hana.schema.auth_requests import *

auth_route = APIRouter(prefix="/auth", tags=["authentication"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from fastapi import APIRouter, Depends
from diana_services_api.schema.llm_requests import *
from diana_services_api.app.dependencies import jwt_bearer, mq_connector
from neon_hana.schema.llm_requests import *
from neon_hana.app.dependencies import jwt_bearer, mq_connector


llm_route = APIRouter(prefix="/llm", tags=["backend"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from fastapi import APIRouter, Depends
from diana_services_api.schema.api_requests import *
from diana_services_api.schema.api_responses import *
from diana_services_api.app.dependencies import jwt_bearer, mq_connector
from neon_hana.schema.api_requests import *
from neon_hana.schema.api_responses import *
from neon_hana.app.dependencies import jwt_bearer, mq_connector


mq_route = APIRouter(tags=["backend"], dependencies=[Depends(jwt_bearer)])
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_stt(self, b64_audio: str, lang: str, timeout: int = 20):
"data": {"audio_data": b64_audio,
"utterances": [""], # TODO: Compat
"lang": lang},
"context": {"source": "diana_services_api"}}
"context": {"source": "hana"}}
response = send_mq_request("/neon_chat_api", request_data,
"neon_chat_api_request", timeout=timeout)
return response
Expand All @@ -138,7 +138,7 @@ def get_tts(self, string: str, lang: str, gender: str, timeout: int = 20):
"gender": gender,
"lang": lang},
"lang": lang},
"context": {"source": "diana_services_api"}}
"context": {"source": "hana"}}
response = send_mq_request("/neon_chat_api", request_data,
"neon_chat_api_request", timeout=timeout)
return response
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_requirements(requirements_filename: str):
with open(path.join(BASE_PATH, "README.md"), "r") as f:
long_description = f.read()

with open(path.join(BASE_PATH, "diana_services_api",
with open(path.join(BASE_PATH, "hana",
"version.py"), "r", encoding="utf-8") as v:
for line in v.readlines():
if line.startswith("__version__"):
Expand All @@ -63,12 +63,12 @@ def get_requirements(requirements_filename: str):


setup(
name='diana-services-api',
name='neon-hana',
version=version,
description='Web API to access Neon DIANA Services',
description='Web API to access DIANA Services',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/NeonGeckoCom/diana-services-api',
url='https://github.com/NeonGeckoCom/neon-hana',
author='NeonGecko',
author_email='[email protected]',
license='BSD-3-Clause',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class TestClientManager(unittest.TestCase):
from diana_services_api.auth.client_manager import ClientManager
from neon_hana.auth.client_manager import ClientManager
client_manager = ClientManager({})

def test_check_auth_request(self):
Expand Down

0 comments on commit 4c2bfc9

Please sign in to comment.