当前位置: 首页 > article >正文

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


http://www.kler.cn/news/288537.html

相关文章:

  • OpenCVSharp中基本绘图函数
  • Qt Dialog退出事件
  • Golang使用Quic-Go开源库实现Quic客户端和服务端
  • Unity接入飞行遥杆外设
  • 【BES2500x系列 -- RTX5操作系统】Battery模块 -- 创建电池检测定时器 --(十五)
  • 利用Spring Boot的@Transactional注解保障业务数据的一致性
  • 2024 【Delphi 12】苹果ios开发环境配置(五星保姆级)
  • UML(ER) manual book
  • 深入理解Java序列化:从入门到实践
  • c++ std::advance 使用简介
  • MySQL库表设计规范
  • IMU助力预测青少年脊柱侧弯
  • Apache DolphinScheduler大规模任务调度系统对大数据实时Flink任务支持
  • TikTok运营:IP地址如何影响TikTok的内容运营?
  • 内存管理篇-20 Linux虚拟内存管理
  • 亚信安全荣获“2024年网络安全优秀创新成果大赛”优胜奖
  • 缓存预热有哪些方案?
  • Java面试题真题·项目介绍部分总结
  • 【测试】bug 相关知识点总结
  • 单片机原理图与PCB设计心得体会
  • 解决Qt Creator与MSVC不匹配的问题
  • WebView快速打开
  • 【Linux】FRP:内网穿透
  • 第十二章 rust中的项目管理
  • PHP一键创建全球参与探索现代在线投票系统
  • sql 优化,提高查询速度
  • 阿里巴巴开源大作:EchoMimic—数字人技术的颠覆者
  • 【无标题】奥沙
  • Pandas 16-条件格式化
  • Ozon现在什么品类好卖,OZON热销类目