分类
AI nlp

OpenAI GPT API 初探:价格,成本、模型选择以及中英文文本摘要篇

注意:本文介绍的是GPT-3 API的价格,目前OpenAI已经推出ChatGPT API,简而言之,新API价格是GPT-3最好模型的1/10,速度也将近快了10倍。强烈建议迁移你的代码到ChatGPT API。需要做的改动并不大,而且效果也会更好。

ChatGPT 最近非常火爆,甚至完全出圈。早在 GPT-3 发布的时候,我就非常关注。但是当时没进行具体的开发,只是看了看 API 做了一些实验。现在 ChatGPT 这么火爆,而且功能这么强大,我觉得我以前想做的很多产品,都可以利用这样的 AI 能力去实现。所以我决定开始写一些产品,用 ChatGPT 和其他 AI 模型的能力去打造产品。

目前 ChatGPT 的 API 还没出来,所以我先玩玩 GPT-3 的 API。其实 GPT3 的 API 已经非常强大了。现在笔记软件 Craft 和 Notion 里面的 AI 功能也是用 GPT-3 实现的,我目前的视频创作和写作中经常用到它们。Github 的 Copilot 其实也是用 GPT-3 的 API 实现的。我准备先玩玩 GPT-3 的 API,慢慢等 OpenAI 开放 ChatGPT 的 API。

价格

目前按照模型的报价如下:

  • Ada(最快,效果最差)$0.0004  / 1K tokens
  • Babbage $0.0005  / 1K tokens
  • Curie $0.0020  / 1K tokens
  • Davinci(效果最好) $0.0200  / 1K tokens

可以看得出来价格很悬殊。最贵的和最便宜的价格差异是50倍。

按照文档 1000 个 tokens 大概折合 750 个英文单词。

我找了一篇今天的新闻,纯文本的,如下:

Michigan State University shooting leaves five wounded; manhunt underway for suspect

A gunman opened fire inside an academic hall on Michigan State University's campus on Monday evening, leaving at least five people wounded, according to police. 

The suspect, described as a short Black male wearing black pants, a blue jacket, and red shoes, was still on the run as of 11:30 p.m. 

All five victims, some of whom have life-threatening wounds, were transported to Sparrow Hospital for treatment. 

Hundreds of law enforcement officers from several different agencies were involved in the search for the suspect. 


The suspect was described as a short Black male wearing a blue jacket, black pants, and red shoes.  (MSU Police)

The shooting started at 8:18 p.m. inside Berkey Hall, which is home to MSU's Department of Sociology on the northern boundary of campus. 

The school sent out a shelter-in-place order at 8:31 p.m., telling students to stay inside and barricade themselves. 

"Run, Hide, Fight," MSU said in the alert. "Run means evacuate away from danger if you can do so safely, Hide means to secure-in-place, and Fight means protect yourself if no other option."

The gunman then went from Berkey Hall to the MSU Union a short walk away and opened fire, according to police. 

Emergency personnel respond to a shooting at Michigan State University in East Lansing, Michigan, February 13, 2023. 
Emergency personnel respond to a shooting at Michigan State University in East Lansing, Michigan, February 13, 2023.  (Matthew Dae Smith/USA TODAY Network via REUTERS )

Ben Finkelstein, a senior at MSU, said that he was hiding under his bed after hearing two faint shots earlier in the evening. 

"I've never been more afraid than I am now," Finkelstein told Fox News Digital. "I'm shaking."

按照 Word 计算有 291 个单词,计算空格的话,有 1777 个字符。在 OpenAI 的 API playground 上说有 424 个 tokens。

我们假设一篇新闻的长度都是这样的,比如我们做个产品要处理新闻,我们要处理10000篇新闻的话,我算了一个价格出来。也就是我们的每日成本为:(424*10000/1000*price)

  • Ada:1.696 美金
  • Babbage:2.12 美金
  • Curie:8.48 美金
  • Davinci:84.8 美金

所以,简单结论要是用来处理长文本,甚至比我刚才的新闻更长的内容还真有点贵。

但是如果你的任务是给推特分类,看情绪是负面的还是正面的内容,例如这个例子:

Classify the sentiment in these tweets:

1. "I can't stand homework"
2. "I can't wait for Halloween!!!"

Tweet sentiment ratings:

1. Negative
2. Positive

这个例子是把前面最后一个冒号前的内容交给 GPT-3,它就可以告诉你,第一条是负面推文,第二条是正面推文。这个任务的 tokens 数量为36个。我们也可以算算价格,同样假设做10000次:(36*10000/1000*price)

  • Ada:0.144 美金
  • Babbage:0.18 美金
  • Curie:0.72 美金
  • Davinci:7.2 美金

