Skip to content

Commit

Permalink
🤖 feat: Add Agents librechat.yaml Configuration (danny-avila#4953)
Browse files Browse the repository at this point in the history
* feat: CONFIG_VERSION v1.1.9, agents config

* refactor: Assistants Code Interpreter Toggle Improved Accessibility

* feat: Agents Config
  • Loading branch information
danny-avila authored and Tsounguinzo committed Dec 14, 2024
1 parent 31e4150 commit c384d76
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 48 deletions.
9 changes: 9 additions & 0 deletions api/server/controllers/EndpointController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ async function endpointController(req, res) {
capabilities,
};
}
if (mergedConfig[EModelEndpoint.agents] && req.app.locals?.[EModelEndpoint.agents]) {
const { disableBuilder, capabilities, ..._rest } = req.app.locals[EModelEndpoint.agents];

mergedConfig[EModelEndpoint.agents] = {
...mergedConfig[EModelEndpoint.agents],
disableBuilder,
capabilities,
};
}

if (
mergedConfig[EModelEndpoint.azureAssistants] &&
Expand Down
5 changes: 5 additions & 0 deletions api/server/services/AppService.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const handleRateLimits = require('./Config/handleRateLimits');
const { loadDefaultInterface } = require('./start/interface');
const { azureConfigSetup } = require('./start/azureOpenAI');
const { loadAndFormatTools } = require('./ToolService');
const { agentsConfigSetup } = require('./start/agents');
const { initializeRoles } = require('~/models/Role');
const paths = require('~/config/paths');

Expand Down Expand Up @@ -94,6 +95,10 @@ const AppService = async (app) => {
);
}

if (endpoints?.[EModelEndpoint.agents]) {
endpointLocals[EModelEndpoint.agents] = agentsConfigSetup(config);
}

