openai/openai-quickstart-python
openai/openai-quickstart-python has 1,832 GitHub stars and 1,352 forks. GitHot measured 0 stars in 24 hours, 0 in 7 days, and +1 in 15 days. Last checked 2026-11-24 09:46 UTC. Last push 2024-06-14.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
关于
OpenAI API 快速入门教程中的 Python 示例应用。
学习资源README.md
原文OpenAI API Quickstart - Python
This repository hosts multiple quickstart apps for different OpenAI API endpoints (chat, assistants, etc). Check out the examples folder to try out different examples and get started using the OpenAI API.
Basic request
To send your first API request with the OpenAI Python SDK, make sure you have the right dependencies installed and then run the following code:
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
)
print(completion.choices[0].message)
Setup
If you don’t have Python installed, install it from Python.org.
Clone this repository.
Navigate into the project directory:
$ cd openai-quickstart-pythonCreate a new virtual environment:
macOS:
$ python -m venv venv $ . venv/bin/activateWindows:
> python -m venv venv > .\venv\Scripts\activate
Install the requirements:
$ pip install -r requirements.txtMake a copy of the example environment variables file:
$ cp .env.example .envAdd your API key to the newly created
.envfile.Run the app:
This step depends on the app itself. If the code uses flask (like the chat-basic example), you can run:
$ flask run
You should now be able to access the app from your browser at the following URL: http://localhost:5000!
If the code is just a simple Python script, you can run it with:
$ python my_file.py
探索相关项目
加载中…