Skip to main content

LLMWhisperer Python Client Documentation

Classes

LLMWhispererClient

A client for interacting with the LLMWhisperer API.

This client uses the requests library to make HTTP requests to the LLMWhisperer API. It also includes a logger for tracking the client's activities and errors.

Methods:

  • Constructor (self, base_url="", api_key="", api_timeout=120, logging_level=""): Initializes the client with the given parameters.
  • get_usage_info(self): Retrieves the usage information of the LLMWhisperer API.
  • whisper(self, file_path="", url="", processing_mode="ocr", output_mode="line-printer", page_seperator="<<<", force_text_processing=False, pages_to_extract="", timeout=200, store_metadata_for_highlighting=False, median_filter_size=0, gaussian_blur_radius=0, ocr_provider="advanced", line_splitter_tolerance=0.4, horizontal_stretch_factor=1.0): Sends a request to the LLMWhisperer API to process a document.
  • whisper_status(self, whisper_hash): Retrieves the status of the whisper operation from the LLMWhisperer API.
  • whisper_retrieve(self, whisper_hash): Retrieves the result of the whisper operation from the LLMWhisperer API.
  • highlight_data(self, whisper_hash, search_text): Highlights the specified text in the result of a whisper operation.

Detailed Method Documentation

Constructor

Initializes the LLMWhispererClient with the given parameters.

Args:

  • base_url (str, optional): The base URL for the LLMWhisperer API. Defaults to "".
  • api_key (str, optional): The API key for the LLMWhisperer API. Defaults to "".
  • api_timeout (int, optional): The timeout for API requests. Defaults to 120 seconds.
  • logging_level (str, optional): The logging level for the client. Can be "DEBUG", "INFO", "WARNING" or "ERROR". Defaults to the value of the LLMWHISPERER_LOGGING_LEVEL environment variable, or "DEBUG" if the environment variable is not set.

get_usage_info

Retrieves the usage information of the LLMWhisperer API.

This method sends a GET request to the '/get-usage-info' endpoint of the LLMWhisperer API. The response is a JSON object containing the usage information.

Returns:

  • dict: A dictionary containing the usage information.

Raises:

  • LLMWhispererClientException: If the API request fails, it raises an exception with the error message and status code returned by the API.

whisper

Sends a request to the LLMWhisperer API to process a document.

Args:

  • file_path (str, optional): The path to the file to be processed. Defaults to "".
  • stream (IO[bytes], optional): A stream of bytes to be processed. Defaults to None.
  • url (str, optional): The URL of the file to be processed. Defaults to "".
  • processing_mode (str, optional): The processing mode. Can be "ocr" or "text". Defaults to "ocr".
  • output_mode (str, optional): The output mode. Can be "line-printer" or "text". Defaults to "line-printer".
  • page_seperator (str, optional): The page separator. Defaults to "<<<".
  • force_text_processing (bool, optional): Whether to force text processing. Defaults to False.
  • pages_to_extract (str, optional): The pages to extract. Defaults to "".
  • timeout (int, optional): The timeout for the request in seconds. Defaults to 200.
  • store_metadata_for_highlighting (bool, optional): Whether to store metadata for highlighting. Defaults to False.
  • median_filter_size (int, optional): The size of the median filter. Defaults to 0.
  • gaussian_blur_radius (int, optional): The radius of the Gaussian blur. Defaults to 0.
  • ocr_provider (str, optional): The OCR provider. Can be "advanced" or "basic". Defaults to "advanced".
  • line_splitter_tolerance (float, optional): The line splitter tolerance. Defaults to 0.4.
  • horizontal_stretch_factor (float, optional): The horizontal stretch factor. Defaults to 1.0.

Returns:

  • dict: The response from the API as a dictionary.

Raises:

  • LLMWhispererClientException: If the API request fails, it raises an exception with the error message and status code returned by the API.

whisper_status

Retrieves the status of the whisper operation from the LLMWhisperer API.

This method sends a GET request to the '/whisper-status' endpoint of the LLMWhisperer API. The response is a JSON object containing the status of the whisper operation.

Args:

  • whisper_hash (str): The hash of the whisper operation.

Returns:

  • dict: A dictionary containing the status of the whisper operation. The keys in the dictionary include 'status_code' and the status details.

Raises:

  • LLMWhispererClientException: If the API request fails, it raises an exception with the error message and status code returned by the API.

whisper_retrieve

Retrieves the result of the whisper operation from the LLMWhisperer API.

This method sends a GET request to the '/whisper-retrieve' endpoint of the LLMWhisperer API. The response is a JSON object containing the result of the whisper operation.

Args:

  • whisper_hash (str): The hash of the whisper operation.

Returns:

  • dict: A dictionary containing the status code and the extracted text from the whisper operation.

Raises:

  • LLMWhispererClientException: If the API request fails, it raises an exception with the error message and status code returned by the API.

highlight_data

Highlights the specified text in the result of a whisper operation.

Note: The whisper operation must have been performed with the store_metadata_for_highlighting parameter set to True.

This method sends a POST request to the '/highlight-data' endpoint of the LLMWhisperer API. The response is a JSON object containing the highlighted text information.

Args:

  • whisper_hash (str): The hash of the whisper operation.
  • search_text (str): The text to be highlighted.

Returns:

  • dict: A dictionary containing the status code and the highlighted text.

Raises:

  • LLMWhispererClientException: If the API request fails, it raises an exception with the error message and status code returned by the API.