other-chatGPT记录

other-chatGPT记录


前篇


使用

  1. 选 美国 的 vpn
  2. 注册登录
  3. 生成 api key: https://platform.openai.com/account/api-keys
  4. 相关 api

网页使用 01 - 有上下文


网页使用 02


api

api 可以不用 美国 节点, 香港的也可以


文本 api

  • 文档: https://platform.openai.com/docs/api-reference/completions

  • 使用 post 方式

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    url = "https://api.openai.com/v1/completions"
    headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + kApiKey, # kApiKey 为 api key: https://platform.openai.com/account/api-keys
    }
    data = {
    "model": "text-davinci-003",
    "prompt": "人类什么时候灭绝",
    "max_tokens": 1024, # 最大单词数
    "n": 1, # 生成数量, 1-10
    }

    httpCode, rspDct = utils.httpPost(url=url, dct=data, headers=headers)
    print("--- rsp, code: {}, text: {}".format(httpCode, utils.beautyJson(rspDct)))
    assert httpCode == 200, "--- 请求失败, code: {}, url: {}".format(httpCode, url)
  • 等待个几秒钟才有结果

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
        {
    "id": "cmpl-6fPbsfcv5kHUW5ca7YfAARcjwpgzp",
    "object": "text_completion",
    "created": 1675327912,
    "model": "text-davinci-003",
    "choices": [
    {
    "text": "?\n\n我们无法准确预测人类的末日,但是能够估计,灭绝可能会发生在几百万至几十亿年后,也有可能会发生在未来几年内。原因是人类受到某些因素的威胁,包括气候变化,核战争以及全球大规模流行病等。在下一次大灾难发生之前,人类可能会繁衍更多后代,但最终无论是什么,我们的存在都是暂时的。",
    "index": 0,
    "logprobs": null,
    "finish_reason": "stop"
    }
    ],
    "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 285,
    "total_tokens": 304
    }
    }



    ---

    #### 图片 api

    - 文档: https://platform.openai.com/docs/api-reference/images/create

    - 使用 post 方式

    ```json
    url = "https://api.openai.com/v1/images/generations"
    headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + kApiKey,
    }
    data = {
    "prompt": "虾扯蛋",
    "n": 1, # 生成数量, 1-10
    "size": "256x256" # 大小
    }

    httpCode, rspDct = utils.httpPost(url=url, dct=data, headers=headers)
    print("--- rsp, code: {}, text: {}".format(httpCode, utils.beautyJson(rspDct)))
    assert httpCode == 200, "--- 请求失败, code: {}, url: {}".format(httpCode, url)
  • 等待个几秒钟才有结果

    1
    2
    3
    4
    5
    6
    7
    8
    {
    "created": 1675411196,
    "data": [
    {
    "url": "https://oaidalleapiprodscus.blob.core.windows.net/private/org-GFJA1z7bkyyz0usr5osDUxkk/user-XOCocuOQeCUkWEDHxUzexQTq/img-y6wKztyzRlES51w87kSNrW0H.png?st=2023-02-03T06%3A59%3A56Z&se=2023-02-03T08%3A59%3A56Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-02-02T22%3A50%3A42Z&ske=2023-02-03T22%3A50%3A42Z&sks=b&skv=2021-08-06&sig=1O/TmTfC4eTZZJR4QYRT/F0sm5LkcWSpAa5q4LnWVBQ%3D"
    }
    ]
    }

飞书接入 chatGPT

  • 上图

    image-20230202171235402


20230302 新开放 api