Skip to content

Commit

Permalink
[Lint] reformat affinda/client.py and test_interface.py
Browse files Browse the repository at this point in the history
  • Loading branch information
coscialp committed Nov 6, 2023
1 parent f878a6d commit 89fcf8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
20 changes: 10 additions & 10 deletions edenai_apis/apis/affinda/client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down
47 changes: 25 additions & 22 deletions edenai_apis/features/text/text_interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import abstractmethod
from typing import List, Optional, Dict, Literal, Union

from edenai_apis.features.text import (
KeywordExtractionDataClass,
NamedEntityRecognitionDataClass,
Expand All @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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
Expand Down

0 comments on commit 89fcf8a

Please sign in to comment.