目录

GPT

由 OpenAI 训练的大型语言模型,也称为 Generative Pretrained Transformer。

版本 发布时间 模型参数 GPU内存 能力
GPT 2018年 1.17亿 8G 文本自动补全、问答、语句生成
GPT-2 2019年 15亿 16G 文本自动补全、问答、语句生成、命名实体识别、关系抽取
GPT-3 2020年 1750亿 32G 文本自动补全、问答、语句生成、命名实体识别、关系抽取、文本分类、翻译
GPT-3.5 2021年 1750亿 32G 基于 GPT-3 微调的一系列模型
  • 语言生成任务:文本自动补全、问答、语句生成
  • 语言理解任务:命名实体识别、关系抽取、文本分类、翻译

OpenAI API

模型能力

  • 执行各种自然语言任务的 GPT-3
  • 将自然语言翻译成代码的 Codex
  • 创建和编辑原始图像的 DALL·E

价格

  • 开始试用可在前 3 个月内使用 18 美元免费额度。
  • 1000 tokens 为 1 个计量单位
    • 一个汉字为 2 个 tokens
    • 大约 4 英文字母为 1 个 tokens
  • Tokenizer tool

Python 示例

调用 API 的参数

  • model: text-davinci-003 是基于 GPT-3 最好的模型,能力:复杂意图、因果关系、创建生成、搜索、总结等。
  • prompt: 请求的 tokens 最大数量 2048 - 4000。
  • temperature: 越高生成的结果随机性越大,0 意味着生成结果的确定性和稳定性。
  • max_tokens: 生成的最大 tokens 数。

Python 代码

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.Completion.create(model="text-davinci-003", prompt="Suggest one name for a horse.", temperature=0.6, max_tokens=500)
print(response)

使用 ChatGPT 的模型(gpt-3.5-turbo)进行多轮对话

import openai

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
        {"role": "system", "content": "你一位中国历史学者。"},
        {"role": "user", "content": "中国最伟大的女帝是谁?"},
        {"role": "assistant", "content": "中国历史上最伟大的女帝之一是武则天(624年-705年),她在唐朝时期担任过多个重要职位,包括嫔妃、太监、宰相等,并于690年成为唐朝的皇帝,直至705年逝世。武则天在位期间,她大力发展经济、加强军队,进行了一系列重要的改革和政策措施,使得唐朝在她的统治下保持了长期的繁荣和稳定。同时,武则天也倡导文化发展,推动了诗词、音乐、>绘画等艺术的繁荣,使得唐朝文化达到了巅峰。因此,武则天被后人称为“开辟了中国历史上女性争取政治地位的先河”的女皇帝。"},
        {"role": "user", "content": "她在位期间的主要政绩是。"}
    ]
)

print(completion)
print('-'*80)
print(completion.choices[0].message.content)

选择你的模型

ChatGPT

ChatGPT 是 OpenAI 基于 GPT 语言生成模型开发的,它可以生成各种语言文本,回答各种问题,进行各种对话,根据上下文进行文本生成,用于自然语言处理领域的应用。

速率限制

免费用户,每分钟 20 个请求或 15万个 Token。

付费用户,每分钟 3500 个请求或 35万个 Token。

中国用户购买 ChatGPT Plus

  1. 欧易数字货币交易所,通过微信或支付宝进行充值,转换为USDT货币(USDT 是一种稳定币,与美元等法定货币的价值保持1:1的固定比例。);
  2. Depay 应用中创建虚拟信用卡;
  3. 在欧易数字货币交易所进行提币,输入 Depay 应用中的充值地址,即可将USDT充值到虚拟信用卡中;
  4. 在 OpenAI 中订阅 ChatGPT Plus,通过虚拟信用卡进行支付。

ChatGPT 模型的提示示例

例子

Grammatical Standard English(语法标准英语)

Correct this to standard English:

She no went to the market.
将其更正为标准英语:

她没有去市场。

  • text-davinci-003 (Temperature: 0)
She did not go to the market.
她没有去市场。
  • ChatGPT
Corrected sentence:

She didn't go to the market.

Explanation:

The original sentence contains a double negative construction which is considered non-standard English. In standard English, we use the auxiliary verb "did" in the negative form to indicate that something did not happen in the past. Therefore, "no went" should be changed to "didn't go".
更正语句:

她没有去市场。

