Python package
pangram.text_classifier module
- class pangram.text_classifier.PangramText(api_key: str | None = None, max_batch_size=32)
Bases:
object
- __init__(api_key: str | None = None, max_batch_size=32) None
A classifier for text inputs using the Pangram Labs API.
This class provides synchronous and asynchronous methods to classify text by making API requests.
- Parameters:
api_key (str, optional) – Your API key for the Pangram Labs. If not provided, the environment variable PANGRAM_API_KEY will be used.
- Raises:
ValueError – If the API key is not provided and not set in the environment.
- predict(text: str)
Classify text as AI- or human-written.
Sends a request to the Pangram Text API and returns the classification result.
- Parameters:
text (str) – The text to be classified.
- Returns:
The classification result from the API.
- Return type:
dict
- batch_predict(text_batch: List[str])
Classify a batch of text as AI- or human-written.
This method sends a batch of text to the Pangram Text API and returns the classification results.
- Parameters:
text_batch (List[str]) – A list of strings to be classified.
- Returns:
A list of classification results from the API for each text in the batch.
- Return type:
List[dict]
- predict_sliding_window(text: str)
Classify a long document using a sliding window to iterate across the full document. :param text: The text to be classified. :type text: str :return: The classification result from the API. :rtype: dict