ChatGPT调试

2023-03-07  本文已影响0人  李霖弢

ChatGPT官网:https://chat.openai.com/chat
接码平台:https://sms-activate.org/cn/history#

注册账号
登录openai,进入个人中心,生成 API KEY
测试接口

3.0老版本接口文档

    fetch('https://api.openai.com/v1/completions', {
        method: 'post',
        body: JSON.stringify(
            {
                "model": "text-davinci-003",
                "prompt": "用java写一个hello world",
                "max_tokens": 2048,
                "temperature": 0,
                "top_p": 1,
                "frequency_penalty": 0,
                "presence_penalty": 0.6,
                "stop": ["Human:", "AI:"]
            }),
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer sk-开头的自己的key'
        }
    }).then(function (data) {


    })

3.5新版本接口文档

import os
import openai

openai.organization = "org-开头的自己的key"
openai.api_key = "sk-开头的自己的key"

os.environ["http_proxy"] = "http://127.0.0.1:7890"
os.environ["https_proxy"] = "http://127.0.0.1:7890"

messages = [
    {"role": "system", "content": "Respond in the voice of cute cat, and be as unhelpful as possible!"}
]

while True:

    # Add the user's input to the messages list and user the 'user' role
    user_input = input("Q: ")
    messages.append({"role": "user", "content": user_input})

    # Call the OpenAI api for Chat GPT, and pass our complete list of messages
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=messages,
        temperature=0.8,  # 0~2 值越大返回结果越随机
        n=1, # 返回的choices的长度
        presence_penalty=0, # -2~2 越大越不容易基于之前的聊天内容
        frequency_penalty=0, # -2~2 越大越不容易容易输出重复内容
    )

    # Show ChatGPT's response and add the response to our list of messages
    print('A: ' + str(response['choices'][0]['message']['content']) + '\n')
    messages.append(response['choices'][0]['message'])
上一篇 下一篇

猜你喜欢

热点阅读