Pārlūkot izejas kodu

fix a ValidationError and add network test

highing666 4 gadi atpakaļ
vecāks
revīzija
fc5f32698c

+ 7 - 3
app/controllers/nlp/meeting.py

@@ -52,9 +52,10 @@ class MeetingInfoCatcher:
     async def extract_name(self, sentence: str) -> List[str]:
         _, ner_tokens = await self.nlp_service.get_lexical_analysis_result(sentence)
         name_list = []
-        for token in ner_tokens:
-            if token.Type == 'PER':
-                name_list.append(token.Word)
+        if ner_tokens:
+            for token in ner_tokens:
+                if token.Type == 'PER':
+                    name_list.append(token.Word)
 
         return name_list
 
@@ -77,5 +78,8 @@ async def get_caught_result(sentence: str) -> Tuple:
         duckling = Duckling(client)
         service = TencentNLP()
 
+        r = await client.get('https://api.github.com/users/octocat/orgs')  # Test external network
+        logger.debug(r.status_code)
+
         catcher = MeetingInfoCatcher(service, duckling)
         return await catcher.run(sentence)

+ 1 - 0
app/models/domain/nlp.py

@@ -8,6 +8,7 @@ class RoomSize(str, Enum):
     small = 'small'
     medium = 'medium'
     large = 'large'
+    unknown = ''
 
 
 class NLPResponseBase(BaseModel):

+ 1 - 1
app/services/tencent_nlp.py

@@ -41,7 +41,7 @@ class TencentNLP:
         client = nlp_client.NlpClient(cred, 'ap-guangzhou', client_profile)
         self.client = client
 
-    async def get_lexical_analysis_result(self, text: str) -> Tuple[Dict, Dict]:
+    async def get_lexical_analysis_result(self, text: str) -> Tuple[List, List]:
         req = models.LexicalAnalysisRequest()
         params = {
             'Text': text