other-chatGPT记录


title: other-chatGPT记录
categories: Others
tags: [人工智能, ai, 机器人, chatGPT]
date: 2023-02-02 10:04:33
comments: false
mathjax: true
toc: true

other-chatGPT记录


前篇

  • 官网
    • https://openai.com/
    • api - https://openai.com/api/
    • 测试 - https://platform.openai.com/playground
  • 将ChatGPT接入微信实现智能回复 - https://www.cnblogs.com/zhayujie/p/16989904.html
  • 注册教程 - https://www.cnblogs.com/damugua/p/16969508.html
  • ChatGPT 使用 API 进行 Postman 调用测试 - https://www.ossez.com/t/chatgpt-api-postman/14279

使用

  1. 选 美国 的 vpn
  2. 注册登录
  3. 生成 api key: https://platform.openai.com/account/api-keys
  4. 相关 api
    • 文本: https://platform.openai.com/docs/api-reference/completions
    • 图片: https://platform.openai.com/docs/api-reference/images
    • 编辑: https://platform.openai.com/docs/api-reference/edits
      • 根据输入 和 指示, 返回结果

网页测试

  • https://platform.openai.com/playground

  • 输入文字, 点击 submit

    image-20230202111755082


api

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

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


文本 api

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

  • 使用 post 方式

    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)
    
  • 等待个几秒钟才有结果

    {
          
          
        "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
        }
    }
    
    
    
    

飞书接入 chatGPT

  • 上图

    image-20230202171235402


猜你喜欢

转载自blog.csdn.net/yangxuan0261/article/details/128854010