From e6746c49ef0517d9d98763a3e73058dbd7a69a0f Mon Sep 17 00:00:00 2001 From: Danny Avila <110412045+danny-avila@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:39:30 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20feat:=20Add=20`OPENAI=5FORGANIZA?= =?UTF-8?q?TION`=20for=20all=20OpenAI=20Requests=20(#1590)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/clients/OpenAIClient.js | 4 ++++ server/services/ModelService.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/clients/OpenAIClient.js b/app/clients/OpenAIClient.js index f832b3ca134..7d0baa40d79 100644 --- a/app/clients/OpenAIClient.js +++ b/app/clients/OpenAIClient.js @@ -954,6 +954,10 @@ ${convo} opts.defaultHeaders = { ...opts.defaultHeaders, 'api-key': this.apiKey }; } + if (process.env.OPENAI_ORGANIZATION) { + opts.organization = process.env.OPENAI_ORGANIZATION; + } + let chatCompletion; const openai = new OpenAI({ apiKey: this.apiKey, diff --git a/server/services/ModelService.js b/server/services/ModelService.js index 2e433dbd14e..76ac061546d 100644 --- a/server/services/ModelService.js +++ b/server/services/ModelService.js @@ -53,6 +53,10 @@ const fetchModels = async ({ apiKey, baseURL, name = 'OpenAI', azure = false }) payload.httpsAgent = new HttpsProxyAgent(PROXY); } + if (process.env.OPENAI_ORGANIZATION && baseURL.includes('openai')) { + payload.headers['OpenAI-Organization'] = process.env.OPENAI_ORGANIZATION; + } + const res = await axios.get(`${baseURL}${azure ? '' : '/models'}`, payload); models = res.data.data.map((item) => item.id); } catch (err) {