Stop using connection params as global variable in the package
Describe the feature or improvement you're requesting
Currently, in order to create openai connection, we need to do the following:
import openai
openai.organization = "ORG"
openai.api_key = os.getenv("KEY")
openai.Completion.create(.....)
In my use case I have Flask server with 2 endpoint, each on them uses different OpenAI credentials.
With the current implementation, when the credentials are global param in the package, I cannot use the 2 endpoints simultaneously
Ideally, I want something like this:
import openai
with openai.create_connection(org, key, ...) as conn:
conn.Completion.create(.....)
Additional context
No response
@salexln It looks like you should be able to pass the api_key and organization parameters (among others) through most model APIs that inherit from OpenAIObject.
@ewpatton thanks! after digging in the code I saw that I can do
import openai
openai.ChatCompletion.create(model=gpt_model_config.model_engine,
api_key=SECRET
api_base=BASE,
api_type=TYPE,
api_version=VERSION,
...)
Any chance we can add it to the documentation ?
We tend to leave that documentation to high level API changes. If you're interested, I'd happily accept a PR to this repo with this documentation change
We've moved to a client instance based API in our upcoming v1 beta which addresses this request!
from openai import OpenAI
client = OpenAI(
api_key=os.environ['OPENAI_API_KEY'], # this is also the default, it can be omitted
)