解释:

原句包含双重否定结构,被认为是非标准英语。 在标准英语中,我们使用否定形式的助动词“did”来表示过去没有发生的事情。 因此,“不去”应改为“没去”。

Summarize for a 2nd grader(给二年级学生总结)

Summarize this for a second-grade student:

Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.
给一个二年级的学生总结一下:

木星是距离太阳第五远的行星,也是太阳系中最大的行星。 它是一颗气体巨行星,质量是太阳的千分之一,但却是太阳系中所有其他行星总和的两倍半。 木星是夜空中肉眼可见的最亮天体之一,早> 在有记载的历史之前就已为古代文明所知。 它以罗马神木星命名。 [19] 从地球上看,木星的亮度足以使其反射光投下可见的阴影,[20] 平均而言,木星是继月球和金星之后夜空中第三亮的自然> 物体。

  • text-davinci-003 (Temperature: 0.7)
Jupiter is the fifth planet from the Sun and the biggest in our Solar System. It is very bright and can be seen in the night sky. It is named after the Roman god Jupiter. It is so bright that it can even cast shadows!
木星是太阳的第五颗行星,也是我们太阳系中最大的行星。 它非常明亮,可以在夜空中看到。 它以罗马神木星命名。 它是如此明亮,以至于它甚至可以投下阴影!
  • ChatGPT
Jupiter is a really big planet in our Solar System, and it's fifth from the Sun. It's much larger than all the other planets combined, but smaller than the Sun. People have known about Jupiter for a very long time, and it's named after a Roman god. At night, Jupiter looks very bright and it's one of the brightest things you can see in the sky. Sometimes it's so bright that it can even make shadows!
木星是我们太阳系中一颗非常大的行星,距离太阳第五。 它比所有其他行星的总和大得多,但比太阳小。 人们很早就知道木星,它以罗马神的名字命名。 到了晚上,木星看起来非常明亮,它是您在天空中可以看到的最亮的物体之一。 有时它是如此明亮,以至于它甚至可以产生阴影!

text to command(命令文本)

Convert this text to a programmatic command:

Example: Ask Constance if we need some bread
Output: send-msg `find constance` Do we need some bread?

Reach out to the ski store and figure out if I can get my skis fixed before I leave on Thursday
将此文本转换为编程命令:

示例:询问康斯坦斯我们是否需要一些面包
输出:send-msg `find constance` 我们需要面包吗?

去滑雪商店看看我是否可以在星期四离开前修好我的滑雪板

  • text-davinci-003 (Temperature: 0.7)
Output: send-msg `find ski store` Can I get my skis fixed before I leave on Thursday?
输出:send-msg `find ski store` 我可以在星期四离开前修好我的滑雪板吗?
  • ChatGPT
Output: send-msg `find ski store` Can I get my skis fixed before I leave on Thursday?
输出:send-msg `find ski store` 我可以在星期四离开前修好我的滑雪板吗?

Q&A(问答)

I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with "Unknown".

Q: What is human life expectancy in the United States?
A: Human life expectancy in the United States is 78 years.

Q: Who was president of the United States in 1955?
A: Dwight D. Eisenhower was president of the United States in 1955.

Q: Which party did he belong to?
A: He belonged to the Republican Party.

Q: What is the square root of banana?
A: Unknown

Q: How does a telescope work?
A: Telescopes use lenses or mirrors to focus light and make objects appear closer.

Q: Where were the 1992 Olympics held?
A: The 1992 Olympics were held in Barcelona, Spain.

Q: How many squigs are in a bonk?
A: Unknown

Q: Why is OpenAI not open for use in China?
我是一个高度智能的问答机器人。 如果你问我一个植根于真理的问题,我会给你答案。 如果你问我的问题是无稽之谈,骗人的,或者没有明确答案,我会回答“未知”。

问:美国人的预期寿命是多少?
答:美国人的预期寿命是78岁。

问:谁是 1955 年的美国总统?
答:德怀特·D·艾森豪威尔 (Dwight D. Eisenhower) 于 1955 年担任美国总统。

问:他属于哪个党派?
答:他属于共和党。

问:香蕉的平方根是多少?
答:未知

问:望远镜是如何工作的?
答:望远镜使用透镜或镜子来聚焦光线并使物体看起来更近。

