mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-06-17 23:38:30 +00:00
feat(utils): add files utils, remove logger, fix API url
This commit is contained in:
@ -7,7 +7,7 @@ export const getSuggestions = async (chatHisory: Message[]) => {
|
|||||||
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
const customOpenAIKey = localStorage.getItem('openAIApiKey');
|
||||||
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
const customOpenAIBaseURL = localStorage.getItem('openAIBaseURL');
|
||||||
|
|
||||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, {
|
const res = await fetch(`/api/suggestions`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -109,7 +109,6 @@ const mergeConfigs = (current: any, update: any): any => {
|
|||||||
export const updateConfig = (config: RecursivePartial<Config>) => {
|
export const updateConfig = (config: RecursivePartial<Config>) => {
|
||||||
const currentConfig = loadConfig();
|
const currentConfig = loadConfig();
|
||||||
const mergedConfig = mergeConfigs(currentConfig, config);
|
const mergedConfig = mergeConfigs(currentConfig, config);
|
||||||
console.log(mergedConfig);
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(path.join(process.cwd(), `${configFileName}`)),
|
path.join(path.join(process.cwd(), `${configFileName}`)),
|
||||||
toml.stringify(mergedConfig),
|
toml.stringify(mergedConfig),
|
||||||
|
@ -3,7 +3,6 @@ import { htmlToText } from 'html-to-text';
|
|||||||
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
|
import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter';
|
||||||
import { Document } from '@langchain/core/documents';
|
import { Document } from '@langchain/core/documents';
|
||||||
import pdfParse from 'pdf-parse';
|
import pdfParse from 'pdf-parse';
|
||||||
import logger from './logger';
|
|
||||||
|
|
||||||
export const getDocumentsFromLinks = async ({ links }: { links: string[] }) => {
|
export const getDocumentsFromLinks = async ({ links }: { links: string[] }) => {
|
||||||
const splitter = new RecursiveCharacterTextSplitter();
|
const splitter = new RecursiveCharacterTextSplitter();
|
||||||
|
17
ui/lib/utils/files.ts
Normal file
17
ui/lib/utils/files.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
export const getFileDetails = (fileId: string) => {
|
||||||
|
const fileLoc = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
'./uploads',
|
||||||
|
fileId + '-extracted.json',
|
||||||
|
);
|
||||||
|
|
||||||
|
const parsedFile = JSON.parse(fs.readFileSync(fileLoc, 'utf8'));
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: parsedFile.title,
|
||||||
|
fileId: fileId,
|
||||||
|
};
|
||||||
|
};
|
@ -1,22 +0,0 @@
|
|||||||
import winston from 'winston';
|
|
||||||
|
|
||||||
const logger = winston.createLogger({
|
|
||||||
level: 'info',
|
|
||||||
transports: [
|
|
||||||
new winston.transports.Console({
|
|
||||||
format: winston.format.combine(
|
|
||||||
winston.format.colorize(),
|
|
||||||
winston.format.simple(),
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
new winston.transports.File({
|
|
||||||
filename: 'app.log',
|
|
||||||
format: winston.format.combine(
|
|
||||||
winston.format.timestamp(),
|
|
||||||
winston.format.json(),
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
export default logger;
|
|
Reference in New Issue
Block a user