OpenAI

since 2023-03-04

https://openai.com/blog/introducing-chatgpt-and-whisper-apis

Get started から初期設定して Secret Key をひとつ作る。

https://platform.openai.com/docs/quickstart/build-your-application

node.js ではなく python flask を試す。

git clone https://github.com/openai/openai-quickstart-python.git

このままだと macOS (Apple Silicon) だと python3.11 で pip install がこけた。。

  Preparing metadata (setup.py) ... done
ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3 Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11
ERROR: Could not find a version that satisfies the requirement numpy==1.21.3 (from versions: 1.3.0, 1.4.1, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 1.13.3, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 1.15.4, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0, 1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5, 1.20.0, 1.20.1, 1.20.2, 1.20.3, 1.21.0, 1.21.1, 1.22.0, 1.22.1, 1.22.2, 1.22.3, 1.22.4, 1.23.0rc1, 1.23.0rc2, 1.23.0rc3, 1.23.0, 1.23.1, 1.23.2, 1.23.3, 1.23.4, 1.23.5, 1.24.0rc1, 1.24.0rc2, 1.24.0, 1.24.1, 1.24.2)
ERROR: No matching distribution found for numpy==1.21.3

だがよく見ると requirements.txt が古いバージョンを指定しているので、直してやる

click
Flask
numpy
openai
requests
python-dotenv

以下も参考

https://moneyforward-dev.jp/entry/2023/03/02/160050

@app.route("/", methods=("GET", "POST"))
def index():
    if request.method == "POST":
        animal = request.form["animal"]
        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo",
            messages=[
                {"role": "system", "content": "あなたはペットトリマーです。"},
                {"role": "user", "content": f"{animal}のお手入れについて知りたい。"},
            ],
        )
        return redirect(url_for("index", animal=animal, result=response.choices[0].message.content))

    animal = request.args.get("animal")
    result = request.args.get("result")
    return render_template("index.html", animal=animal, result=result)

成果 <html> <blockquote class="twitter-tweet"><p lang="ja" dir="ltr">なるほどこういうのは作れるな <a href="https://t.co/Wbqk70Ive5">pic.twitter.com/Wbqk70Ive5</a></p>&mdash; にしもつ (@24motz) <a href="https://twitter.com/24motz/status/1631839861702549504?ref_src=twsrc%5Etfw">March 4, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> </html>

openai.txt · 最終更新: 2023/03/04 12:47 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0