fix(OpenAIClient): use official SDK to identify client and avoid false Rate Limit Error (#1161)

* chore: add eslint ignore unused var pattern

* feat: add extractBaseURL helper for valid OpenAI reverse proxies, with tests

* feat(OpenAIClient): add new chatCompletion using official OpenAI node SDK

* fix(ci): revert change to FORCE_PROMPT condition
This commit is contained in:
Danny Avila 2023-11-09 14:04:36 -05:00 committed by GitHub
parent ed3d7c9f80
commit 5ab9802aa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 297 additions and 12 deletions

View file

@ -1,6 +1,7 @@
const Keyv = require('keyv');
const axios = require('axios');
const { isEnabled } = require('../utils');
const { extractBaseURL } = require('../../utils');
const keyvRedis = require('../../cache/keyvRedis');
// const { getAzureCredentials, genAzureChatCompletion } = require('../../utils/');
const { openAIApiKey, userProvidedOpenAI } = require('./EndpointService').config;
@ -30,7 +31,7 @@ const fetchOpenAIModels = async (opts = { azure: false, plugins: false }, _model
}
if (reverseProxyUrl) {
basePath = reverseProxyUrl.match(/.*v1/)?.[0];
basePath = extractBaseURL(reverseProxyUrl);
}
const cachedModels = await modelsCache.get(basePath);