mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔧 refactor: Improve Agent Context & Minor Fixes (#5349)
* refactor: Improve Context for Agents
* 🔧 fix: Safeguard against undefined properties in OpenAIClient response handling
* refactor: log error before re-throwing for original stack trace
* refactor: remove toolResource state from useFileHandling, allow svg files
* refactor: prevent verbose logs from axios errors when using actions
* refactor: add silent method recordTokenUsage in AgentClient
* refactor: streamline token count assignment in BaseClient
* refactor: enhance safety settings handling for Gemini 2.0 model
* fix: capabilities structure in MCPConnection
* refactor: simplify civic integrity threshold handling in GoogleClient and llm
* refactor: update token count retrieval method in BaseClient tests
* ci: fix test for svg
This commit is contained in:
parent
e309c6abef
commit
b35a8b78e2
19 changed files with 324 additions and 112 deletions
|
|
@ -39,7 +39,6 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
const [errors, setErrors] = useState<string[]>([]);
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const { startUploadTimer, clearUploadTimer } = useDelayedUploadToast();
|
||||
const [toolResource, setToolResource] = useState<string | undefined>();
|
||||
const { files, setFiles, setFilesLoading, conversation } = useChatContext();
|
||||
const setError = (error: string) => setErrors((prevErrors) => [...prevErrors, error]);
|
||||
const { addFile, replaceFile, updateFileById, deleteFileById } = useUpdateFiles(
|
||||
|
|
@ -149,9 +148,6 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
: error?.response?.data?.message ?? 'com_error_files_upload';
|
||||
setError(errorMessage);
|
||||
},
|
||||
onMutate: () => {
|
||||
setToolResource(undefined);
|
||||
},
|
||||
},
|
||||
abortControllerRef.current?.signal,
|
||||
);
|
||||
|
|
@ -187,7 +183,7 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
if (!agent_id) {
|
||||
formData.append('message_file', 'true');
|
||||
}
|
||||
const tool_resource = extendedFile.tool_resource ?? toolResource;
|
||||
const tool_resource = extendedFile.tool_resource;
|
||||
if (tool_resource != null) {
|
||||
formData.append('tool_resource', tool_resource);
|
||||
}
|
||||
|
|
@ -365,7 +361,7 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
|
||||
const isImage = originalFile.type.split('/')[0] === 'image';
|
||||
const tool_resource =
|
||||
extendedFile.tool_resource ?? params?.additionalMetadata?.tool_resource ?? toolResource;
|
||||
extendedFile.tool_resource ?? params?.additionalMetadata?.tool_resource;
|
||||
if (isAgentsEndpoint(endpoint) && !isImage && tool_resource == null) {
|
||||
/** Note: this needs to be removed when we can support files to providers */
|
||||
setError('com_error_files_unsupported_capability');
|
||||
|
|
@ -388,11 +384,11 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
}
|
||||
};
|
||||
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>, _toolResource?: string) => {
|
||||
event.stopPropagation();
|
||||
if (event.target.files) {
|
||||
setFilesLoading(true);
|
||||
handleFiles(event.target.files);
|
||||
handleFiles(event.target.files, _toolResource);
|
||||
// reset the input
|
||||
event.target.value = '';
|
||||
}
|
||||
|
|
@ -408,7 +404,6 @@ const useFileHandling = (params?: UseFileHandling) => {
|
|||
|
||||
return {
|
||||
handleFileChange,
|
||||
setToolResource,
|
||||
handleFiles,
|
||||
abortUpload,
|
||||
setFiles,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue