Difference between revisions of "Dreamily API"

From Caiyun Wiki
Jump to: navigation, search
Line 1: Line 1:
 
Hello, everybody, and welcome to Colorfulclouds's Dreamily API. It's still in its early stages. The steps are as follows:
 
Hello, everybody, and welcome to Colorfulclouds's Dreamily API. It's still in its early stages. The steps are as follows:
 
大家好,在这里介绍彩云小梦 API 的调用。目前还非常初级,处于尝鲜版本。使用步骤如下:
 
大家好,在这里介绍彩云小梦 API 的调用。目前还非常初级,处于尝鲜版本。使用步骤如下:
* send e-mail to api@dreamily.ai. To apply for a token, please specify: 发送邮件到 api@caiyunapp.com 申请 token,请写明:
+
* send e-mail to support@dreamily.ai. To apply for a token, please specify: 发送邮件到 api@caiyunapp.com 申请 token,请写明:
 
** Your Company/School and name 你的单位/学校和姓名
 
** Your Company/School and name 你的单位/学校和姓名
 
** The purpose of the application API 申请 API 的用途
 
** The purpose of the application API 申请 API 的用途

Revision as of 15:48, 25 September 2022

Hello, everybody, and welcome to Colorfulclouds's Dreamily API. It's still in its early stages. The steps are as follows: 大家好,在这里介绍彩云小梦 API 的调用。目前还非常初级,处于尝鲜版本。使用步骤如下:

  • send e-mail to support@dreamily.ai. To apply for a token, please specify: 发送邮件到 api@caiyunapp.com 申请 token,请写明:
    • Your Company/School and name 你的单位/学校和姓名
    • The purpose of the application API 申请 API 的用途
    • links to apps or websites App 或 网站的链接
  • follow the instructions below to make the call 按照下面的说明进行调用

python version

colab link:https://colab.research.google.com/drive/1Ha0IEOm-VoPu6DbtbUkuYE5HycdfQ9Ax?usp=sharing

def write(title, content):
    global nid

    import requests
    import json
    
    url = "http://if.caiyunai.com/v1/dream/"
    
    #WARNING, this should be replaced by your token
    token = #your token


    #创建文章,如果已经创建过就使用之前的文章id

    try:
    
        payload = {
                "content" : content, 
                "title" : title,
                "nid": nid,
               }

    except:

        payload = {
                "content" : content, 
                "title" : title,
               }


        response = requests.request("POST", url+token+"/novel_save", data=json.dumps(payload))

        nid = json.loads(response.text)['data']['nid']

    #选择模型

    #小梦0号:60094a2a9661080dc490f75a
    #小梦1号:601ac4c9bd931db756e22da6
    #纯爱:601f92f60c9aaf5f28a6f908
    #言情:601f936f0c9aaf5f28a6f90a
    #玄幻:60211134902769d45689bf75

    #我们在本文例子里,选“小梦0号“
    mid="60094a2a9661080dc490f75a"

    #发起续写

    payload = {
            "content" : content, 
            "title" : title,
            "mid": mid,
            "nid": nid
            }

    response = requests.request("POST", url+token+"/novel_ai", data=json.dumps(payload))

    try:
        xid=json.loads(response.text)['data']['xid']
    except:
        print(response.text)
        return;
        
    #等待结果
    import time

    while True:

      time.sleep(1) 

      #获取结果
      payload = {
              "xid": xid,
              "nid": nid
              }

      response = requests.request("POST", url+token+"/novel_dream_loop", data=json.dumps(payload))

      if json.loads(response.text)['data']['count']==0:
        res = json.loads(response.text)['data']['rows']
        break

    return res

write("星球大战","地球联合舰队")