Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829
  1. from common.log import logger
  2. from config import conf
  3. # ZhipuAI提供的画图接口
  4. class ZhipuAIImage(object):
  5. def __init__(self):
  6. from zhipuai import ZhipuAI
  7. self.client = ZhipuAI(api_key=conf().get("zhipu_ai_api_key"))
  8. def create_img(self, query, retry_count=0, api_key=None, api_base=None):
  9. try:
  10. if conf().get("rate_limit_dalle"):
  11. return False, "请求太快了,请休息一下再问我吧"
  12. logger.info("[ZHIPU_AI] image_query={}".format(query))
  13. response = self.client.images.generations(
  14. prompt=query,
  15. n=1, # 每次生成图片的数量
  16. model=conf().get("text_to_image") or "cogview-3",
  17. size=conf().get("image_create_size", "1024x1024"), # 图片大小,可选有 256x256, 512x512, 1024x1024
  18. quality="standard",
  19. )
  20. image_url = response.data[0].url
  21. logger.info("[ZHIPU_AI] image_url={}".format(image_url))
  22. return True, image_url
  23. except Exception as e:
  24. logger.exception(e)
  25. return False, "画图出现问题,请休息一下再问我吧"