update: 4,6

This commit is contained in:
hscspring
2023-04-28 23:49:15 +08:00
parent 3c478b3e41
commit 635b6fcfc2
2 changed files with 114 additions and 28 deletions

View File

@ -42,7 +42,9 @@
"outputs": [],
"source": [
"import openai\n",
"openai.api_key = 'sk-请输入你的api-key'\n",
"import os\n",
"OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\")\n",
"openai.api_key = OPENAI_API_KEY\n",
"\n",
"def get_completion(prompt, model=\"gpt-3.5-turbo\"): \n",
" messages = [{\"role\": \"user\", \"content\": prompt}]\n",
@ -80,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "4d9c0eeb",
"metadata": {},
"outputs": [],
@ -107,7 +109,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "43b5dd25",
"metadata": {},
"outputs": [],
@ -483,7 +485,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 5,
"id": "ee7caa78",
"metadata": {},
"outputs": [],
@ -563,10 +565,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "9d1aa5ac",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 Soft and cute panda plush toy loved by daughter, but a bit small for the price. Arrived early. \n",
"\n",
"1 Affordable lamp with storage, fast shipping, and excellent customer service. Easy to assemble and missing parts were quickly replaced. \n",
"\n",
"2 Good battery life, small toothbrush head, but effective cleaning. Good deal if bought around $50. \n",
"\n",
"3 The product was on sale for $49 in November, but the price increased to $70-$89 in December. The base doesn't look as good as previous editions, but the reviewer plans to be gentle with it. A special tip for making smoothies is to freeze the fruits and vegetables beforehand. The motor made a funny noise after a year, and the warranty had expired. Overall quality has decreased. \n",
"\n"
]
}
],
"source": [
"for i in range(len(reviews)):\n",
" prompt = f\"\"\"\n",
@ -578,7 +595,6 @@
"\n",
" Review: ```{reviews[i]}```\n",
" \"\"\"\n",
"\n",
" response = get_completion(prompt)\n",
" print(i, response, \"\\n\")"
]

View File

