diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b3227598..0c170dac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.6.0 +* [#104](https://github.com/cohere-ai/cohere-python/pull/96) + * Remove experimental `moderate` api + ## 2.5.0 * [#96](https://github.com/cohere-ai/cohere-python/pull/96) * The default `max_tokens` value is now configured on the backend diff --git a/cohere/__init__.py b/cohere/__init__.py index b2e135f19..8653db825 100644 --- a/cohere/__init__.py +++ b/cohere/__init__.py @@ -8,7 +8,6 @@ EMBED_URL = 'embed' CLASSIFY_URL = 'classify' EXTRACT_URL = 'extract' -MODERATE_URL= 'moderate' CHECK_API_KEY_URL = 'check-api-key' TOKENIZE_URL = 'tokenize' diff --git a/cohere/client.py b/cohere/client.py index f06adce1a..27b6d5329 100644 --- a/cohere/client.py +++ b/cohere/client.py @@ -17,7 +17,6 @@ from cohere.extract import Example as ExtractExample from cohere.extract import Extraction, Extractions from cohere.generation import Generation, Generations, TokenLikelihood -from cohere.moderate import Moderation, Moderations from cohere.tokenize import Tokens from cohere.detokenize import Detokenization @@ -193,22 +192,6 @@ def classify( return Classifications(classifications) - def moderate(self, inputs: List[str], model: str = None, truncate: str = 'NONE') -> Moderations: - json_body = json.dumps({ - 'model': model, - 'inputs': inputs, - 'truncate': truncate, - }) - response = self.__request(json_body, cohere.MODERATE_URL) - - moderations = [] - for res in response['results']: - moderations.append( - Moderation(res['profanity'], res['hate_speech'], res['violence'], res['self_harm'], res['sexual'], - res['sexual_non_consensual'], res['spam'])) - - return Moderations(moderations=moderations) - def unstable_extract(self, examples: List[ExtractExample], texts: List[str]) -> Extractions: ''' Makes a request to the Cohere API to extract entities from a list of texts. diff --git a/cohere/moderate.py b/cohere/moderate.py deleted file mode 100644 index 516d41f4b..000000000 --- a/cohere/moderate.py +++ /dev/null @@ -1,32 +0,0 @@ -from typing import List - -from cohere.response import CohereObject - - -class Moderation(CohereObject): - - def __init__(self, profanity: float, hate_speech: float, violence: float, self_harm: float, sexual: float, - sexual_non_consensual: float, spam: float) -> None: - self.profanity = profanity - self.hate_speech = hate_speech - self.violence = violence - self.self_harm = self_harm - self.sexual = sexual - self.sexual_non_consensual = sexual_non_consensual - self.spam = spam - - -class Moderations(CohereObject): - - def __init__(self, moderations: List[Moderation]) -> None: - self.moderations = moderations - self.iterator = iter(moderations) - - def __iter__(self) -> iter: - return self.iterator - - def __next__(self) -> next: - return next(self.iterator) - - def __len__(self) -> int: - return len(self.moderations) diff --git a/tests/test_moderate.py b/tests/test_moderate.py deleted file mode 100644 index 9e50b3a66..000000000 --- a/tests/test_moderate.py +++ /dev/null @@ -1,18 +0,0 @@ -import unittest - -import cohere - -from utils import get_api_key - -co = cohere.Client(get_api_key()) - - -class TestModerate(unittest.TestCase): - - def test_success(self): - moderations = co.moderate(inputs=['I Love Cohere!']) - self.assertEqual(len(moderations), 1) - - def test_invalid_text(self): - with self.assertRaises(cohere.CohereError): - co.moderate(inputs=[])