GitXplorerGitXplorer
o

openai-quickstart-python

public
1682 stars
1311 forks
1 issues

Commits

List of commits on branch master.
Verified
ec8890d101bdc17d66512d94a76b5e7131d188a1

Merge pull request #76 from openai/dev/logan/add-files-ui

llogankilpatrick committed 7 months ago
Unverified
75edcdfb4068af73f4381eed53181690f8fcd658

Handle case where the Assistant tried to pass back an image

llogankilpatrick committed 7 months ago
Unverified
77712bd0706a44b365ceae60d59a7f2282ef75a1

Make it so that files are deleted and the files section dynamically changes

llogankilpatrick committed 7 months ago
Unverified
cea2d98f0c4394edbf5983bfa0a6f126cbf22db8

Fix the delete files icon spacing

llogankilpatrick committed 7 months ago
Unverified
ffe7fa57287bb51bd5f91d19273c0179ac837704

Stash

llogankilpatrick committed 7 months ago
Unverified
d12ea7f56874a070b56f26aec827ef61fe82ee2a

Fix the messages so they flex to the correct side

llogankilpatrick committed 7 months ago

README

The README file for this repository.

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

  1. If you don’t have Python installed, install it from Python.org.

  2. Clone this repository.

  3. Navigate into the project directory:

    $ cd openai-quickstart-python
  4. Create a new virtual environment:

    • macOS:

      $ python -m venv venv
      $ . venv/bin/activate
    • Windows:

      > python -m venv venv
      > .\venv\Scripts\activate
  5. Install the requirements:

    $ pip install -r requirements.txt
  6. Make a copy of the example environment variables file:

    $ cp .env.example .env
  7. Add your API key to the newly created .env file.

  8. 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