← 返回首页
ChatGPT3.5接口参数详解
发表时间:2023-04-17 08:47:05
ChatGPT3.5接口参数详解

ChatGPT 是由 OpenAI 开发的一款自然语言处理工具,可以通过发送 HTTP 请求来调用其 API 接口实现文本生成、问答等功能。

1.基础参数 - model:指定要使用的 ChatGPT 模型。目前支持的模型有 davinci、curie、babbage、ada 以及 text-davinci-003 等多个模型。其中,gpt-3.5-turbo和text-davinci-003 是目前最强大的 ChatGPT 模型。 - prompt:表示对话的上文或者是开头语,可以为空。 - temperature:表示对生成的回答的多样性程度,通常在0.7到1.0之间取值。 - max_tokens:指定API生成文本的最大长度。 - top_p:表示从概率分布中选择可能结果的阈值大小,通常在0.9到1.0之间取值。 - presence_penalty:表示尽量避免生成上下文中已经提到过的单词,通常在0.3到0.9之间取值。 - frequency_penalty:表示尽量不重复生成同一个单词,通常在0到1之间取值。 - stop:用于指定在生成文本时停止的条件。可以使用特定的符号作为终止符,例如 \n、.、! 等。

2.接口调用案例


curl --location 'https://api.openai.com/v1/chat/completions' \
--header 'Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
    "model": "gpt-3.5-turbo",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": "写一份有五年开发经验的Java工程师简历。"
        }
    ]
}'



curl --location 'https://api.openai.com/v1/completions' \
--header 'Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
    "model": "text-davinci-003",
    "prompt": "写一份有五年开发经验的Java工程师简历。\\nAI:",
    "temperature": 0.7,
    "max_tokens": 1024,
    "stop": [
        "Human:",
        "AI:"
    ]
}'

请求头的Authorization参数为你申请的ChatGPT的APIKEY。

由于gpt-3.5-turbo的性能与text-davinci-003相似,但每个令牌的价格仅有text-davinci-003的10%,因此建议大多数开发者使用gpt-3.5-turbo。