const endpointKeys = [
EModelEndpoint.openAI,
EModelEndpoint.google,
Expand Down
14 changes: 14 additions & 0 deletions api/server/services/start/agents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { EModelEndpoint, agentsEndpointSChema } = require('librechat-data-provider');

/**
* Sets up the Agents configuration from the config (`librechat.yaml`) file.
* @param {TCustomConfig} config - The loaded custom configuration.
* @returns {Partial<TAgentsEndpoint>} The Agents endpoint configuration.
*/
function agentsConfigSetup(config) {
const agentsConfig = config.endpoints[EModelEndpoint.agents];
const parsedConfig = agentsEndpointSChema.parse(agentsConfig);
return parsedConfig;
}

module.exports = { agentsConfigSetup };
8 changes: 7 additions & 1 deletion api/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,17 @@
*/

/**
* @exports TAssistantEndpoint
* @exports TAgentsEndpoint
* @typedef {import('librechat-data-provider').TAssistantEndpoint} TAssistantEndpoint
* @memberof typedefs
*/

/**
* @exports TAgentsEndpoint
* @typedef {import('librechat-data-provider').TAgentsEndpoint} TAgentsEndpoint
* @memberof typedefs
*/

/**
* @exports Agent
* @typedef {import('librechat-data-provider').Agent} Agent
Expand Down
1 change: 1 addition & 0 deletions client/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export type AgentPanelProps = {
setAction: React.Dispatch<React.SetStateAction<t.Action | undefined>>;
endpointsConfig?: t.TEndpointsConfig;
setCurrentAgentId: React.Dispatch<React.SetStateAction<string | undefined>>;
agentsConfig?: t.TAgentsEndpoint | null;
};

export type AgentModelPanelProps = {
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/SidePanel/Agents/AgentConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
PermissionTypes,
AgentCapabilities,
} from 'librechat-data-provider';
import type { TConfig, TPlugin } from 'librechat-data-provider';
import type { TPlugin } from 'librechat-data-provider';
import type { AgentForm, AgentPanelProps } from '~/common';
import { cn, defaultTextProps, removeFocusOutlines, getEndpointField, getIconKey } from '~/utils';
import { useCreateAgentMutation, useUpdateAgentMutation } from '~/data-provider';
Expand Down Expand Up @@ -43,7 +43,7 @@ export default function AgentConfig({
endpointsConfig,
setActivePanel,
setCurrentAgentId,
}: AgentPanelProps & { agentsConfig?: TConfig | null }) {
}: AgentPanelProps) {
const { user } = useAuthContext();
const fileMap = useFileMapContext();
const queryClient = useQueryClient();
Expand All @@ -69,19 +69,19 @@ export default function AgentConfig({
});

const toolsEnabled = useMemo(
() => agentsConfig?.capabilities?.includes(AgentCapabilities.tools),
() => agentsConfig?.capabilities.includes(AgentCapabilities.tools),
[agentsConfig],
);
const actionsEnabled = useMemo(
() => agentsConfig?.capabilities?.includes(AgentCapabilities.actions),
() => agentsConfig?.capabilities.includes(AgentCapabilities.actions),
[agentsConfig],
);
const fileSearchEnabled = useMemo(
() => agentsConfig?.capabilities?.includes(AgentCapabilities.file_search) ?? false,
() => agentsConfig?.capabilities.includes(AgentCapabilities.file_search) ?? false,
[agentsConfig],
);
const codeEnabled = useMemo(
() => agentsConfig?.capabilities?.includes(AgentCapabilities.execute_code) ?? false,
() => agentsConfig?.capabilities.includes(AgentCapabilities.execute_code) ?? false,
[agentsConfig],
);

Expand Down
3 changes: 1 addition & 2 deletions client/src/components/SidePanel/Agents/AgentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
isAssistantsEndpoint,
defaultAgentFormValues,
} from 'librechat-data-provider';
import type { TConfig } from 'librechat-data-provider';
import type { AgentForm, AgentPanelProps, StringOption } from '~/common';
import {
useCreateAgentMutation,
Expand All @@ -33,7 +32,7 @@ export default function AgentPanel({
setCurrentAgentId,
agentsConfig,
endpointsConfig,
}: AgentPanelProps & { agentsConfig?: TConfig | null }) {
}: AgentPanelProps) {
const localize = useLocalize();
const { user } = useAuthContext();
const { showToast } = useToastContext();
Expand Down
19 changes: 11 additions & 8 deletions client/src/components/SidePanel/Builder/Code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,29 @@ export default function Code({ version }: { version: number | string }) {
checked={field.value}
onCheckedChange={field.onChange}
className="relative float-left mr-2 inline-flex h-4 w-4 cursor-pointer"
value={field?.value?.toString()}
value={field.value.toString()}
/>
)}
/>
<div className="flex items-center space-x-2">
<button
type="button"
className="flex items-center space-x-2"
onClick={() =>
setValue(Capabilities.code_interpreter, !getValues(Capabilities.code_interpreter), {
shouldDirty: true,
})
}
>
<label
className="form-check-label text-token-text-primary w-full cursor-pointer"
htmlFor={Capabilities.code_interpreter}
onClick={() =>
setValue(Capabilities.code_interpreter, !getValues(Capabilities.code_interpreter), {
shouldDirty: true,
})
}
>
{localize('com_assistants_code_interpreter')}
</label>
<HoverCardTrigger>
<CircleHelpIcon className="h-5 w-5 text-gray-500" />
</HoverCardTrigger>
</div>
</button>
<HoverCardPortal>
<HoverCardContent side={ESide.Top} className="w-80">
<div className="space-y-2">
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/Nav/useSideNavLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function useSideNavLinks({
hasAccessToCreateAgents &&
isAgentsEndpoint(endpoint) &&
agents &&
// agents.disableBuilder !== true &&
agents.disableBuilder !== true &&
keyProvided &&
interfaceConfig.parameters === true
) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/localization/languages/Eng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default {
com_agents_enable_file_search: 'Enable File Search',
com_agents_file_search_info:
'When enabled, the agent will be informed of the exact filenames listed below, allowing it to retrieve relevant context from these files.',
com_agents_code_interpreter_title: 'Code Interpreter',
com_agents_code_interpreter_title: 'Code Interpreter API',
com_agents_by_librechat: 'by LibreChat',
com_agents_code_interpreter:
'When enabled, allows your agent to leverage the LibreChat Code Interpreter API to run generated code, including file processing, securely. Requires a valid API key.',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/data-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librechat-data-provider",
"version": "0.7.60",
"version": "0.7.61",
"description": "data services for librechat apps",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
34 changes: 7 additions & 27 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,37 +208,17 @@ export type TAssistantEndpoint = z.infer<typeof assistantEndpointSchema>;

export const agentsEndpointSChema = baseEndpointSchema.merge(
z.object({
/* assistants specific */
/* agents specific */
disableBuilder: z.boolean().optional(),
pollIntervalMs: z.number().optional(),
timeoutMs: z.number().optional(),
version: z.union([z.string(), z.number()]).default(2),
supportedIds: z.array(z.string()).min(1).optional(),
excludedIds: z.array(z.string()).min(1).optional(),
privateAssistants: z.boolean().optional(),
retrievalModels: z.array(z.string()).min(1).optional().default(defaultRetrievalModels),
capabilities: z
.array(z.nativeEnum(Capabilities))
.array(z.nativeEnum(AgentCapabilities))
.optional()
.default([
Capabilities.code_interpreter,
Capabilities.image_vision,
Capabilities.retrieval,
Capabilities.actions,
Capabilities.tools,
AgentCapabilities.execute_code,
AgentCapabilities.file_search,
AgentCapabilities.actions,
AgentCapabilities.tools,
]),
/* general */
apiKey: z.string().optional(),
models: z
.object({
default: z.array(z.string()).min(1),
fetch: z.boolean().optional(),
userIdQuery: z.boolean().optional(),
})
.optional(),
titleConvo: z.boolean().optional(),
titleMethod: z.union([z.literal('completion'), z.literal('functions')]).optional(),
headers: z.record(z.any()).optional(),
}),
);

Expand Down Expand Up @@ -1097,7 +1077,7 @@ export enum Constants {
/** Key for the app's version. */
VERSION = 'v0.7.5',
/** Key for the Custom Config's version (librechat.yaml). */
CONFIG_VERSION = '1.1.8',
CONFIG_VERSION = '1.1.9',
/** Standard value for the first message's `parentMessageId` value, to indicate no parent exists. */
NO_PARENT = '00000000-0000-0000-0000-000000000000',
/** Standard value for the initial conversationId before a request is sent */
Expand Down

0 comments on commit c384d76

Please sign in to comment.