微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从谷歌视角 API 中遇到异常响应?

如何解决从谷歌视角 API 中遇到异常响应?

我一直在构建一个 discord.py 聊天机器人,它使用透视 API 分析消息,以确定消息是否有毒。以下文件是众多文件中的一个,用于确定消息是否有毒:

from googleapiclient import discovery


def score(restype,message):
  try:
    API_KEY= os.getenv('API_KEY')

    service = discovery.build('commentanalyzer','v1alpha1',developerKey=API_KEY)
    
    analyze_request = {
      'comment': { 'text': f'{message}' },'requestedAttributes': {'TOXICITY': {}}
    }

    response = service.comments().analyze(body=analyze_request).execute()


    final = float(response["attributescores"]["TOXICITY"]["spanscores"][0]["score"]["value"])

    if restype == "show":
      print(final)

      complete = int(final * 100)

      return complete
      print("sent")
    else:
      print("evaluated.")
  except:
    print("score calculation issue")


  @Cog.listener()
  async def on_message(self,message):
    print("CALLED")
    channel = message.channel
    userid = message.author.id
    restype = ("show")
    value = score(restype,message)
    if value > 70:
      await channel.send(f"your message was {value}% toxic! Lets be nice!")
      db.execute("UPDATE users SET Offences = Offences + 1 WHERE UserID = ?",userid)
      name = message.author.display_name
      print(f"updated DB for {name} with userid:{userid}")

当我使用粗鲁的话时,它可以出色地响应范围为 0.7 - 0.9 的数字,而在我平静时使用更低的数字,但是突然间不管我的输入如何,它都保持在 0.1 左右,即使使用粗鲁的话也几乎没有变化!???这是什么原因!?非常感谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。