gpt4 book ai didi

r - 开放人工智能 API : Can I remove the line break from the response with a parameter?

转载 作者:行者123 更新时间:2023-12-02 05:46:33 25 4
gpt4 key购买 nike

我开始在 R 中使用 OpenAI API。我下载了 openai 包。我在文本响应中不断遇到双换行符。这是我的代码示例:


library(openai)

vector = create_completion(
model = "text-davinci-003",
prompt = "Tell me what the weather is like in London, UK, in Celsius in 5 words.",
max_tokens = 20,
temperature = 0,
echo = FALSE
)


vector_2 = vector$choices[1]

vector_2$text


[1] "\n\nRainy, mild, cool, humid."

有没有办法在不使用其他函数“更正”响应文本的情况下摆脱这种情况?

最佳答案

不,这不可能。

默认情况下,OpenAI API 返回带有起始 \n\n 的完成。 Completions endpoint 没有参数控制这个。

您需要手动删除换行符。

示例响应如下所示:

{
"id": "cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7",
"object": "text_completion",
"created": 1589478378,
"model": "text-davinci-003",
"choices": [
{
"text": "\n\nThis is indeed a test",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 5,
"completion_tokens": 7,
"total_tokens": 12
}
}

关于r - 开放人工智能 API : Can I remove the line break from the response with a parameter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75299615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com