结论是文字越多越贵,要根据自己的任务来计算会花多少钱。事先有一个估计,免得回头承受不了。

不同的模型

其实 OpenAI 不只有泛化的 GPT-3 模型,还有针对特定任务的模型,比如 Codex 专注代码生成,和 Content filter 专注内容是否安全(敏感信息或者不良信息),我们暂时只讨论 GPT-3 模型。

不同的模型(来自文档,我们后面会测试):

  • 达芬奇(Davinci)
    最强大的 GPT-3,也是最贵的,可以做其他模型做的一切事情。一般质量更高,结果更长,更遵守指示。
    对于需要对内容有很多理解的应用,例如针对特定受众的摘要和创意内容生成,达芬奇将产生最佳结果。这些增强的功能需要更多的计算资源,因此每个 API 调用的成本更高,并且速度不如其他模型。
    达芬奇在理解文本意图方面也是一大亮点。达芬奇非常擅长解决许多种逻辑问题并解释字符的动机。达芬奇已经能够解决一些涉及因果关系的最具挑战性的 AI 问题。
    擅长于:复杂意图、因果关系、针对受众的摘要
  • 居里(Curie)
    非常强大,但速度非常快。尽管在分析复杂文本方面达芬奇更强大,但居里非常擅长许多微妙的任务,如情感分类和摘要。居里在回答问题和执行问答以及作为普通服务聊天机器人方面也非常擅长。
    擅长于:语言翻译、复杂分类、文本情感、摘要
  • 巴贝奇(Babbage)
    可以执行简单分类等简单任务。当涉及语义搜索(Semantic Search)对文档与搜索查询的匹配程度进行排名时,它也非常有能力。
    擅长于:中等分类、语义搜索分类
  • 艾达(Ada)
    通常是最快的模型,可以执行解析文本、地址校正和某些不需要太多细微差别的分类任务。提供更多上下文信息可以提高艾达的性能。
    擅长于:解析文本、简单分类、地址校正、关键字

简单的结论是,因为 GPT-3 可以做很多任务,我们一个复杂的系统也需要很多能力,但是都用一个模型,最好的模型,比如 Davinci 的话,可能太贵。如果 Ada 或者其他低级模型可以做的事情,尽量不用 Davinci ,可以省钱,还可以让系统变得更快。

效果比较

今天我们只比较摘要,未来我们会尽量把可以用到的能力都拿来比较一下。

一开始不用写代码,进入 playground ,就可以测试了。把我刚才找的新闻,粘到 playground 的输入框里面,前面加上”Summarize:”说明任务是摘要。

然后点击下面submit按钮,就开始生成结果了。

结果以绿色背景的形式输出。

基本操作非常简单,但是注意,在 playground 里面测试和实际使用 API 都是一样收费的。只不过,每个用户注册,默认有 18 美金的余额,不用充钱也可以玩一阵子。

那么我们现在比较,几个模型生成的结果,首先大概介绍下这个新闻,其实说的是密歇根州立大学昨天有一个枪击案,5人受伤,截止到发稿罪犯还没找到。我们可以看看不同模型的结果有什么区别。结果翻译我用了 DeepL ,省一点我的 API 调用费用。 Temperature 设置为0.2。

Davinci

Five people were wounded in a shooting at Michigan State University on Monday evening. The suspect, a short Black male wearing black pants, a blue jacket, and red shoes, is still on the run and a manhunt is underway. All five victims were transported to Sparrow Hospital for treatment, some with life-threatening wounds. Hundreds of law enforcement officers from several different agencies are involved in the search for the suspect. The school sent out a shelter-in-place order and students were told to "Run, Hide, Fight."

翻译:

周一晚上,密歇根州立大学发生枪击事件,5人受伤。嫌疑人是一名矮小的黑人男子,身穿黑色裤子、蓝色夹克和红色鞋子,目前仍在逃,追捕行动正在进行中。所有五名受害者都被送往斯帕罗医院接受治疗,有些人的伤口有生命危险。来自多个不同机构的数百名执法人员参与了对嫌犯的搜捕。学校发出了就地收容的命令,学生们被告知要 "跑、藏、打"。

Curie

As of 11:30 p.m., the search was still ongoing.

翻译:

截至晚上11点30分,搜索工作仍在进行。

Babbage

The suspect is described as a short Black male wearing black pants, a blue jacket, and red shoes. (MSU Police)

