Skip to main content

A Flask extension for easy integration with OpenAI's API.

Project description

Flask-OpenAI Extension

The Flask-OpenAI extension provides a simple and intuitive way to integrate OpenAI's API into your Flask applications. With minimal setup, you can start leveraging the power of AI models in your Flask projects, whether it's for generating text, code, or any other application supported by OpenAI.

Features

  • Easy integration of OpenAI's API into Flask applications.
  • Automatic management of OpenAI API keys.
  • Efficient handling of API client instances throughout the application lifecycle.

Installation

Install Flask-OpenAI using pip:

pip install flask-openai

Quick Start

  1. Set up your Flask application

First, ensure you have Flask installed. If not, you can install it using pip:

pip install Flask

Then, set up a basic Flask application:

from flask import Flask
app = Flask(__name__)
  1. Configure the Flask-OpenAI extension

Import and initialize the OpenAI extension, passing your Flask app object to it. Don't forget to set the OPENAI_API_KEY in your app's configuration:

from flask_openai import OpenAI

app.config['OPENAI_API_KEY'] = 'your_openai_api_key_here'
openai_extension = OpenAI(app)

Alternatively, if you are using a factory function to create your Flask app, you can set up the OpenAI extension like this:

openai_extension = OpenAI()

def create_app():
    app = Flask(__name__)
    app.config['OPENAI_API_KEY'] = 'your_openai_api_key_here'
    openai_extension.init_app(app)
    return app
  1. Use the OpenAI client in your application

Now, you can access the OpenAI client in your route handlers using openai_extension.client. Here's an example of how to generate text with the OpenAI API:

@app.route('/generate-text')
def generate_text():
    response = openai_extension.client.Completion.create(
      engine="text-davinci-003",
      prompt="Once upon a time",
      max_tokens=50
    )
    return response.choices[0].text

Documentation

For more information on OpenAI's API and its capabilities, visit OpenAI API documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

Support

If you have any questions or encounter any issues, please open an issue on the project's GitHub page.

Acknowledgements

This project is not officially associated with OpenAI. All trademarks are the property of their respective owners.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_openai-0.3.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

flask_openai-0.3.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file flask_openai-0.3.0.tar.gz.

File metadata

  • Download URL: flask_openai-0.3.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for flask_openai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 725499c646e69b3adc4656d8c8eab0da58685a2663c26f66aa140197d5a0ebdd
MD5 007802595d8e8b31cc0aac7b2111df03
BLAKE2b-256 1de56e61e9eb12c9e59cd2b6e11fdcc033b5ad5a3a8b42f84d4d7179c6a953f2

See more details on using hashes here.

File details

Details for the file flask_openai-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_openai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad0fe26ae58e4e3ec6db08a97f12d8c37a91cee70e919d9b470b2ef10097c9c2
MD5 18beff36960c491695dd0aff8342984b
BLAKE2b-256 928c9d98583038c8afa66cbf205a235d945444c67ca90445f5def8ddbf4c10c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page