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

@ -6,6 +6,7 @@ const { addImages, buildErrorInput, buildPromptPrefix } = require('./output_pars
const checkBalance = require('../../models/checkBalance');
const { formatLangChainMessages } = require('./prompts');
const { isEnabled } = require('../../server/utils');
const { extractBaseURL } = require('../../utils');
const { SelfReflectionTool } = require('./tools');
const { loadTools } = require('./tools/util');
@ -34,7 +35,7 @@ class PluginsClient extends OpenAIClient {
this.isGpt3 = this.modelOptions?.model?.includes('gpt-3');
if (this.options.reverseProxyUrl) {
this.langchainProxy = this.options.reverseProxyUrl.match(/.*v1/)?.[0];
this.langchainProxy = extractBaseURL(this.options.reverseProxyUrl);
!this.langchainProxy &&
console.warn(`The reverse proxy URL ${this.options.reverseProxyUrl} is not valid for Plugins.
The url must follow OpenAI specs, for example: https://localhost:8080/v1/chat/completions