|
18 | 18 | LLMWhispererClientException: Exception raised for errors in the LLMWhispererClient.
|
19 | 19 | """
|
20 | 20 |
|
21 |
| -import copy |
22 | 21 | import json
|
23 | 22 | import logging
|
24 | 23 | import os
|
@@ -504,9 +503,44 @@ def register_webhook(self, url: str, auth_token: str, webhook_name: str) -> dict
|
504 | 503 | "webhook_name": webhook_name,
|
505 | 504 | }
|
506 | 505 | url = f"{self.base_url}/whisper-manage-callback"
|
507 |
| - headersx = copy.deepcopy(self.headers) |
508 |
| - headersx["Content-Type"] = "application/json" |
509 |
| - req = requests.Request("POST", url, headers=headersx, json=data) |
| 506 | + req = requests.Request("POST", url, headers=self.headers, json=data) |
| 507 | + prepared = req.prepare() |
| 508 | + s = requests.Session() |
| 509 | + response = s.send(prepared, timeout=self.api_timeout) |
| 510 | + if response.status_code != 201: |
| 511 | + err = json.loads(response.text) |
| 512 | + err["status_code"] = response.status_code |
| 513 | + raise LLMWhispererClientException(err) |
| 514 | + return json.loads(response.text) |
| 515 | + |
| 516 | + def update_webhook_details(self, webhook_name: str, url: str, auth_token: str) -> dict: |
| 517 | + """Updates the details of a webhook from the LLMWhisperer API. |
| 518 | +
|
| 519 | + This method sends a PUT request to the '/whisper-manage-callback' endpoint of the LLMWhisperer API. |
| 520 | + The response is a JSON object containing the status of the webhook update. |
| 521 | +
|
| 522 | + Refer to https://docs.unstract.com/llm_whisperer/apis/ |
| 523 | +
|
| 524 | + Args: |
| 525 | + webhook_name (str): The name of the webhook. |
| 526 | + url (str): The URL of the webhook. |
| 527 | + auth_token (str): The authentication token for the webhook. |
| 528 | +
|
| 529 | + Returns: |
| 530 | + dict: A dictionary containing the status code and the response from the API. |
| 531 | +
|
| 532 | + Raises: |
| 533 | + LLMWhispererClientException: If the API request fails, it raises an exception with |
| 534 | + the error message and status code returned by the API. |
| 535 | + """ |
| 536 | + |
| 537 | + data = { |
| 538 | + "url": url, |
| 539 | + "auth_token": auth_token, |
| 540 | + "webhook_name": webhook_name, |
| 541 | + } |
| 542 | + url = f"{self.base_url}/whisper-manage-callback" |
| 543 | + req = requests.Request("PUT", url, headers=self.headers, json=data) |
510 | 544 | prepared = req.prepare()
|
511 | 545 | s = requests.Session()
|
512 | 546 | response = s.send(prepared, timeout=self.api_timeout)
|
@@ -547,6 +581,37 @@ def get_webhook_details(self, webhook_name: str) -> dict:
|
547 | 581 | raise LLMWhispererClientException(err)
|
548 | 582 | return json.loads(response.text)
|
549 | 583 |
|
| 584 | + def delete_webhook(self, webhook_name: str) -> dict: |
| 585 | + """Deletes a webhook from the LLMWhisperer API. |
| 586 | +
|
| 587 | + This method sends a DELETE request to the '/whisper-manage-callback' endpoint of the LLMWhisperer API. |
| 588 | + The response is a JSON object containing the status of the webhook deletion. |
| 589 | +
|
| 590 | + Refer to https://docs.unstract.com/llm_whisperer/apis/ |
| 591 | +
|
| 592 | + Args: |
| 593 | + webhook_name (str): The name of the webhook. |
| 594 | +
|
| 595 | + Returns: |
| 596 | + dict: A dictionary containing the status code and the response from the API. |
| 597 | +
|
| 598 | + Raises: |
| 599 | + LLMWhispererClientException: If the API request fails, it raises an exception with |
| 600 | + the error message and status code returned by the API. |
| 601 | + """ |
| 602 | + |
| 603 | + url = f"{self.base_url}/whisper-manage-callback" |
| 604 | + params = {"webhook_name": webhook_name} |
| 605 | + req = requests.Request("DELETE", url, headers=self.headers, params=params) |
| 606 | + prepared = req.prepare() |
| 607 | + s = requests.Session() |
| 608 | + response = s.send(prepared, timeout=self.api_timeout) |
| 609 | + if response.status_code != 200: |
| 610 | + err = json.loads(response.text) |
| 611 | + err["status_code"] = response.status_code |
| 612 | + raise LLMWhispererClientException(err) |
| 613 | + return json.loads(response.text) |
| 614 | + |
550 | 615 | def get_highlight_rect(
|
551 | 616 | self,
|
552 | 617 | line_metadata: list[int],
|
|
0 commit comments