openai-api - 聊天完成/v1/聊天/完成结果与 ChatGPT 结果有很大不同

标签 openai-api chatgpt-api

我发现 API/v1/chat/completions 结果与网页结果有很大不同。

这是问题的 API 响应:“content”:“乔治·华盛顿的生日是哪一天”

    curl --location 'https://api.openai.com/v1/chat/completions' \
    --header 'Authorization: Bearer TOKEN' \
    --header 'Content-Type: application/json' \
    --data '{
        "model": "gpt-4",
        "messages": [
            {
                "role": "user",
                "content": "What is the birthday of George Washington"
            }
        ]
    }'
    "choices": [
            {
                "message": {
                    "role": "assistant",
                    "content": "George Washington was born on February 22, 1732."
                },
                "finish_reason": "stop",
                "index": 0
            }
        ]

这是网页上的结果。你可以看到它更长了。 enter image description here

最佳答案

使用 OpenAI 时 create completion使用 GPT,您可以转动一些“旋钮”来调整结果。

其中一个旋钮是温度。 温度是 0 到 1 之间的数字。0 非常集中且确定性,1 非常随机。

要生成更长的文本,您还可以使用 max_tokens 参数。

但就你的情况而言,我认为你需要调整提示。添加诸如告诉我更多关于他的信息之类的内容,您应该会看到结果有所改善。

这是我的测试:

curl --location 'https://api.openai.com/v1/chat/completions' \
--header 'Authorization: Bearer TOKEN' \
--header 'Content-Type: application/json' \
--data '{
        "model": "gpt-3.5-turbo",
        "messages": [
            {
                "role": "user",
                "content": "What is the birthday of George Washington? Tell me more about him."
            }
        ]
    }'

答案:

{
    "object": "chat.completion",
    "model": "gpt-3.5-turbo-0301",
    "usage": {
        "prompt_tokens": 22,
        "completion_tokens": 143,
        "total_tokens": 165
    },
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "George Washington's birthday is on February 22, 1732. He was the first president of the United States and is often known as the \"Father of His Country.\" Washington also led the Continental Army to victory over the British during the American Revolution. He is known for his strong leadership, unwavering commitment to his country, and the sacrifices he made to help establish the United States. Washington also played a key role in the creation of the U.S. Constitution, which remains a pillar of American democracy today. Throughout his life, Washington was known for his honesty, integrity, and commitment to the ideals of the American democratic system. His legacy has made him one of the most important figures in American history."
            },
            "finish_reason": "stop",
            "index": 0
        }
    ]
}

关于openai-api - 聊天完成/v1/聊天/完成结果与 ChatGPT 结果有很大不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76020058/

相关文章:

reactjs - 如何生成有效的 arkose_token 来创建 GPT-4 对话?

openai-api - 如何计算整个ChatGPT对话的token?

python - 聊天 GPT3.5-turbo API 不打印聊天响应。没有代码错误

openai-api - ChatGPT - 确定响应是否为 "not unknown"的方法?

python - 如何修复 TypeError : load() missing 1 required positional argument: 'Loader' error in Colab?

python - 如何向 RetrievalQA.from_chain_type 添加内存?或者,如何向 ConversationalRetrievalChain 添加自定义提示?

openai-api - OpenAI API Codex 模型中的上下文窗口长度

python - 有没有办法可以处理 Langchain QA 检索中的上下文和一般问题?

python - 如何创建内存存储以用作 OpenAI-ChatGPT Python 脚本的上下文信息?

python - 将聊天响应放入 GPT API 中的列表中