mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-11 14:10:15 -07:00
Attachments: cleanups
This commit is contained in:
@@ -10,7 +10,7 @@ import VerticalAlignBottomIcon from '@mui/icons-material/VerticalAlignBottom';
|
||||
import { CloseableMenu } from '~/common/components/CloseableMenu';
|
||||
import { copyToClipboard } from '~/common/util/clipboardUtils';
|
||||
|
||||
import type { LLMAttachment } from './useLLMAttachments';
|
||||
import { attachmentCollapseOutputs, LLMAttachment } from './useLLMAttachments';
|
||||
import { useAttachmentsStore } from './store-attachments';
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export function AttachmentMenu(props: {
|
||||
const handleInlineText = React.useCallback(() => {
|
||||
onClose();
|
||||
onAttachmentInlineText(aId);
|
||||
}, [onClose, onAttachmentInlineText, aId]);
|
||||
}, [aId, onAttachmentInlineText, onClose]);
|
||||
|
||||
const handleMoveUp = React.useCallback(() => {
|
||||
useAttachmentsStore.getState().moveAttachment(aId, -1);
|
||||
@@ -74,17 +74,22 @@ export function AttachmentMenu(props: {
|
||||
return useAttachmentsStore.getState().setConverterIdx(aId, converterIdx);
|
||||
}, [aId]);
|
||||
|
||||
// const handleSummarizeText = React.useCallback(() => {
|
||||
// onAttachmentSummarizeText(aId);
|
||||
// }, [aId, onAttachmentSummarizeText]);
|
||||
|
||||
const handleCopyOutputToClipboard = React.useCallback(() => {
|
||||
if (aOutputs.length >= 1) {
|
||||
const concat = aOutputs.map(output => {
|
||||
const outputs = attachmentCollapseOutputs(aOutputs);
|
||||
if (outputs.length >= 1) {
|
||||
const concat = outputs.map(output => {
|
||||
if (output.type === 'text-block')
|
||||
return output.text;
|
||||
else if (output.type === 'image-part')
|
||||
return output.base64Url;
|
||||
else
|
||||
return null;
|
||||
}).join('\n\n');
|
||||
copyToClipboard(concat, 'Converted attachment');
|
||||
}).join('\n\n---\n\n');
|
||||
copyToClipboard(concat.trim(), 'Converted attachment');
|
||||
}
|
||||
}, [aOutputs]);
|
||||
|
||||
@@ -163,6 +168,10 @@ export function AttachmentMenu(props: {
|
||||
{/* <ListItemDecorator><ContentCopyIcon /></ListItemDecorator>*/}
|
||||
{/* Copy*/}
|
||||
{/*</MenuItem>*/}
|
||||
{/*<MenuItem onClick={handleSummarizeText} disabled={!isOutputTextInlineable}>*/}
|
||||
{/* <ListItemDecorator><CompressIcon color='success' /></ListItemDecorator>*/}
|
||||
{/* Shrink*/}
|
||||
{/*</MenuItem>*/}
|
||||
<MenuItem onClick={handleInlineText} disabled={!isOutputTextInlineable}>
|
||||
<ListItemDecorator><VerticalAlignBottomIcon /></ListItemDecorator>
|
||||
Inline text
|
||||
|
||||
@@ -19,31 +19,9 @@ import { ContentReducer } from '~/modules/aifn/summarize/ContentReducer';
|
||||
handleReducerClose();
|
||||
setComposeText(_t => _t + text);
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
/// Text template helpers
|
||||
|
||||
/*const PromptTemplates = {
|
||||
Concatenate: '{{input}}\n\n{{text}}',
|
||||
PasteFile: '{{input}}\n\n```{{fileName}}\n{{fileText}}\n```\n',
|
||||
PasteMarkdown: '{{input}}\n\n```\n{{clipboard}}\n```\n',
|
||||
};
|
||||
|
||||
const expandPromptTemplate = (template: string, dict: object) => (inputValue: string): string => {
|
||||
let expanded = template.replaceAll('{{input}}', (inputValue || '').trim()).trim();
|
||||
for (const [key, value] of Object.entries(dict))
|
||||
expanded = expanded.replaceAll(`{{${key}}}`, value.trim());
|
||||
return expanded;
|
||||
};*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
const handleAttachFiles = async (files: FileList, overrideFileNames?: string[]): Promise<void> => {
|
||||
|
||||
|
||||
// see how we fare on budget
|
||||
if (chatLLMId) {
|
||||
const newTextTokens = countModelTokens(newText, chatLLMId, 'reducer trigger');
|
||||
|
||||
@@ -96,7 +96,7 @@ function areAllOutputsSupported(outputs: ComposerOutputMultiPart, supportedOutpu
|
||||
: false;
|
||||
}
|
||||
|
||||
function attachmentCollapseOutputs(outputs: ComposerOutputMultiPart): ComposerOutputMultiPart {
|
||||
export function attachmentCollapseOutputs(outputs: ComposerOutputMultiPart): ComposerOutputMultiPart {
|
||||
const accumulatedOutputs: ComposerOutputMultiPart = [];
|
||||
|
||||
// Accumulate attachment outputs of the same type and 'collapsible' into a single object of that type.
|
||||
|
||||
Reference in New Issue
Block a user