The search for the suspect began at 11:30 p.m. and is ongoing. 

Five people were wounded in the shooting, including the gunman, and are in serious condition. 

The suspect is described as a short Black male wearing black pants, a blue jacket, and red shoes. (MSU Police)

翻译:

嫌疑人被描述为一名矮小的黑人男子,身穿黑色裤子,蓝色夹克,红色鞋子。(MSU Police)

对嫌疑人的搜索从晚上11点30分开始,目前正在进行。

有五人在枪击事件中受伤,其中包括枪手,伤势严重。

嫌疑人被描述为一个矮小的黑人男子,身穿黑色裤子,蓝色夹克,红色鞋子。(MSU Police)

Ada

All five people injured in the shooting are students at MSU, including three women and a man. 
The suspect is a short, Black male wearing a blue jacket and red shoes.

翻译:

在枪击事件中受伤的五人都是MSU的学生,包括三名女性和一名男性。
嫌疑人是一名矮小的黑人男性,身穿蓝色夹克和红色鞋子。

结果明显是 Davinci 比较好,比较意外的是在这个具体的任务里,Babbage 的效果好于 Ada, Ada 好于 Curie,跟文档的描述不符合。

然后,我又测试了几个开源模型的摘要引擎:

Google/Pegasus-large

地址:https://huggingface.co/google/pegasus-large

这是开源的模型介绍地址,在地址里面你也可以测试该模型。

Michigan State University shooting leaves five wounded; manhunt underway for suspect A gunman opened fire inside an academic hall on Michigan State University's campus on Monday evening, leaving at least five people wounded, according to police. The suspect, described as a short Black male wearing black pants, a blue jacket, and red shoes, was still on the run as of 11:30 p.m.

翻译:

密歇根州立大学枪击案造成五人受伤;正在追捕嫌犯 据警方透露,周一晚间,一名枪手在密歇根州立大学校园内的学术厅内开枪,造成至少五人受伤。嫌犯被描述为一名身穿黑色裤子、蓝色夹克和红色鞋子的矮小黑人男子,截至晚上11点30分,他仍在逃。

Facebook/Bart-large-cnn

地址:https://huggingface.co/facebook/bart-large-cnn

Michigan State University shooting leaves five wounded; manhunt underway for suspect. Gunman opened fire inside an academic hall on Michigan State University's campus on Monday evening, leaving at least five people wounded. The suspect, described as a short Black male wearing black pants, and red shoes, was still on the run as of 11:30 p.m.

翻译:

密歇根州立大学枪击案造成5人受伤,正在追捕嫌犯。周一晚上,枪手在密歇根州立大学校园内的一个学术厅内开火,造成至少五人受伤。据描述,嫌疑人是一名身穿黑色裤子和红色鞋子的矮小黑人男子,截至晚上11点30分,他仍然在逃。

Google/Pegasus-cnn_dailymail

地址:https://huggingface.co/google/pegasus-cnn_dailymail

A gunman opened fire inside an academic hall on Michigan State University's campus on Monday evening, leaving at least five people wounded .<n>The suspect, described as a short Black male wearing black pants, a blue jacket, and red shoes, was still on the run as of 11:30 p.m.<n>All five victims, some of whom have life-threatening wounds, were transported to Sparrow Hospital for treatment .

翻译:

周一晚间,一名枪手在密歇根州立大学校园内的学术厅内开枪,造成至少5人受伤。<n>据描述,嫌疑人是一名矮小的黑人男子,身穿黑色裤子、蓝色夹克和红色鞋子,截至晚上11:30,他仍在逃。<n>所有5名受害者,其中一些人有生命危险,被送往斯帕罗医院治疗。

Philschmid/Bart-large-cnn-samsum

地址:https://huggingface.co/philschmid/bart-large-cnn-samsum

Gunman opened fire inside an academic hall on Michigan State University's campus on Monday evening, leaving at least five people wounded. The shooting started at 8:18 p.m. inside Berkey Hall, which is home to the Department of Sociology on the northern boundary of campus. The school sent out a shelter-in-place order. Ben Finkelstein, a senior at MSU, was hiding under his bed after hearing two faint shots earlier in the evening.

翻译:

周一晚上,枪手在密歇根州立大学校园的一个学术厅内开枪,造成至少5人受伤。枪击事件于晚上8点18分在伯基厅内开始,该厅是位于校园北部边界的社会学系的所在地。学校发出了就地避难的命令。MSU的大四学生本-芬克尔斯坦(Ben Finkelstein)在晚上早些时候听到两声微弱的枪声后躲在床下。

