mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* WIP: initial logging changes add several transports in ~/config/winston omit messages in logs, truncate long strings add short blurb in dotenv for debug logging GoogleClient: using logger OpenAIClient: using logger, handleOpenAIErrors Adding typedef for payload message bumped winston and using winston-daily-rotate-file moved config for server paths to ~/config dir Added `DEBUG_LOGGING=true` to .env.example * WIP: Refactor logging statements in code * WIP: Refactor logging statements and import configurations * WIP: Refactor logging statements and import configurations * refactor: broadcast Redis initialization message with `info` not `debug` * refactor: complete Refactor logging statements and import configurations * chore: delete unused tools * fix: circular dependencies due to accessing logger * refactor(handleText): handle booleans and write tests * refactor: redact sensitive values, better formatting * chore: improve log formatting, avoid passing strings to 2nd arg * fix(ci): fix jest tests due to logger changes * refactor(getAvailablePluginsController): cache plugins as they are static and avoids async addOpenAPISpecs call every time * chore: update docs * chore: update docs * chore: create separate meiliSync logger, clean up logs to avoid being unnecessarily verbose * chore: spread objects where they are commonly logged to allow string truncation * chore: improve error log formatting
100 lines
3 KiB
JavaScript
100 lines
3 KiB
JavaScript
const OpenAI = require('openai');
|
|
const express = require('express');
|
|
const { logger } = require('~/config');
|
|
|
|
const router = express.Router();
|
|
|
|
/**
|
|
* Create an assistant.
|
|
* @route POST /assistants
|
|
* @param {AssistantCreateParams} req.body - The assistant creation parameters.
|
|
* @returns {Assistant} 201 - success response - application/json
|
|
*/
|
|
router.post('/', async (req, res) => {
|
|
try {
|
|
const openai = new OpenAI(process.env.OPENAI_API_KEY);
|
|
const assistantData = req.body;
|
|
const assistant = await openai.beta.assistants.create(assistantData);
|
|
logger.debug('/assistants/', assistant);
|
|
res.status(201).json(assistant);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Retrieves an assistant.
|
|
* @route GET /assistants/:id
|
|
* @param {string} req.params.id - Assistant identifier.
|
|
* @returns {Assistant} 200 - success response - application/json
|
|
*/
|
|
router.get('/:id', async (req, res) => {
|
|
try {
|
|
const openai = new OpenAI(process.env.OPENAI_API_KEY);
|
|
const assistant_id = req.params.id;
|
|
const assistant = await openai.beta.assistants.retrieve(assistant_id);
|
|
res.json(assistant);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Modifies an assistant.
|
|
* @route PATCH /assistants/:id
|
|
* @param {string} req.params.id - Assistant identifier.
|
|
* @param {AssistantUpdateParams} req.body - The assistant update parameters.
|
|
* @returns {Assistant} 200 - success response - application/json
|
|
*/
|
|
router.patch('/:id', async (req, res) => {
|
|
try {
|
|
const openai = new OpenAI(process.env.OPENAI_API_KEY);
|
|
const assistant_id = req.params.id;
|
|
const updateData = req.body;
|
|
const updatedAssistant = await openai.beta.assistants.update(assistant_id, updateData);
|
|
res.json(updatedAssistant);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Deletes an assistant.
|
|
* @route DELETE /assistants/:id
|
|
* @param {string} req.params.id - Assistant identifier.
|
|
* @returns {Assistant} 200 - success response - application/json
|
|
*/
|
|
router.delete('/:id', async (req, res) => {
|
|
try {
|
|
const openai = new OpenAI(process.env.OPENAI_API_KEY);
|
|
const assistant_id = req.params.id;
|
|
const deletionStatus = await openai.beta.assistants.del(assistant_id);
|
|
res.json(deletionStatus);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Returns a list of assistants.
|
|
* @route GET /assistants
|
|
* @param {AssistantListParams} req.query - The assistant list parameters for pagination and sorting.
|
|
* @returns {Array<Assistant>} 200 - success response - application/json
|
|
*/
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const openai = new OpenAI(process.env.OPENAI_API_KEY);
|
|
const { limit, order, after, before } = req.query;
|
|
const assistants = await openai.beta.assistants.list({
|
|
limit,
|
|
order,
|
|
after,
|
|
before,
|
|
});
|
|
res.json(assistants);
|
|
} catch (error) {
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|