@ -28,13 +28,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 7,
"id": "ac57ad72",
"metadata": {},
"outputs": [],
"source": [
"import openai\n",
"openai.api_key = 'sk-请输入你的api-key'\n",
"import os\n",
"OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY2\")\n",
"openai.api_key = OPENAI_API_KEY\n",
"\n",
"def get_completion(prompt, model=\"gpt-3.5-turbo\", temperature=0): \n",
" messages = [{\"role\": \"user\", \"content\": prompt}]\n",
@ -202,7 +204,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"id": "21f3af91",
"metadata": {},
"outputs": [],
@ -218,10 +220,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "6a884190",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"原始消息 (法语): La performance du système est plus lente que d'habitude.\n",
"\n",
"中文翻译:系统性能比平时慢。\n",
"英文翻译The system performance is slower than usual. \n",
"=========================================\n",
"原始消息 (西班牙语): Mi monitor tiene píxeles que no se iluminan.\n",
"\n",
"中文翻译:我的显示器有一些像素点不亮。\n",
"英文翻译My monitor has pixels that don't light up. \n",
"=========================================\n",
"原始消息 (意大利语): Il mio mouse non funziona\n",
"\n",
"中文翻译:我的鼠标不工作了。\n",
"英文翻译My mouse is not working. \n",
"=========================================\n",
"原始消息 (波兰语): Mój klawisz Ctrl jest zepsuty\n",
"\n",
"中文翻译我的Ctrl键坏了\n",
"英文翻译My Ctrl key is broken. \n",
"=========================================\n",
"原始消息 (中文): 我的屏幕在闪烁\n",
"\n",
"中文翻译:我的屏幕在闪烁。\n",
"英文翻译My screen is flickering. \n",
"=========================================\n"
]
}
],
"source": [
"for issue in user_messages:\n",
" prompt = f\"告诉我以下文本是什么语种,直接输出语种,如法语,无需输出标点符号: ```{issue}```\"\n",
@ -257,7 +291,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "84ce3099",
"metadata": {},
"outputs": [
@ -428,7 +462,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 14,
"id": "b7d04bc0",
"metadata": {},
"outputs": [],
@ -446,10 +480,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"id": "1ef55b7b",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 The girl with the black and white puppies has a ball.\n",
"1 未发现错误。\n",
"2 It's going to be a long day. Does the car need its oil changed?\n",
"3 Their goes my freedom. They're going to bring their suitcases.\n",
"4 输出You're going to need your notebook.\n",
"5 That medicine affects my ability to sleep. Have you heard of the butterfly effect?\n",
"6 This phrase is to check chatGPT for spelling ability.\n"
]
}
],
"source": [
"for i in range(len(text)):\n",
" prompt = f\"\"\"请校对并更正以下文本,注意纠正文本保持原始语种,无需输出原始文本。\n",
@ -473,7 +521,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 18,
"id": "6696b06a",
"metadata": {},
"outputs": [],
@ -512,15 +560,37 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"id": "51de86c3",
"metadata": {},
"outputs": [],
"source": [
"response = \"\"\"\n",
"I got this for my daughter's birthday because she keeps taking mine from my room. Yes, adults also like pandas too. She takes it everywhere with her, and it's super soft and cute. However, one of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. It's also a bit smaller than I expected for the price. I think there might be other options that are bigger for the same price. On the bright side, it arrived a day earlier than expected, so I got to play with it myself before giving it to my daughter.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07f32f1f",
"metadata": {},
"outputs": [],
"source": [
"# 如未安装redlines需先安装\n",
"!pip3.8 install redlines"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "e8604dfb",
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"<span style=\"color:red;font-weight:700;text-decoration:line-through;\">Got </span><span style=\"color:red;font-weight:700;\">I got </span>this for my <span style=\"color:red;font-weight:700;text-decoration:line-through;\">daughter for her </span><span style=\"color:red;font-weight:700;\">daughter's </span>birthday <span style=\"color:red;font-weight:700;text-decoration:line-through;\">cuz </span><span style=\"color:red;font-weight:700;\">because </span>she keeps taking mine from my <span style=\"color:red;font-weight:700;text-decoration:line-through;\">room. </span><span style=\"color:red;font-weight:700;\">room. </span>Yes, adults also like pandas <span style=\"color:red;font-weight:700;text-decoration:line-through;\">too. </span><span style=\"color:red;font-weight:700;\">too. </span>She takes it everywhere with her, and it's super soft and <span style=\"color:red;font-weight:700;text-decoration:line-through;\">cute. One </span><span style=\"color:red;font-weight:700;\">cute. However, one </span>of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. It's <span style=\"color:red;font-weight:700;\">also </span>a bit <span style=\"color:red;font-weight:700;text-decoration:line-through;\">small </span><span style=\"color:red;font-weight:700;\">smaller than I expected </span>for <span style=\"color:red;font-weight:700;text-decoration:line-through;\">what I paid for it though. </span><span style=\"color:red;font-weight:700;\">the price. </span>I think there might be other options that are bigger for the same <span style=\"color:red;font-weight:700;text-decoration:line-through;\">price. It </span><span style=\"color:red;font-weight:700;\">price. On the bright side, it </span>arrived a day earlier than expected, so I got to play with it myself before <span style=\"color:red;font-weight:700;text-decoration:line-through;\">I gave </span><span style=\"color:red;font-weight:700;\">giving </span>it to my <span style=\"color:red;font-weight:700;text-decoration:line-through;\">daughter.\n",
"</span><span style=\"color:red;font-weight:700;\">daughter.</span>"
"<span style=\"color:red;font-weight:700;text-decoration:line-through;\">Got </span><span style=\"color:red;font-weight:700;\">I got </span>this for my <span style=\"color:red;font-weight:700;text-decoration:line-through;\">daughter for her </span><span style=\"color:red;font-weight:700;\">daughter's </span>birthday <span style=\"color:red;font-weight:700;text-decoration:line-through;\">cuz </span><span style=\"color:red;font-weight:700;\">because </span>she keeps taking mine from my <span style=\"color:red;font-weight:700;text-decoration:line-through;\">room. </span><span style=\"color:red;font-weight:700;\">room. </span>Yes, adults also like pandas <span style=\"color:red;font-weight:700;text-decoration:line-through;\">too. </span><span style=\"color:red;font-weight:700;\">too. </span>She takes it everywhere with her, and it's super soft and <span style=\"color:red;font-weight:700;text-decoration:line-through;\">cute. One </span><span style=\"color:red;font-weight:700;\">cute. However, one </span>of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. It's <span style=\"color:red;font-weight:700;\">also </span>a bit <span style=\"color:red;font-weight:700;text-decoration:line-through;\">small </span><span style=\"color:red;font-weight:700;\">smaller than I expected </span>for <span style=\"color:red;font-weight:700;text-decoration:line-through;\">what I paid for it though. </span><span style=\"color:red;font-weight:700;\">the price. </span>I think there might be other options that are bigger for the same <span style=\"color:red;font-weight:700;text-decoration:line-through;\">price. It </span><span style=\"color:red;font-weight:700;\">price. On the bright side, it </span>arrived a day earlier than expected, so I got to play with it myself before <span style=\"color:red;font-weight:700;text-decoration:line-through;\">I gave </span><span style=\"color:red;font-weight:700;\">giving </span>it to my daughter.\n"
],
"text/plain": [
"<IPython.core.display.Markdown object>"
@ -531,9 +601,8 @@
}
],
"source": [
"# 如未安装redlines需先安装\n",
"# !pip install redlines\n",
"from redlines import Redlines\n",
"from IPython.display import display, Markdown\n",
"\n",
"diff = Redlines(text,response)\n",
"display(Markdown(diff.output_markdown))"
@ -549,7 +618,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 23,
"id": "584dcc21",
"metadata": {},
"outputs": [],
@ -568,7 +637,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 24,
"id": "5061d6a3",
"metadata": {
"scrolled": true
@ -579,14 +648,15 @@
"text/markdown": [
"【优点】\n",
"- 超级柔软可爱,女儿生日礼物非常受欢迎。\n",
"- 送货速度快,提前一天到达,让我有时间玩一下。\n",
"- 成人也喜欢熊猫,我也很喜欢它。\n",
"- 提前一天到货,让我有时间玩一下。\n",
"\n",
"【缺点】\n",
"- 价格有点高,但是大小有点小,可能有其他同价位更大的选择。\n",
"- 一只耳朵比另一只低,不太对称。\n",
"- 一只耳朵比另一只低,不对称。\n",
"- 价格有点贵,但尺寸有点小,可能有更大的同价位选择。\n",
"\n",
"【总结】\n",
"这只熊猫玩具非常适合作为生日礼物,柔软可爱,深受女儿喜爱。虽然价格有点,但是大小有点小,可能有其他同价位更大的选择。送货速度快,提前一天到达,让我有时间玩一下。"
"这只熊猫玩具非常适合作为生日礼物,柔软可爱,深受孩子喜欢。虽然价格有点,但尺寸有点小,不对称的设计也有点让人失望。如果你想要更大的同价位选择,可能需要考虑其他选项。总的来说,这是一款不错的熊猫玩具,值得购买。"
],
"text/plain": [
"<IPython.core.display.Markdown object>"