system 第二章加入一些文字描述
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "3e71eee8",
|
"id": "3e71eee8",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -9,6 +10,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "c7e800b0",
|
"id": "c7e800b0",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -92,7 +94,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 1,
|
||||||
"id": "b8b8f1c7",
|
"id": "b8b8f1c7",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -104,10 +106,11 @@
|
|||||||
"# from dotenv import load_dotenv, find_dotenv\n",
|
"# from dotenv import load_dotenv, find_dotenv\n",
|
||||||
"# _ = load_dotenv(find_dotenv()) # 读取本地的.env环境文件\n",
|
"# _ = load_dotenv(find_dotenv()) # 读取本地的.env环境文件\n",
|
||||||
"\n",
|
"\n",
|
||||||
"openai.api_key = 'sk-xxxxxxxxxxxx' #更换成你自己的key"
|
"openai.api_key = '***' #更换成你自己的key"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "19cf84a8",
|
"id": "19cf84a8",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -118,7 +121,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 15,
|
"execution_count": 2,
|
||||||
"id": "3fda8d03",
|
"id": "3fda8d03",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -136,6 +139,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"attachments": {},
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"id": "536ad0c2",
|
"id": "536ad0c2",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@ -236,6 +240,19 @@
|
|||||||
""
|
""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"attachments": {},
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "c06944b4",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"对于英文输入,一个 token 一般对应4个字符或者四分之三个单词;对于中文输入,一个 token 一般对应一个或半个词。\n",
|
||||||
|
"\n",
|
||||||
|
"不同模型有不同的 token 限制,需要注意的是,这里的 token 限制是输入的 prompt 和输出的 completion 的 token 数之和,因此输入的 prompt 越长,能输出的 completion 的上限就越低。\n",
|
||||||
|
"\n",
|
||||||
|
"ChatGPT3.5 的 token 上限是 4096。"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"attachments": {
|
"attachments": {
|
||||||
"image.png": {
|
"image.png": {
|
||||||
@ -252,13 +269,23 @@
|
|||||||
""
|
""
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"attachments": {},
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"id": "ffafb0f1",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"System 信息用于制定模型的规则,例如设定、回答准则一类的,而 assistant 信息就是具体让模型完成的指令"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": 3,
|
||||||
"id": "bd009d67",
|
"id": "bd009d67",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
|
"# 支持更多参数自定义的封装函数\n",
|
||||||
"def get_completion_from_messages(messages, \n",
|
"def get_completion_from_messages(messages, \n",
|
||||||
" model=\"gpt-3.5-turbo\", \n",
|
" model=\"gpt-3.5-turbo\", \n",
|
||||||
" temperature=0, \n",
|
" temperature=0, \n",
|
||||||
@ -274,7 +301,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": 4,
|
||||||
"id": "e09def17",
|
"id": "e09def17",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@ -282,20 +309,25 @@
|
|||||||
"name": "stdout",
|
"name": "stdout",
|
||||||
"output_type": "stream",
|
"output_type": "stream",
|
||||||
"text": [
|
"text": [
|
||||||
"在海洋深处有一个小鲸鱼,\n",
|
"在蓝色的海洋深处,\n",
|
||||||
"它快乐的游啊游,\n",
|
"有一只小鲸鱼嬉闹着。\n",
|
||||||
"它的身体白晃晃,\n",
|
"它游啊游,欢笑着,\n",
|
||||||
"好像穿着白雪的衣裳。\n",
|
"尽情享受自由的感受。\n",
|
||||||
"\n",
|
"\n",
|
||||||
"它游来游去,玩得很开心,\n",
|
"它跳啊跃,翻滚着,\n",
|
||||||
"偶尔还秀一下游泳技能,\n",
|
"好像永远都停不下来。\n",
|
||||||
"小鲸鱼是个聪明的孩子,\n",
|
"它的身体,是那么轻盈,\n",
|
||||||
"它让波涛跟着它摇晃。\n",
|
"好像没有任何重量。\n",
|
||||||
"\n",
|
"\n",
|
||||||
"快乐的小鲸鱼,\n",
|
"它的笑声,犹如海浪,\n",
|
||||||
"带给海洋欢乐的音符,\n",
|
"响彻于大海深处。\n",
|
||||||
"我们也跟着它笑起来,\n",
|
"它的快乐,也如海浪,\n",
|
||||||
"真是一个美好的夏日午后。\n"
|
"绵延不绝,没有尽头。\n",
|
||||||
|
"\n",
|
||||||
|
"啊,这可爱的小鲸鱼,\n",
|
||||||
|
"让人忍不住想嬉闹。\n",
|
||||||
|
"让我们跟它一起游,\n",
|
||||||
|
"在蓝色的海洋里畅游。\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -364,7 +396,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 5,
|
||||||
"id": "b0907cac",
|
"id": "b0907cac",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -385,8 +417,11 @@
|
|||||||
" content = response.choices[0].message[\"content\"]\n",
|
" content = response.choices[0].message[\"content\"]\n",
|
||||||
" \n",
|
" \n",
|
||||||
" token_dict = {\n",
|
" token_dict = {\n",
|
||||||
|
"# prompt 对应的 token 数\n",
|
||||||
"'prompt_tokens':response['usage']['prompt_tokens'],\n",
|
"'prompt_tokens':response['usage']['prompt_tokens'],\n",
|
||||||
|
"# completion 对应的 token 数\n",
|
||||||
"'completion_tokens':response['usage']['completion_tokens'],\n",
|
"'completion_tokens':response['usage']['completion_tokens'],\n",
|
||||||
|
"# 总共的 token 数\n",
|
||||||
"'total_tokens':response['usage']['total_tokens'],\n",
|
"'total_tokens':response['usage']['total_tokens'],\n",
|
||||||
" }\n",
|
" }\n",
|
||||||
"\n",
|
"\n",
|
||||||
@ -475,7 +510,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.9"
|
"version": "3.10.11"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
Reference in New Issue
Block a user