File size: 2,564 Bytes
0a69585
1c6c5d7
 
02a3c70
 
 
 
 
 
1c6c5d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a69585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c6c5d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from typing import List, Dict, Optional, Any
import os

try:
    from common.base.api_base_async import BaseAsyncAPI
    from common.base.api_base import BaseAPI
except ImportError:
    from ..common.base.api_base_async import BaseAsyncAPI
    from ..common.base.api_base import BaseAPI


class RfpRecommend(BaseAPI):

    def __init__(self):
        super().__init__(
            url=os.getenv("RFP_RECOMMENDATION_URL"),
            headers={"x-api-key": os.getenv("RFP_RECOMMENDATION_API_KEY")},
            total_retries=5,
            backoff_factor=10
        )

    def __call__(self, candid_entity_id: int):
        results = self.get(candid_entity_id=candid_entity_id)
        return results


class RfpFeedback(BaseAPI):

    def __init__(self):
        super().__init__(
            url=f'{os.getenv("RFP_RECOMMENDATION_URL")}/feedback',
            headers={"x-api-key": os.getenv("RFP_RECOMMENDATION_API_KEY")},
            total_retries=2,
            backoff_factor=5
        )

    def __call__(
        self,
        recommendation_data: Dict[str, Any],
        ratings: List[str],
        info_is_correct: Optional[bool] = None,
        info_is_sufficient: Optional[bool] = None,
        comments: Optional[str] = None,
        email: Optional[str] = None,
    ):
        data = {
            "recommendations": recommendation_data,
            "ratings": ratings,
            "correct_info": info_is_correct,
            "sufficient_info": info_is_sufficient
        }

        if comments:
            data["comments"] = comments
        if email:
            data["email"] = email

        results = self.post(payload=data)
        return results


class Inferencing(BaseAsyncAPI):

    def __init__(self):
        super().__init__(
            url=os.getenv("AUTOCODING_API_URL"),
            headers={"x-api-key": os.getenv("AUTOCODING_API_KEY")}
        )

    async def __call__(self, text: str, taxonomy: str = "pcs",
        chunk: bool = False, high_precision: bool = False
    ):
        result = self.post(payload={
            "text": text,
            "taxonomy": taxonomy,
            "chunk": chunk,
            "high_precision": high_precision
        })
        return result


class Entities(BaseAsyncAPI):

    def __init__(self):
        super().__init__(
            url=os.getenv("DOCUMENT_API_URL").replace("/analyze", "/entities"),
            headers={"x-api-key": os.getenv("DOCUMENT_API_KEY")}
        )

    async def __call__(self, text: str):
        result = self.post(payload={"text": text})
        return result