diff --git a/edenai_apis/apis/affinda/client.py b/edenai_apis/apis/affinda/client.py index 89cae0d0..e3ae5a84 100644 --- a/edenai_apis/apis/affinda/client.py +++ b/edenai_apis/apis/affinda/client.py @@ -1,20 +1,20 @@ -#TODO: Add tests for this file from enum import Enum +from http import HTTPStatus from io import BufferedReader from json import JSONDecodeError from typing import Any, Dict, List, Literal, Optional from warnings import warn import requests -from http import HTTPStatus from edenai_apis.utils.exception import ProviderException from edenai_apis.utils.http import HTTPMethod -from .models import Document, Organization, Workspace, Collection from .document import DocumentState, FileParameter, QueryBuilder, UploadDocumentParams +from .models import Document, Organization, Workspace, Collection + class ExtractorType(Enum): - """This class are use to define the type of an extractor + """This class are used to define the type of extractor Actually the affinda api support 6 type of extractor: - resume @@ -478,15 +478,15 @@ def create_document( .add_workspace(self.__current_workspace) .add_collection(self.__current_collection) .build() - ) + ), } files: Optional[Dict[str, BufferedReader]] = None - if file.type == 'url': - payload['url'] = file.file - elif file.type == 'file': - files = { 'file': open(file.file, 'rb') } + if file.type == "url": + payload["url"] = file.file + elif file.type == "file": + files = {"file": open(file.file, "rb")} return Document( **self.__requests( @@ -499,7 +499,7 @@ def create_document( ) def delete_document(self, identifier: str) -> None: - """ Delete the document with the given identifier. + """Delete the document with the given identifier. Args: identifier (str): The identifier of the document. diff --git a/edenai_apis/features/text/text_interface.py b/edenai_apis/features/text/text_interface.py index 4ddf4d49..af783ac8 100644 --- a/edenai_apis/features/text/text_interface.py +++ b/edenai_apis/features/text/text_interface.py @@ -1,5 +1,6 @@ from abc import abstractmethod from typing import List, Optional, Dict, Literal, Union + from edenai_apis.features.text import ( KeywordExtractionDataClass, NamedEntityRecognitionDataClass, @@ -20,13 +21,15 @@ EmotionDetectionDataClass, ) from edenai_apis.features.text.chat.chat_dataclass import StreamChat -from edenai_apis.features.text.plagia_detection.plagia_detection_dataclass import PlagiaDetectionDataClass -from edenai_apis.features.text.spell_check.spell_check_dataclass import ( - SpellCheckDataClass, -) from edenai_apis.features.text.embeddings.embeddings_dataclass import ( EmbeddingsDataClass, ) +from edenai_apis.features.text.plagia_detection.plagia_detection_dataclass import ( + PlagiaDetectionDataClass, +) +from edenai_apis.features.text.spell_check.spell_check_dataclass import ( + SpellCheckDataClass, +) from edenai_apis.utils.types import ResponseType @@ -116,11 +119,13 @@ def text__question_answer( @abstractmethod def text__search( - self, - texts: List[str], - query: str, - similarity_metric: Literal["cosine", "hamming", "manhattan", "euclidean"] = "cosine", - model: Optional[str] = None + self, + texts: List[str], + query: str, + similarity_metric: Literal[ + "cosine", "hamming", "manhattan", "euclidean" + ] = "cosine", + model: Optional[str] = None, ) -> ResponseType[SearchDataClass]: """ Do sementic search over a set of texts @@ -281,9 +286,8 @@ def text__spell_check( @abstractmethod def text__embeddings( - self, - texts: List[str], - model : Optional[str] = None) -> ResponseType[EmbeddingsDataClass]: + self, texts: List[str], model: Optional[str] = None + ) -> ResponseType[EmbeddingsDataClass]: """Text embeddings Args: @@ -299,13 +303,13 @@ def text__chat( self, text: str, chatbot_global_action: Optional[str], - previous_history : Optional[List[Dict[str, str]]], - temperature : float = 0, - max_tokens : int = 25, - model : Optional[str] = None, - stream: bool = False - ) -> ResponseType[Union[ChatDataClass, StreamChat]]: - """Text chat + previous_history: Optional[List[Dict[str, str]]], + temperature: float = 0, + max_tokens: int = 25, + model: Optional[str] = None, + stream: bool = False, + ) -> ResponseType[Union[ChatDataClass, StreamChat]]: + """Text chat Args: text (str): @@ -344,14 +348,13 @@ def text__prompt_optimization( """ raise NotImplementedError - @abstractmethod def text__entity_sentiment(self, text: str, language: str) -> ResponseType: """ Detect sentiment of entities foung through the given text """ raise NotImplementedError - + @abstractmethod def text__plagia_detection( self, text: str, title: str = "" @@ -368,7 +371,7 @@ def text__plagia_detection( @abstractmethod def text__emotion_detection( - self, text: str + self, text: str ) -> ResponseType[EmotionDetectionDataClass]: """ Detect emotion of a given text