|
5 | 5 | import urllib.request
|
6 | 6 | from typing import Any, Dict, List, TypeVar, Optional, TypedDict, cast
|
7 | 7 |
|
8 |
| -from dynarag.constants import DYNARAG_BASE_URL |
9 |
| -from dynarag.exceptions import BadAPIRequest, MissingAPIToken |
| 8 | +from dynarag.exceptions import BadAPIRequest, MissingAPIToken, BadEnvironment |
10 | 9 |
|
11 | 10 | LOGGER = logging.getLogger(__name__)
|
12 | 11 |
|
13 | 12 | T = TypeVar("T")
|
14 | 13 |
|
15 |
| - |
16 | 14 | class Similar(TypedDict):
|
17 | 15 | ID: int
|
18 | 16 | DocumentID: int
|
@@ -51,17 +49,26 @@ class DynaRAGClient:
|
51 | 49 | def __init__(self) -> None:
|
52 | 50 | """Initialise the DynaRAG client."""
|
53 | 51 | api_token = os.environ.get("DYNARAG_API_TOKEN", None)
|
| 52 | + base_url = os.environ.get("DYNARAG_BASE_URL", None) |
54 | 53 | if not api_token:
|
55 | 54 | 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. " |
58 | 56 | )
|
59 | 57 | LOGGER.error(error_str)
|
60 | 58 | 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) |
61 | 68 |
|
62 |
| - LOGGER.info("Obtained DynaRAG API key. Successfully initialised.") |
| 69 | + LOGGER.info("Obtained DynaRAG API key and service URL. Successfully initialised.") |
63 | 70 |
|
64 |
| - self.base_url = DYNARAG_BASE_URL |
| 71 | + self.base_url = base_url |
65 | 72 | self.api_token = api_token
|
66 | 73 |
|
67 | 74 | def _make_request(
|
|
0 commit comments