mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
feat: abort agent requests
This commit is contained in:
parent
757f544a9b
commit
7d54f7147f
4 changed files with 26 additions and 5 deletions
|
|
@ -46,6 +46,13 @@ class AgentClient extends BaseClient {
|
||||||
this.options = Object.assign({ endpoint: options.endpoint }, clientOptions);
|
this.options = Object.assign({ endpoint: options.endpoint }, clientOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the aggregated content parts for the current run.
|
||||||
|
* @returns {MessageContentComplex[]} */
|
||||||
|
getContentParts() {
|
||||||
|
return this.contentParts;
|
||||||
|
}
|
||||||
|
|
||||||
setOptions(options) {
|
setOptions(options) {
|
||||||
logger.info('[api/server/controllers/agents/client.js] setOptions', options);
|
logger.info('[api/server/controllers/agents/client.js] setOptions', options);
|
||||||
}
|
}
|
||||||
|
|
@ -437,12 +444,19 @@ class AgentClient extends BaseClient {
|
||||||
});
|
});
|
||||||
logger.info(this.contentParts, { depth: null });
|
logger.info(this.contentParts, { depth: null });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (!abortController.signal.aborted) {
|
||||||
logger.error(
|
logger.error(
|
||||||
'[api/server/controllers/agents/client.js #chatCompletion] Unhandled error type',
|
'[api/server/controllers/agents/client.js #sendCompletion] Unhandled error type',
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.warn(
|
||||||
|
'[api/server/controllers/agents/client.js #sendCompletion] Operation aborted',
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getEncoding() {
|
getEncoding() {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ const AgentController = async (req, res, next, initializeClient, addTitle) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
/** @type {{ client: TAgentClient }} */
|
||||||
const { client } = await initializeClient({ req, res, endpointOption });
|
const { client } = await initializeClient({ req, res, endpointOption });
|
||||||
|
|
||||||
const getAbortData = () => ({
|
const getAbortData = () => ({
|
||||||
|
|
@ -54,8 +55,8 @@ const AgentController = async (req, res, next, initializeClient, addTitle) => {
|
||||||
promptTokens,
|
promptTokens,
|
||||||
conversationId,
|
conversationId,
|
||||||
userMessagePromise,
|
userMessagePromise,
|
||||||
// text: getPartialText(),
|
|
||||||
messageId: responseMessageId,
|
messageId: responseMessageId,
|
||||||
|
content: client.getContentParts(),
|
||||||
parentMessageId: overrideParentMessageId ?? userMessageId,
|
parentMessageId: overrideParentMessageId ?? userMessageId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ const createAbortController = (req, res, getAbortData, getReqData) => {
|
||||||
finish_reason: 'incomplete',
|
finish_reason: 'incomplete',
|
||||||
endpoint: endpointOption.endpoint,
|
endpoint: endpointOption.endpoint,
|
||||||
iconURL: endpointOption.iconURL,
|
iconURL: endpointOption.iconURL,
|
||||||
model: endpointOption.modelOptions.model,
|
model: endpointOption.modelOptions?.model ?? endpointOption.model_parameters?.model,
|
||||||
unfinished: false,
|
unfinished: false,
|
||||||
error: false,
|
error: false,
|
||||||
isCreatedByUser: false,
|
isCreatedByUser: false,
|
||||||
|
|
|
||||||
|
|
@ -899,6 +899,12 @@
|
||||||
* @memberof typedefs
|
* @memberof typedefs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @exports TAgentClient
|
||||||
|
* @typedef {import('./server/controllers/agents/client')} TAgentClient
|
||||||
|
* @memberof typedefs
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @exports ImportBatchBuilder
|
* @exports ImportBatchBuilder
|
||||||
* @typedef {import('./server/utils/import/importBatchBuilder.js').ImportBatchBuilder} ImportBatchBuilder
|
* @typedef {import('./server/utils/import/importBatchBuilder.js').ImportBatchBuilder} ImportBatchBuilder
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue