从0到1快速入门Python bug智能修复应用应用场景
- Introduce 简介
- setting 设置
- Prompt 提示
- Sample response 回复样本
- API request 接口请求
- python接口请求示例
- node.js接口请求示例
- curl命令示例
- json格式示例
- 其它资料下载
ChatGPT是目前最先进的AI聊天机器人,它能够理解图片和文字,生成流畅和有趣的回答。如果你想跟上AI时代的潮流,你一定要学会使用ChatGPT。如果你想了解OpenAI最新发布的GPT-4模型,以及它如何为ChatGPT聊天机器人带来更强大的功能,那么你一定不要错过OpenAI官网推荐的48种最佳应用场景,不管你是资深开发者、初学者,你都能够从0到1快速入门,并掌握他们。
ChatGPT的强大的自然语言处理能力,可以快速判断出Python代码中的bug所在,并且快速定位和修复这些bug,从而使代码更加健壮易于维护,它也可以大大缩短开发周期,并且更快捷、更高效地完成整体工作,最终有效地帮助程序员,提高代码的质量和可靠性。
Introduce 简介
Python bug fixer Python bug修复器
There’s a number of ways of structuring the prompt for checking for bugs. Here we add a comment suggesting that source code is buggy, and then ask codex to generate a fixed code.
有很多种方法可以构造检查bug的提示。在这里我们添加一个注释,暗示源代码有错误,然后要求codex生成一个修复的代码。
setting 设置
Engine
:text-davinci-003
Max tokens
:182
Temperature
:0
Top p
:1.0
Frequency penalty
:0.0
Presence penalty
:0.0
Stop sequence
:###
Prompt 提示
##### Fix bugs in the below function 修复以下函数中的错误
### Buggy Python 错误的Python代码
import Random
a = random.randint(1,12)
b = random.randint(1,12)
for i in range(10):question = "What is "+a+" x "+b+"? "answer = input(question)if answer = a*bprint (Well done!)else:print("No.")
### Fixed Python 修复的python代码
Sample response 回复样本
import random
a = random.randint(1,12)
b = random.randint(1,12)
for i in range(10):question = "What is "+str(a)+" x "+str(b)+"? "answer = int(input(question))if answer == a*b:print ("Well done!")else:print("No.")
API request 接口请求
python接口请求示例
import os
import openaiopenai.api_key = os.getenv("OPENAI_API_KEY")response = openai.Completion.create(model="text-davinci-003",prompt="##### Fix bugs in the below function\n \n### Buggy Python\nimport Random\na = random.randint(1,12)\nb = random.randint(1,12)\nfor i in range(10):\n question = \"What is \"+a+\" x \"+b+\"? \"\n answer = input(question)\n if answer = a*b\n print (Well done!)\n else:\n print(\"No.\")\n \n### Fixed Python",temperature=0,max_tokens=182,top_p=1.0,frequency_penalty=0.0,presence_penalty=0.0,stop=["###"]
)
node.js接口请求示例
const { Configuration, OpenAIApi } = require("openai");const configuration = new Configuration({apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);const response = await openai.createCompletion({model: "text-davinci-003",prompt: "##### Fix bugs in the below function\n \n### Buggy Python\nimport Random\na = random.randint(1,12)\nb = random.randint(1,12)\nfor i in range(10):\n question = \"What is \"+a+\" x \"+b+\"? \"\n answer = input(question)\n if answer = a*b\n print (Well done!)\n else:\n print(\"No.\")\n \n### Fixed Python",temperature: 0,max_tokens: 182,top_p: 1.0,frequency_penalty: 0.0,presence_penalty: 0.0,stop: ["###"],
});
curl命令示例
curl https://api.openai.com/v1/completions \-H "Content-Type: application/json" \-H "Authorization: Bearer $OPENAI_API_KEY" \-d '{"model": "text-davinci-003","prompt": "##### Fix bugs in the below function\n \n### Buggy Python\nimport Random\na = random.randint(1,12)\nb = random.randint(1,12)\nfor i in range(10):\n question = \"What is \"+a+\" x \"+b+\"? \"\n answer = input(question)\n if answer = a*b\n print (Well done!)\n else:\n print(\"No.\")\n \n### Fixed Python","temperature": 0,"max_tokens": 182,"top_p": 1.0,"frequency_penalty": 0.0,"presence_penalty": 0.0,"stop": ["###"]
}'
json格式示例
{"model": "text-davinci-003","prompt": "##### Fix bugs in the below function\n \n### Buggy Python\nimport Random\na = random.randint(1,12)\nb = random.randint(1,12)\nfor i in range(10):\n question = \"What is \"+a+\" x \"+b+\"? \"\n answer = input(question)\n if answer = a*b\n print (Well done!)\n else:\n print(\"No.\")\n \n### Fixed Python","temperature": 0,"max_tokens": 182,"top_p": 1.0,"frequency_penalty": 0.0,"presence_penalty": 0.0,"stop": ["###"]
}
其它资料下载
如果大家想继续了解人工智能相关学习路线和知识体系,欢迎大家翻阅我的另外一篇博客《重磅 | 完备的人工智能AI 学习——基础知识学习路线,所有资料免关注免套路直接网盘下载》
这篇博客参考了Github知名开源平台,AI技术平台以及相关领域专家:Datawhale,ApacheCN,AI有道和黄海广博士等约有近100G相关资料,希望能帮助到所有小伙伴们。
本文链接:https://my.lmcjl.com/post/8494.html
4 评论