Skip to content

Commit

Permalink
🐛 fix: Prevent Empty File Uploads & Assistants Fixes (danny-avila#2611)
Browse files Browse the repository at this point in the history
* chore: update default models for openai/assistants

* fix: allows assistants models fetching

* change default models order, ensure assistant_id is defined if intended

* fix: prevent empty files from being uploaded
  • Loading branch information
danny-avila authored May 3, 2024
1 parent 5742ab4 commit d3fdbb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions server/services/Files/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ function filterFile({ req, file, image }) {
throw new Error('No file_id provided');
}

if (file.size === 0) {
throw new Error('Empty file uploaded');
}

/* parse to validate api call, throws error on fail */
isUUID.parse(file_id);

Expand Down
10 changes: 5 additions & 5 deletions server/services/ModelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const fetchModels = async ({
* @param {object} opts - The options for fetching the models.
* @param {string} opts.user - The user ID to send to the API.
* @param {boolean} [opts.azure=false] - Whether to fetch models from Azure.
* @param {boolean} [opts.assistants=false] - Whether to fetch models from Azure.
* @param {boolean} [opts.plugins=false] - Whether to fetch models from the plugins.
* @param {string[]} [_models=[]] - The models to use as a fallback.
*/
Expand All @@ -150,7 +151,10 @@ const fetchOpenAIModels = async (opts, _models = []) => {
const openaiBaseURL = 'https://api.openai.com/v1';
let baseURL = openaiBaseURL;
let reverseProxyUrl = process.env.OPENAI_REVERSE_PROXY;
if (opts.azure) {

if (opts.assistants && process.env.ASSISTANTS_BASE_URL) {
reverseProxyUrl = process.env.ASSISTANTS_BASE_URL;
} else if (opts.azure) {
return models;
// const azure = getAzureCredentials();
// baseURL = (genAzureChatCompletion(azure))
Expand Down Expand Up @@ -245,10 +249,6 @@ const getOpenAIModels = async (opts) => {
return models;
}

if (opts.assistants) {
return models;
}

return await fetchOpenAIModels(opts, models);
};

Expand Down

0 comments on commit d3fdbb1

Please sign in to comment.