OpenAI API: Can I remove the line break from the response with a parameter?

题意:OpenAI API:我可以通过一个参数从响应中移除换行符吗?

问题背景:

I've starting using OpenAI API in R. I downloaded the openai package. I keep getting a double linebreak in the text response. Here's an example of my code:

我开始在 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."

Is there a way to get rid of this without 'correcting' the response text using other functions?

有没有办法在不使用其他函数来“修正”响应文本的情况下去除这个问题?

问题解决:

No, it's not possible.        不,可可能

The OpenAI API returns the completion with a starting \n\n by default. There's no parameter for the Completions endpoint to control this.

OpenAI API 默认会在返回的完成文本前加上 `\n\n`。对于 Completions 端点,没有参数可以控制这一点。

You need to remove the line break manually.        你需要手动去掉换行符

An example response looks like this:        一个示例响应如下所示:

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

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值