Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

feat: gpt-3.5-turbo-instruct support, refactor: try fetching models if OpenRouter is set (#981)

Danny Avilad87754c43dec
diff --git a/api/app/clients/ChatGPTClient.js b/api/app/clients/ChatGPTClient.js
index b7c5410855..b8a5c05e3b 100644
--- a/api/app/clients/ChatGPTClient.js
+++ b/api/app/clients/ChatGPTClient.js
@@ -153,6 +153,11 @@ class ChatGPTClient extends BaseClient {
} else {
modelOptions.prompt = input;
}
+
+ if (this.useOpenRouter && modelOptions.prompt) {
+ delete modelOptions.stop;
+ }
+
const { debug } = this.options;
const url = this.completionsUrl;
if (debug) {
diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js
index ad31a6b4ba..cbb925dbfd 100644
--- a/api/app/clients/OpenAIClient.js
+++ b/api/app/clients/OpenAIClient.js
@@ -73,21 +73,22 @@ class OpenAIClient extends BaseClient {
this.useOpenRouter = true;
}
+ const { model } = this.modelOptions;
+
this.isChatCompletion =
this.useOpenRouter ||
this.options.reverseProxyUrl ||
this.options.localAI ||
- this.modelOptions.model.startsWith('gpt-');
+ model.includes('gpt-');
this.isChatGptModel = this.isChatCompletion;
- if (this.modelOptions.model === 'text-davinci-003') {
+ if (model.includes('text-davinci-003') || model.includes('instruct')) {
this.isChatCompletion = false;
this.isChatGptModel = false;
}
const { isChatGptModel } = this;
this.isUnofficialChatGptModel =
- this.modelOptions.model.startsWith('text-chat') ||
- this.modelOptions.model.startsWith('text-davinci-002-render');
- this.maxContextTokens = maxTokensMap[this.modelOptions.model] ?? 4095; // 1 less than maximum
+ model.startsWith('text-chat') || model.startsWith('text-davinci-002-render');
+ this.maxContextTokens = maxTokensMap[model] ?? 4095; // 1 less than maximum
this.maxResponseTokens = this.modelOptions.max_tokens || 1024;
this.maxPromptTokens =
this.options.maxPromptTokens || this.maxContextTokens - this.maxResponseTokens;
@@ -168,8 +169,9 @@ class OpenAIClient extends BaseClient {
tokenizer = this.constructor.getTokenizer(this.encoding, true, extendSpecialTokens);
} else {
try {
- this.encoding = this.modelOptions.model;
- tokenizer = this.constructor.getTokenizer(this.modelOptions.model, true);
+ const { model } = this.modelOptions;
+ this.encoding = model.includes('instruct') ? 'text-davinci-003' : model;
+ tokenizer = this.constructor.getTokenizer(this.encoding, true);
} catch {
tokenizer = this.constructor.getTokenizer(this.encoding, true);
}
@@ -354,6 +356,8 @@ class OpenAIClient extends BaseClient {
if (this.isChatCompletion) {
token =
progressMessage.choices?.[0]?.delta?.content ?? progressMessage.choices?.[0]?.text;
+ } else {
+ token = progressMessage.choices?.[0]?.text;
}
if (!token && this.useOpenRouter) {
diff --git a/api/server/services/ModelService.js b/api/server/services/ModelService.js
index a91be3510c..f2ba7d94c3 100644
--- a/api/server/services/ModelService.js
+++ b/api/server/services/ModelService.js
@@ -88,12 +88,11 @@ const getOpenAIModels = async (opts = { azure: false, plugins: false }) => {
return models;
}
- if (userProvidedOpenAI) {
+ if (userProvidedOpenAI && !OPENROUTER_API_KEY) {
return models;
}
- models = await fetchOpenAIModels(opts, models);
- return models;
+ return await fetchOpenAIModels(opts, models);
};
const getChatGPTBrowserModels = () => {