mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
* refactor(EditMessage): avoid manipulation of native paste handling, leverage react-hook-form for textarea changes * style: apply better theming for MinimalIcon * fix(useVoicesQuery/useCustomConfigSpeechQuery): make sure to only try request once per render * feat: edit message content parts * fix(useCopyToClipboard): handle both assistants and agents content blocks * refactor: remove save & submit and update text content correctly * chore(.env.example/config): exclude unsupported bedrock models * feat: artifacts for aws bedrock * fix: export options for bedrock conversations
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
const { createContentAggregator } = require('@librechat/agents');
|
|
const {
|
|
EModelEndpoint,
|
|
providerEndpointMap,
|
|
getResponseSender,
|
|
} = require('librechat-data-provider');
|
|
const { getDefaultHandlers } = require('~/server/controllers/agents/callbacks');
|
|
// const { loadAgentTools } = require('~/server/services/ToolService');
|
|
const getOptions = require('~/server/services/Endpoints/bedrock/options');
|
|
const AgentClient = require('~/server/controllers/agents/client');
|
|
const { getModelMaxTokens } = require('~/utils');
|
|
|
|
const initializeClient = async ({ req, res, endpointOption }) => {
|
|
if (!endpointOption) {
|
|
throw new Error('Endpoint option not provided');
|
|
}
|
|
|
|
/** @type {Array<UsageMetadata>} */
|
|
const collectedUsage = [];
|
|
const { contentParts, aggregateContent } = createContentAggregator();
|
|
const eventHandlers = getDefaultHandlers({ res, aggregateContent, collectedUsage });
|
|
|
|
// const tools = [createTavilySearchTool()];
|
|
|
|
/** @type {Agent} */
|
|
const agent = {
|
|
id: EModelEndpoint.bedrock,
|
|
name: endpointOption.name,
|
|
instructions: endpointOption.promptPrefix,
|
|
provider: EModelEndpoint.bedrock,
|
|
model: endpointOption.model_parameters.model,
|
|
model_parameters: endpointOption.model_parameters,
|
|
};
|
|
|
|
if (typeof endpointOption.artifactsPrompt === 'string' && endpointOption.artifactsPrompt) {
|
|
agent.instructions = `${agent.instructions ?? ''}\n${endpointOption.artifactsPrompt}`.trim();
|
|
}
|
|
|
|
let modelOptions = { model: agent.model };
|
|
|
|
// TODO: pass-in override settings that are specific to current run
|
|
const options = await getOptions({
|
|
req,
|
|
res,
|
|
endpointOption,
|
|
});
|
|
|
|
modelOptions = Object.assign(modelOptions, options.llmConfig);
|
|
const maxContextTokens =
|
|
agent.max_context_tokens ??
|
|
getModelMaxTokens(modelOptions.model, providerEndpointMap[agent.provider]);
|
|
|
|
const sender = getResponseSender({
|
|
...endpointOption,
|
|
model: endpointOption.model_parameters.model,
|
|
});
|
|
|
|
const client = new AgentClient({
|
|
req,
|
|
agent,
|
|
sender,
|
|
// tools,
|
|
// toolMap,
|
|
modelOptions,
|
|
contentParts,
|
|
eventHandlers,
|
|
collectedUsage,
|
|
maxContextTokens,
|
|
endpoint: EModelEndpoint.bedrock,
|
|
configOptions: options.configOptions,
|
|
attachments: endpointOption.attachments,
|
|
});
|
|
return { client };
|
|
};
|
|
|
|
module.exports = { initializeClient };
|