tencent_nlp.py 947 B

12345678910111213141516171819202122232425
  1. from loguru import logger
  2. from tencentcloud.common import credential
  3. from tencentcloud.common.profile.client_profile import ClientProfile
  4. from tencentcloud.common.profile.http_profile import HttpProfile
  5. from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
  6. from tencentcloud.nlp.v20190408 import nlp_client
  7. from app.core.config import settings
  8. def get_tencent_nlp_client() -> nlp_client.NlpClient:
  9. try:
  10. cred = credential.Credential(settings.TENCENT_SECRET_ID_V1, settings.TENCENT_SECRET_KEY_V1)
  11. http_profile = HttpProfile()
  12. http_profile.reqMethod = 'GET'
  13. http_profile.endpoint = settings.TENCENT_NLP_ENDPOINT
  14. client_profile = ClientProfile()
  15. client_profile.httpProfile = http_profile
  16. client = nlp_client.NlpClient(cred, 'ap-guangzhou', client_profile)
  17. return client
  18. except TencentCloudSDKException as e:
  19. logger.error(e)