Skip to content

Commit df093b5

Browse files
Added custom base URL
1 parent 289fc7f commit df093b5

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DYNARAG_API_TOKEN=<your_jwt_token>
2+
DYNARAG_BASE_URL=<your_base_url>

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
# DynaRAG
22

3-
This is the Python client to the [DynaRAG API](https://www.dynarag.com).
3+
This is the Python client to [DynaRAG](https://github.com/Predixus/DynaRAG).
44

5-
DynaRAG provides a simple and fast interface to implement RAG (Retrieval Augemented Generation) into your application.
5+
DynaRAG provides a simple and fast interface to implement RAG (Retrieval Augemented Generation)
6+
into your application.
67

78
## Configuration
89

9-
DynaRAG only requires an API token to get started. You can obtain an API token by going to the [DynaRAG App](https://app.dynarag.com),
10+
DynaRAG requires some environment variables to get started:
11+
- `DYNARAG_API_TOKEN` - a signed JWT that contains data needed by DynaRAG. Follow the spec in the [DynaRAG](https://github.com/Predixus/DynaRAG)
12+
service repo.
13+
- `DYNARAG_BASE_URL` - url to the DynaRAG service. e.g. http://localhost:7890
14+
15+
You can obtain an API token by going to the [DynaRAG App](https://app.dynarag.com),
1016
logging in and navigating to dashboard>developer. From here you can generate an API token.
1117

12-
> :warning: **API Token**: Put your API token into an environment varibale called `DYNARAG_API_TOKEN` in order for the DynaRAG Client to discover it.
18+
> :warning: **API Token**: Put your API token into an environment variable called `DYNARAG_API_TOKEN`
19+
> in order for the DynaRAG Client to discover it. This must be a JWT that follows the spec of the
20+
> [DynaRAG service](https://github.com/Predixus/DynaRAG).
1321
1422
## Usage
1523

dynarag/constants.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

dynarag/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ class MissingAPIToken(BaseException):
88

99
class BadAPIRequest(BaseException):
1010
"""Raised if a request to the DynaRAG API fails"""
11+
12+
13+
class BadEnvironment(BaseException):
14+
"""Raised when the environment is bad"""

dynarag/main.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
import urllib.request
66
from typing import Any, Dict, List, TypeVar, Optional, TypedDict, cast
77

8-
from dynarag.constants import DYNARAG_BASE_URL
9-
from dynarag.exceptions import BadAPIRequest, MissingAPIToken
8+
from dynarag.exceptions import BadAPIRequest, MissingAPIToken, BadEnvironment
109

1110
LOGGER = logging.getLogger(__name__)
1211

1312
T = TypeVar("T")
1413

15-
1614
class Similar(TypedDict):
1715
ID: int
1816
DocumentID: int
@@ -51,17 +49,26 @@ class DynaRAGClient:
5149
def __init__(self) -> None:
5250
"""Initialise the DynaRAG client."""
5351
api_token = os.environ.get("DYNARAG_API_TOKEN", None)
52+
base_url = os.environ.get("DYNARAG_BASE_URL", None)
5453
if not api_token:
5554
error_str = (
56-
"Could not find the `DYNARAG_API_TOKEN` environment variable."
57-
"You can obtain one by going to https://app.dynarag.com/dashboard/developer and generate a token."
55+
"Could not find the `DYNARAG_API_TOKEN` environment variable. "
5856
)
5957
LOGGER.error(error_str)
6058
raise MissingAPIToken(error_str)
59+
if not base_url:
60+
error_str = (
61+
"Could not find the `DYNARAG_BASE_URL` environment variable. "
62+
"Set it to the URL of your DynaRAG service, e.g. http://localhost:7890. "
63+
"Follow the instructions in the DynaRAG service repo to get started: "
64+
"https://github.com/predixus/dynarag?tab=readme-ov-file#getting-started"
65+
)
66+
LOGGER.error(error_str)
67+
raise BadEnvironment(error_str)
6168

62-
LOGGER.info("Obtained DynaRAG API key. Successfully initialised.")
69+
LOGGER.info("Obtained DynaRAG API key and service URL. Successfully initialised.")
6370

64-
self.base_url = DYNARAG_BASE_URL
71+
self.base_url = base_url
6572
self.api_token = api_token
6673

6774
def _make_request(

0 commit comments

Comments
 (0)