set ( ClientSession ()) # At the end of your program, close the http session await openai. Of your program/event loop: import openai from aiohttp import ClientSession openai. To make async requests more efficient, you can pass in your ownĪiohttp.ClientSession, but you must manually close the client session at the end
create ( model = "gpt-3.5-turbo", messages = ) id ) # create a chat completion chat_completion = openai. list () # print the first model's id print ( models. api_key = "sk-." # list models models = openai. Or set openai.api_key to its value: import openai openai. Either set it as the OPENAI_API_KEY environment variable before using the library: export OPENAI_API_KEY = 'sk-.' The library needs to be configured with your account's secret key which is available on the website. If you encounter a MissingDependencyError, install them with: pip install openai Usage They’re needed for some functionality of this library, but generally not for talking to the API. Install support for Weights & Biases: pip install openaiĭata libraries like numpy and pandas are not installed by default due to their size. Install dependencies for openai.embeddings_utils: pip install openai Install from source with: python setup.py install Want to use the package, just run: pip install -upgrade openai You don't need this source code unless you want to modify the package. You can find usage examples for the OpenAI Python library in our API reference and the OpenAI Cookbook. With a wide range of versions of the OpenAI API. Themselves dynamically from API responses which makes it compatible Pre-defined set of classes for API resources that initialize The OpenAI Python library provides convenient access to the OpenAI APIįrom applications written in the Python language.