问:1992年奥运会是在哪里举办的?
答:1992年奥运会在西班牙巴塞罗那举行。

问:一个 bonk 有多少个 squig?
答:未知

问:为什么OpenAI在中国不开放使用?

  • text-davinci-003 (Temperature: 0)
OpenAI is not open for use in China due to the Chinese government's restrictions on artificial intelligence technology.
由于中国政府对人工智能技术的限制,OpenAI 并未在中国开放使用。
  • ChatGPT
OpenAI is not open for use in China due to regulatory restrictions and government policies in China that limit access to certain types of artificial intelligence technologies developed outside of the country.
由于中国的监管限制和政府政策限制访问在国外开发的某些类型的人工智能技术,因此 OpenAI 未在中国开放使用。

English to other languages(英语到其他语言)

Translate this into 1. French, 2. Spanish and 3. Japanese:

What rooms do you have available?

将其翻译成 1. 法语、2. 西班牙语和 3. 日语:

你们有哪些房间?

  • text-davinci-003 (Temperature: 0.3)
1. Quels salles avez-vous disponibles?
2. ¿Qué habitaciones tienes disponibles?
3. どの部屋が利用可能ですか?
  • ChatGPT
1. French: Quelles chambres avez-vous de disponibles ?
2. Spanish: ¿Qué habitaciones tienen disponibles?
3. Japanese: どの部屋が利用可能ですか?

Parse unstructured data(解析非结构化数据)

A table summarizing the fruits from Goocrux:

There are many fruits that were found on the recently discovered planet Goocrux. There are neoskizzles that grow there, which are purple and taste like candy. There are also loheckles, which are a grayish blue fruit and are very tart, a little bit like a lemon. Pounits are a bright green color and are more savory than sweet. There are also plenty of loopnovas which are a neon pink flavor and taste like cotton candy. Finally, there are fruits called glowls, which have a very sour and bitter taste which is acidic and caustic, and a pale orange tinge to them.

| Fruit | Color | Flavor |
一张表格总结了 Goocrux 的成果:

在最近发现的 Goocrux 星球上发现了许多水果。 那里生长着新斯基兹,它们是紫色的,尝起来像糖果。 还有 loheckles,它是一种灰蓝色的水果,非常酸,有点像柠檬。 Pounits 呈亮绿> 色,咸味多于甜味。 还有很多 loopnovas,它们是霓虹粉的味道,尝起来像棉花糖。 最后,还有一种叫做 glowls 的水果,它有一种非常酸和苦的味道,具有酸性和腐蚀性,并带有淡橙色调。

| 水果 | 颜色 | 风味 |

  • text-davinci-003 (Temperature: 0)
Neoskizzles Purple Candy
Loheckles Grayish Blue Tart, like a lemon
Pounits Bright Green Savory
Loopnovas Neon Pink Cotton Candy
Glowls Pale Orange Sour and Bitter, Acidic and Caustic
新技能 紫色 糖果
洛赫克斯 灰蓝色 酸,像柠檬
亮绿色 咸味
循环新星 霓虹粉 棉花糖
发光 淡橙色 酸和苦,酸性和腐蚀性
  • ChatGPT
Fruit Color Flavor
Neoskizzles Purple Candy-like
Loheckles Grayish Blue Tart/Lemon-like
Pounits Bright Green Savory
Loopnovas Neon Pink Cotton candy-like
Glowls Pale Orange Sour and Bitter
水果 颜色 风味
新技能 紫色 糖果般的
洛赫克斯 灰蓝色 酸/柠檬味
亮绿色 咸味
循环新星 霓虹粉 棉花糖般的
发光 淡橙色 又酸又苦

Classification(分类)

The following is a list of companies and the categories they fall into:

Apple, Facebook, Fedex

Apple
Category:
以下是公司名单及其所属类别:

苹果、脸书、联邦快递

苹果
类别:

  • text-davinci-003 (Temperature: 0)
Technology
  • ChatGPT
Unknown - You have not provided any categories for me to assign to Apple. Please provide more information or specific categories for me to categorize Apple, Facebook, and Fedex.
未知 - 您没有提供任何类别供我分配给 Apple。 请提供更多信息或具体类别,以便我对 Apple、Facebook 和 Fedex 进行分类。

Natural language to python

