mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
🧩 feat: Support Alternate API Keys for Plugins (#1760)
* refactor(DALL-E): retrieve env variables at runtime and not from memory * feat(plugins): add alternate env variable handling to allow setting one api key for multiple plugins * docs: update docs
This commit is contained in:
parent
927ce5395b
commit
39caeb2027
10 changed files with 328 additions and 113 deletions
|
@ -9,14 +9,6 @@ const { processFileURL } = require('~/server/services/Files/process');
|
|||
const extractBaseURL = require('~/utils/extractBaseURL');
|
||||
const { logger } = require('~/config');
|
||||
|
||||
const {
|
||||
DALLE3_SYSTEM_PROMPT,
|
||||
DALLE_REVERSE_PROXY,
|
||||
PROXY,
|
||||
DALLE3_AZURE_API_VERSION,
|
||||
DALLE3_BASEURL,
|
||||
DALLE3_API_KEY,
|
||||
} = process.env;
|
||||
class DALLE3 extends Tool {
|
||||
constructor(fields = {}) {
|
||||
super();
|
||||
|
@ -25,19 +17,22 @@ class DALLE3 extends Tool {
|
|||
this.fileStrategy = fields.fileStrategy;
|
||||
let apiKey = fields.DALLE3_API_KEY ?? fields.DALLE_API_KEY ?? this.getApiKey();
|
||||
const config = { apiKey };
|
||||
if (DALLE_REVERSE_PROXY) {
|
||||
config.baseURL = extractBaseURL(DALLE_REVERSE_PROXY);
|
||||
if (process.env.DALLE_REVERSE_PROXY) {
|
||||
config.baseURL = extractBaseURL(process.env.DALLE_REVERSE_PROXY);
|
||||
}
|
||||
|
||||
if (DALLE3_AZURE_API_VERSION && DALLE3_BASEURL) {
|
||||
config.baseURL = DALLE3_BASEURL;
|
||||
config.defaultQuery = { 'api-version': DALLE3_AZURE_API_VERSION };
|
||||
config.defaultHeaders = { 'api-key': DALLE3_API_KEY, 'Content-Type': 'application/json' };
|
||||
config.apiKey = DALLE3_API_KEY;
|
||||
if (process.env.DALLE3_AZURE_API_VERSION && process.env.DALLE3_BASEURL) {
|
||||
config.baseURL = process.env.DALLE3_BASEURL;
|
||||
config.defaultQuery = { 'api-version': process.env.DALLE3_AZURE_API_VERSION };
|
||||
config.defaultHeaders = {
|
||||
'api-key': process.env.DALLE3_API_KEY,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
config.apiKey = process.env.DALLE3_API_KEY;
|
||||
}
|
||||
|
||||
if (PROXY) {
|
||||
config.httpAgent = new HttpsProxyAgent(PROXY);
|
||||
if (process.env.PROXY) {
|
||||
config.httpAgent = new HttpsProxyAgent(process.env.PROXY);
|
||||
}
|
||||
|
||||
this.openai = new OpenAI(config);
|
||||
|
@ -47,7 +42,7 @@ class DALLE3 extends Tool {
|
|||
- Create only one image, without repeating or listing descriptions outside the "prompts" field.
|
||||
- Maintains the original intent of the description, with parameters for image style, quality, and size to tailor the output.`;
|
||||
this.description_for_model =
|
||||
DALLE3_SYSTEM_PROMPT ??
|
||||
process.env.DALLE3_SYSTEM_PROMPT ??
|
||||
`// Whenever a description of an image is given, generate prompts (following these rules), and use dalle to create the image. If the user does not ask for a specific number of images, default to creating 2 prompts to send to dalle that are written to be as diverse as possible. All prompts sent to dalle must abide by the following policies:
|
||||
// 1. Prompts must be in English. Translate to English if needed.
|
||||
// 2. One image per function call. Create only 1 image per request unless explicitly told to generate more than 1 image.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue