|
6 | 6 |
|
7 | 7 | class DatToolProvider(ToolProvider): |
8 | 8 | def _validate_credentials(self, credentials: dict[str, Any]) -> None: |
9 | | - pass |
10 | | - # base_url = credentials["base_url"] |
11 | | - # if not base_url: |
12 | | - # raise ValueError("Please fill in the DAT OpenAPI Server base url") |
13 | | - # |
14 | | - # timeout = credentials["timeout"] |
15 | | - # if timeout is None or timeout.strip() == "" or not timeout.isdigit(): |
16 | | - # raise ValueError("Timeout can be empty or fill with integer value") |
17 | | - # |
18 | | - # url = urljoin(base_url.rstrip('/') + '/', 'health') |
19 | | - # |
20 | | - # headers = { |
21 | | - # 'accept': 'application/json' |
22 | | - # } |
23 | | - # |
24 | | - # try: |
25 | | - # response = requests.get(url,headers=headers, timeout=int(timeout)) |
26 | | - # except Exception as e: |
27 | | - # raise ValueError(f"DAT OpenAPI Server invoke failed: {e}") |
28 | | - # |
29 | | - # if response.status_code != 200: |
30 | | - # if response.status_code == 401: |
31 | | - # raise ValueError("DAT OpenAPI Server invoke authorization error") |
32 | | - # elif response.status_code == 429: |
33 | | - # raise ValueError("DAT OpenAPI Server invoke rate limit error") |
34 | | - # elif response.status_code == 500: |
35 | | - # raise ValueError("DAT OpenAPI Server invoke server unavailable error") |
36 | | - # else: |
37 | | - # raise ValueError("DAT OpenAPI Server invoke bad request error") |
| 9 | + base_url = credentials["base_url"] |
| 10 | + if not base_url: |
| 11 | + raise ValueError("Please fill in the DAT OpenAPI Server base url") |
| 12 | + |
| 13 | + timeout = credentials["timeout"] |
| 14 | + if timeout is None or timeout.strip() == "" or not timeout.isdigit(): |
| 15 | + raise ValueError("Timeout can be empty or fill with integer value") |
| 16 | + |
| 17 | + url = urljoin(base_url.rstrip('/') + '/', 'health') |
| 18 | + |
| 19 | + headers = { |
| 20 | + 'accept': 'application/json' |
| 21 | + } |
| 22 | + |
| 23 | + try: |
| 24 | + response = requests.get(url,headers=headers, timeout=int(timeout)) |
| 25 | + except Exception as e: |
| 26 | + raise ValueError(f"DAT OpenAPI Server invoke failed: {e}") |
| 27 | + |
| 28 | + if response.status_code != 200: |
| 29 | + if response.status_code == 401: |
| 30 | + raise ValueError("DAT OpenAPI Server invoke authorization error") |
| 31 | + elif response.status_code == 429: |
| 32 | + raise ValueError("DAT OpenAPI Server invoke rate limit error") |
| 33 | + elif response.status_code == 500: |
| 34 | + raise ValueError("DAT OpenAPI Server invoke server unavailable error") |
| 35 | + else: |
| 36 | + raise ValueError("DAT OpenAPI Server invoke bad request error") |
0 commit comments