"""
1. Create a list of first names
2. Create a list of last names
3. Combine them randomly into a list of 100 full names
"""
1. 创建名字列表
2. 创建姓氏列表
3. 随机组合成100个全名的列表

  • code-davinci-002 (Temperature: 0)
import random

first_names = ['John', 'Jane', 'Corey', 'Travis', 'Dave', 'Kurt', 'Neil', 'Sam', 'Steve', 'Tom', 'James', 'Robert', 'Michael', 'Charles', 'Joe', 'Mary', 'Maggie', 'Nicole', 'Patricia', 'Linda', 'Barbara', 'Elizabeth', 'Laura', 'Jennifer', 'Maria']

last_names = ['Smith', 'Doe', 'Jenkins', 'Robinson', 'Davis', 'Stuart', 'Jefferson', 'Jacobs', 'Wright', 'Patterson', 'Wilks', 'Arnold', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor', 'Anderson', 'Thomas', 'Jackson', 'White', 'Harris', 'Martin']

full_names = []

for i in range(100):
    first = random.choice(first_names)
    last = random.choice(last_names)
    full_names.append(f"{first} {last}")

print(full_names)
  • text-davinci-003 (Temperature: 0.7)
#1.
first_names = ["John", "Mary", "Sue", "Joe", "Amy", "Jason", "Kelly", "Ryan", "Paul", "Anne"]

#2.
last_names = ["Smith", "Jones", "Williams", "Brown", "Davis", "Miller", "Wilson", "Taylor", "Anderson", "Thomas"]

#3.
import random

full_names = []

for i in range(100):
    first_name = random.choice(first_names)
    last_name = random.choice(last_names)
    full_name = first_name + " " + last_name
    full_names.append(full_name)
    
print(full_names)
  • ChatGPT

Here’s an example code in Python that performs the tasks you described:

import random

# 1. List of first names
first_names = ["Emma", "Noah", "Olivia", "Liam", "Ava", "William", "Sophia", "Mason", "Isabella", "James"]

# 2. List of last names
last_names = ["Smith", "Johnson", "Brown", "Taylor", "Miller", "Wilson", "Davis", "Garcia", "Martinez", "Anderson"]

# 3. Combine randomly into a list of 100 full names
full_names = []
for i in range(100):
    full_name = random.choice(first_names) + " " + random.choice(last_names)
    full_names.append(full_name)

print(full_names)
['Noah Wilson', 'Emma Anderson', 'Isabella Taylor', 'William Davis', 'James Johnson', 'Sophia Brown', 'Noah Garcia', 'Sophia Anderson', 'Mason Brown', 'Olivia Davis', 'Emma Wilson', 'Sophia Garcia', 'Ava Davis', 'William Johnson', 'Isabella Taylor', 'Emma Brown', 'William Martinez', 'James Anderson', 'Emma Wilson', 'William Martinez', 'Mason Anderson', 'Sophia Smith', 'Olivia Martinez', 'Isabella Taylor', 'William Anderson', 'Mason Davis', 'Ava Smith', 'Noah Wilson', 'James Davis', 'William Anderson', 'Olivia Wilson', 'Mason Garcia', 'Isabella Anderson', 'Emma Davis', 'William Martinez', 'Sophia Davis', 'Ava Anderson', 'Olivia Martinez', 'Ava Brown', 'William Johnson', 'Isabella Brown', 'Mason Wilson', 'James Davis', 'Emma Brown', 'Sophia Davis', 'Ava Martinez', 'William Smith', 'James Johnson', 'Isabella Davis', 'Noah Brown', 'Sophia Garcia', 'Olivia Smith', 'James Martinez', 'Ava Brown', 'Noah Wilson', 'Isabella Anderson', 'Emma Wilson', 'Mason Johnson', 'William Smith', 'Sophia Taylor', 'Olivia Anderson', 'James Martinez', 'Ava Wilson', 'Isabella Smith', 'William Brown', 'Emma Smith', 'Noah Davis', 'Mason Wilson', 'Olivia Brown', 'Sophia Davis', 'Isabella Anderson', 'Ava Martinez', 'James Brown', 'William Davis', 'Emma Smith', 'Mason Brown', 'Olivia Davis', 'Sophia Anderson', 'Noah Johnson', 'Isabella Martinez', 'Ava Smith', 'William Wilson', 'James Smith', 'Emma Martinez', 'Olivia Wilson', 'Sophia Johnson', 'Mason Martinez', 'Isabella Wilson', 'William Davis', 'Ava Johnson', 'James Brown', 'Emma Wilson', 'Olivia Davis', 'Noah Martinez', 'Sophia Smith', 'Isabella Johnson', 'William Wilson']

Explain code(解释代码)

class Log:
    def __init__(self, path):
        dirname = os.path.dirname(path)
        os.makedirs(dirname, exist_ok=True)
        f = open(path, "a+")

        # Check that the file is newline-terminated
        size = os.path.getsize(path)
        if size > 0:
            f.seek(size - 1)
            end = f.read(1)
            if end != "\n":
                f.write("\n")
        self.f = f
        self.path = path

    def log(self, event):
        event["_event_id"] = str(uuid.uuid4())
        json.dump(event, self.f)
        self.f.write("\n")

    def state(self):
        state = {"complete": set(), "last": None}
        for line in open(self.path):
            event = json.loads(line)
            if event["type"] == "submit" and event["success"]:
                state["complete"].add(event["id"])
                state["last"] = event
        return state

"""
Here's what the above class is doing:
1.
这是上面的类正在做的事情:
1.

  • code-davinci-002 (Temperature: 0)
1. It creates a directory for the log file if it doesn't exist.
2. It checks that the log file is newline-terminated.
3. It writes a newline-terminated JSON object to the log file.
4. It reads the log file and returns a dictionary with the following
1. 如果日志文件不存在,它会为日志文件创建一个目录。
2. 检查日志文件是否以换行符结尾。
3. 它将以换行符结尾的 JSON 对象写入日志文件。
4. 它读取日志文件并返回一个包含以下内容的字典
  • ChatGPT
The above class is a Python implementation of a logging utility that allows users to write events to a log file. The class contains three methods:

* `__init__(self, path)`: The constructor method that creates a new log file with the given path if it doesn't exist and opens the file for appending. If the file already exists, it checks if the file ends with a newline character and adds one if it doesn't.
* `log(self, event)`: This method takes an event dictionary as an argument, adds a unique _event_id key to the dictionary using the uuid module, serializes the dictionary to JSON format and writes it to the log file. It then adds a newline character to separate the events in the file.
* `state(self)`: This method reads the log file line by line, parses each line as a JSON object and extracts the IDs of all completed events that were successful. It returns a dictionary that contains a set of completed event IDs and the last successful event as key-value pairs.

Overall, the Log class provides a simple and efficient way to log events and maintain state in a Python application.
上面的类是一个日志实用程序的 Python 实现,它允许用户将事件写入日志文件。 该类包含三个方法:

* `__init__(self, path)`: 如果给定路径不存在则创建一个新日志文件并打开文件进行附加的构造函数方法。 如果文件已经存在,它会检查文件是否以换行符结尾,如果没有则添加一个。
* `log(self, event)`: 此方法以事件字典作为参数,使用 uuid 模块将唯一的_event_id 键添加到字典中,将字典序列化为 JSON 格式并将其写入日志文件。 然后它添加一个换行符来分> 隔文件中的事件。
* `state(self)`:此方法逐行读取日志文件,将每一行解析为 JSON 对象并提取所有已成功完成的事件的 ID。 它返回一个字典,其中包含一组已完成的事件 ID 和最后一个成功的事件作为键> 值对。

总的来说,Log 类提供了一种在 Python 应用程序中记录事件和维护状态的简单而有效的方法。

Chat(聊天)

The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly.

Human: Hello, who are you?
AI: I am an AI created by OpenAI. How can I help you today?
Human: 
以下是与AI助手的对话。 助理乐于助人、富有创意、聪明而且非常友好。

人类:你好,你是谁?
AI:我是 OpenAI 创建的 AI。 今天我能帮到你什么?
人类:

  • text-davinci-003 (Temperature: 0.9)
AI: What kind of help do you need?
AI:你需要什么样的帮助?
  • ChatGPT
I'm looking for a good pizza place near me. Can you recommend one?
AI: Sure, I can help with that. What's your location?
我正在寻找离我最近的好披萨店。 你能推荐一个吗?
AI:当然,我可以帮忙。 你在什么位置?

ChatGPT 集成到微信

使用个人微信登录

有被腾讯公司封号的风险

微信公众号接入

ChatGPT 集成到企业微信

参考资料