基本上,我们可以看到,GPT-3 的效果相当不错,跟那几个大厂出的开源的模型做摘要效果差不多。

那么我们为什么要用 GPT-3 呢,是因为它什么都能干,摘要也只是它的一部分而已。而且他还能做中文英文都可以。

比如,我用我之前 Blog 的片段:

我是从92年,上初中的时候开始写代码的。2001年大学毕业以后,我的工作也一直都在写代码,写了20年。

那时候也有一些所谓高光时刻。

我在09年第一次创业,做一家搜索和技术咨询的公司。

如果你用过大众点评、饭统,当时北京和上海最大的两家餐饮相关的网站。那么你就用过我写的代码。他们的搜索,在很长一段时间都是我们做的。六间房的搜索也是我们做的,六间房是当时排在优酷和土豆后面的,全国第三名的视频网站。当然还有一些其他的公司,比如英国金融时报的中国版,等。

09年的时候,iPhone SDK刚刚火起来以后。有道准备做有道词典iOS版的时候,他们找不到人做,就辗转找到我。让我帮他们做了第一个版本。当然这仅仅是一个小的外包项目。


再后来第一次搜索创业失败以后,我和合伙人先后进入了盛大。我在盛大待了一年,最后一段时间,我负责整个盛大云中书城的iOS端,代码基本上都是我一个人写的。因为当时盛大也没有几个人会写iOS代码。你知道当年最火的起点,一堆国内文学网站,都是属于盛大云中书城的。

在国内iOS/iPhone的开发比较前期的时候,我还是比较闪亮的。那个时间点人才比较少。

然后我离开盛大以后,自己创业了几年。后来又去过两家公司去管技术团队,管了两年。

再后来我抑郁了半年多,窝在家里,再后来,我就没再出门工作过了。生活主要就是靠写作,靠微信公众号啊。偶尔做点视频。

但是我也有1年左右没写过代码了,也是2022年下半年才开始恢复的。

用 GPT-3 生成结果:

Davinci:

这是一个关于一个人20年来一直从事编程的故事。从1992年开始,他一直在写代码,直到2022年下半年才恢复。他曾经参与过许多知名公司的项目,包括大众点评、饭统、六间房、英国金融时报的中国版等。他也曾经创业过,并在盛大担任过一年的技术负责人。之后他又创业了几年,然后去过两家公司管技术团队,之后又抑郁了半年多,最后以写作和微信公众号为主,直到2022年下半年才恢复编程。

Curie:

This person has been coding for over 20 years and has worked in various positions in the software industry, including writing code for search engines and technology consulting companies. In 2009, he started his own company, which failed after a year. In 2012, he went back to two other companies to work in technology teams before founding his own company again in 2016.

In the early days of iPhone development, he was one of the few people who could write code for the platform. He also worked on the first version of the Chinese version of the website for the largest restaurant chain in Beijing and Shanghai at the time.

In 2009, when iPhone SDKs were just starting to become popular, he was hired to work on a dictionary app for iOS. He later worked on six other apps for the company before leaving in 2012.

In 2016, he founded his own company again. Since then, he has not written any code. He spends most of his time writing and doing videos.

Babbage:

代码是一个很重要的工作。


代码是一个很重要的工作。它是一个很重要的途径,一个很重要的途径是通过代码来实现什么。代码是一个通道,通道是一个很重要的途径。

代码是一个很重要的途径,通道是一个很重要的途径。代码是一个通道,通道是一个很重要的途径。代码是一个通道,通道是一个很重要的途径。

Ada:

在2020年才开始写代码了。

写代码是一直都在写的。

2002年,我开始了iPhone SDK。

2011年,我接轨了iPhone SDK的开发者。

2016年,我接轨了iPhone SDK的开发者。

2018年,我接轨了iPhone SDK的开发者。

2022年,我写了代码。

结论是,英文中文,GPT-3 都可以处理的很好。Davinci效果是完美的。只是很奇怪,Curie 理解了,但是输出的是英文。Babbage 和 Ada 的效果基本上是不可接受的。

而刚才那四个在英文摘要上效果很好的开源模型,则完全不能处理中文内容,大家可以自行测试。

敬请期待后续文章,我会继续介绍 GPT-3 API 可以干什么,以及我测试的不同模型下表现,以及可以做类似任务的其他开源模型的效果。

打赏

“OpenAI GPT API 初探:价格,成本、模型选择以及中英文文本摘要篇”上的5条回复

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据