feat(api): add support for user-provided OpenAI API key (#311)

- Add support for user-provided OpenAI API key by setting OPENAI_KEY to
  "user_provided" in .env.example
- Pass oaiApiKey to titleConvo function in titleConvo.js
- Pass oaiApiKey to askClient function in askOpenAI.js
- Modify openAI object in endpoints.js to include userProvide property
  based on whether OPENAI_KEY is set to "user_provided" or not.
This commit is contained in:
Danny Avila 2023-05-17 21:58:56 -04:00 committed by GitHub
parent 61a4231feb
commit 26152d7e5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 8 deletions

View file

@ -17,7 +17,7 @@ const proxyEnvToAxiosProxy = (proxyString) => {
return proxyConfig;
};
const titleConvo = async ({ endpoint, text, response }) => {
const titleConvo = async ({ endpoint, text, response, oaiApiKey }) => {
let title = 'New Chat';
const ChatGPTClient = (await import('@waylaidwanderer/chatgpt-api')).default;
@ -50,7 +50,7 @@ const titleConvo = async ({ endpoint, text, response }) => {
frequency_penalty: 0
};
let apiKey = process.env.OPENAI_KEY;
let apiKey = oaiApiKey || process.env.OPENAI_KEY;
if (azure) {
apiKey = process.env.AZURE_OPENAI_API_KEY;