用chatgpt重构代码,优化代码,震惊!

下面纯属探索ChatGPT于重构代码、辅助编程方面的可能性,实际工作是否如此,不予讨论。下面1代表提问者,2为ChatGPT。整个过程的体验令人震撼,几乎感觉被高手环绕指导,人工智能潜力不可限量。


import osimport openai
from flask import Flask, redirect, render_template, request, url_forapp = Flask(__name__)
openai.api_key = os.getenv("OPENAI_API_KEY")@app.route("/", methods=("GET", "POST"))
def index():if request.method == "POST":animal = request.form["animal"]response = openai.Completion.create(model="text-davinci-003",prompt=generate_prompt(animal),temperature=0.6,)return redirect(url_for("index", result=response.choices[0].text))result = request.args.get("result")return render_template("index.html", result=result)def generate_prompt(animal):return """Suggest three names for an animal that is a superhero.Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: {}
Names:""".format(animal.capitalize())

本文链接:https://my.lmcjl.com/post/3343.html

展开阅读全文

4 评论

留下您的评论.