Skip to content

Commit

Permalink
Merge branch 'enricoros:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
icratech authored Feb 18, 2024
2 parents 5040aee + b550cbd commit 718a4b3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Frontend Build: ignore API files disabled for this build
/app/**/*.backup

# dependencies
/node_modules
/.pnp
Expand Down
4 changes: 2 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const BuildOptions = {
// Future: Electron/Frontend-only builds
exportFrontend: false,
exportFrontend: !!process.env.EXPORT_FRONTEND,
};

/** @type {import('next').NextConfig} */
Expand All @@ -11,7 +11,7 @@ let nextConfig = {
...BuildOptions.exportFrontend && {
// Export the frontend to ./dist
output: 'export',
distDir: 'dist',
distDir: 'out',

// Disable Image optimization
images: { unoptimized: true },
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "next start",
"lint": "next lint",
"postinstall": "prisma generate",
"prebuild": "node scripts/prebuild.mjs",
"db:push": "prisma db push",
"db:studio": "prisma studio",
"vercel:env:pull": "npx vercel env pull .env.development.local"
Expand Down
47 changes: 47 additions & 0 deletions scripts/prebuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { default as fs, renameSync } from 'fs';
import { dirname as pathDirName, join as pathJoin } from 'path';
import { fileURLToPath } from 'url';


// build-time configuration
const buildOnlyFrontend = !!process.env.EXPORT_FRONTEND;


function getApiDirName() {
const __filename = fileURLToPath(import.meta.url);
const __dirname = pathDirName(__filename);
return pathJoin(__dirname, '../app/api');
}

function findAllFiles(startDir) {
return fs.readdirSync(startDir).flatMap((file) => {
const fullPath = pathJoin(startDir, file);
if (fs.statSync(fullPath).isDirectory())
return findAllFiles(fullPath);
return fullPath;
},
);
}

/**
* Hide/show API routes depending on the build type
* Due to an upstream bug, NextJS will not ignore the nodejs API routes and choose to abort instead.
*/
function prebuildFrontendHotFixes(hideFiles) {
const apiDirName = getApiDirName();
const apiRoutesPaths = findAllFiles(apiDirName)
.filter((path) => path.endsWith('.ts') || path.endsWith('.ts.backup'));

apiRoutesPaths.forEach((path) => {
const isBackup = path.endsWith('.backup');
if (hideFiles) {
// If building the frontend, rename (effectively hide) the file
!isBackup && renameSync(path, `${path}.backup`);
} else {
// If it's a normal build and including API routes and a backup exists, restore it
isBackup && renameSync(path, path.slice(0, -7));
}
});
}

prebuildFrontendHotFixes(buildOnlyFrontend);
1 change: 1 addition & 0 deletions src/apps/chat/components/composer/attachments/pipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const PLAIN_TEXT_MIMETYPES: string[] = [
'text/markdown',
'text/csv',
'text/css',
'text/javascript',
'application/json',
];

Expand Down
3 changes: 2 additions & 1 deletion src/modules/llms/store-llms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ export function findSourceOrThrow<TSourceSetup>(sourceId: DModelSourceId) {


const modelsKnowledgeMap: { contains: string[], cutoff: string }[] = [
{ contains: ['4-0125', '4-turbo', '4-1106', '4-vision'], cutoff: '2023-04' },
{ contains: ['4-0125', '4-turbo'], cutoff: '2023-12' },
{ contains: ['4-1106', '4-vision'], cutoff: '2023-04' },
{ contains: ['4-0613', '4-0314', '4-32k', '3.5-turbo'], cutoff: '2021-09' },
] as const;

Expand Down

1 comment on commit 718a4b3

@vercel
Copy link

@vercel vercel bot commented on 718a4b3 Feb 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.