F: Implement schema variables + small UI fixes
This commit is contained in:
parent
ea892bc9cb
commit
fd6ee0d736
|
@ -5,6 +5,8 @@ const describePromptVariableRecord: Record<PromptVariableType, string> = {
|
||||||
[PromptVariableType.OSS]: 'Текущая операционная схема',
|
[PromptVariableType.OSS]: 'Текущая операционная схема',
|
||||||
[PromptVariableType.SCHEMA]: 'Текущая концептуальная схема',
|
[PromptVariableType.SCHEMA]: 'Текущая концептуальная схема',
|
||||||
[PromptVariableType.SCHEMA_THESAURUS]: 'Термины и определения текущей концептуальной схемы',
|
[PromptVariableType.SCHEMA_THESAURUS]: 'Термины и определения текущей концептуальной схемы',
|
||||||
|
[PromptVariableType.SCHEMA_GRAPH]: 'Граф связей определений конституент',
|
||||||
|
[PromptVariableType.SCHEMA_TYPE_GRAPH]: 'Граф ступеней концептуальной схемы',
|
||||||
[PromptVariableType.CONSTITUENTA]: 'Текущая конституента',
|
[PromptVariableType.CONSTITUENTA]: 'Текущая конституента',
|
||||||
[PromptVariableType.CONSTITUENTA_SYNTAX_TREE]: 'Синтаксическое дерево конституенты'
|
[PromptVariableType.CONSTITUENTA_SYNTAX_TREE]: 'Синтаксическое дерево конституенты'
|
||||||
};
|
};
|
||||||
|
@ -14,6 +16,8 @@ const mockPromptVariableRecord: Record<PromptVariableType, string> = {
|
||||||
[PromptVariableType.OSS]: 'Пример: Текущая операционная схема',
|
[PromptVariableType.OSS]: 'Пример: Текущая операционная схема',
|
||||||
[PromptVariableType.SCHEMA]: 'Пример: Текущая концептуальная схема',
|
[PromptVariableType.SCHEMA]: 'Пример: Текущая концептуальная схема',
|
||||||
[PromptVariableType.SCHEMA_THESAURUS]: 'Пример\nТермин1 - Определение1\nТермин2 - Определение2',
|
[PromptVariableType.SCHEMA_THESAURUS]: 'Пример\nТермин1 - Определение1\nТермин2 - Определение2',
|
||||||
|
[PromptVariableType.SCHEMA_GRAPH]: 'Пример: Граф связей определений конституент',
|
||||||
|
[PromptVariableType.SCHEMA_TYPE_GRAPH]: 'Пример: Граф ступеней концептуальной схемы',
|
||||||
[PromptVariableType.CONSTITUENTA]: 'Пример: Текущая конституента',
|
[PromptVariableType.CONSTITUENTA]: 'Пример: Текущая конституента',
|
||||||
[PromptVariableType.CONSTITUENTA_SYNTAX_TREE]: 'Пример синтаксического дерева конституенты'
|
[PromptVariableType.CONSTITUENTA_SYNTAX_TREE]: 'Пример синтаксического дерева конституенты'
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { type IBlock, type IOperationSchema, NodeType } from '@/features/oss/mod
|
||||||
import { CstType, type IConstituenta, type IRSForm } from '@/features/rsform';
|
import { CstType, type IConstituenta, type IRSForm } from '@/features/rsform';
|
||||||
import { labelCstTypification } from '@/features/rsform/labels';
|
import { labelCstTypification } from '@/features/rsform/labels';
|
||||||
import { isBasicConcept } from '@/features/rsform/models/rsform-api';
|
import { isBasicConcept } from '@/features/rsform/models/rsform-api';
|
||||||
|
import { TypificationGraph } from '@/features/rsform/models/typification-graph';
|
||||||
|
|
||||||
import { PARAMETER } from '@/utils/constants';
|
import { PARAMETER } from '@/utils/constants';
|
||||||
|
|
||||||
|
@ -41,9 +42,9 @@ export function varSchema(schema: IRSForm): string {
|
||||||
result += `[${schema.alias}] Описание: "${schema.description}"\n\n`;
|
result += `[${schema.alias}] Описание: "${schema.description}"\n\n`;
|
||||||
result += 'Понятия:\n';
|
result += 'Понятия:\n';
|
||||||
schema.items.forEach(item => {
|
schema.items.forEach(item => {
|
||||||
result += `${item.alias} - "${labelCstTypification(item)}" - "${item.term_resolved}" - "${
|
result += `\n${item.alias} - "${labelCstTypification(item)}" - "${item.term_resolved}" - "${
|
||||||
item.definition_formal
|
item.definition_formal
|
||||||
}" - "${item.definition_resolved}" - "${item.convention}"\n`;
|
}" - "${item.definition_resolved}" - "${item.convention}"`;
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -58,14 +59,37 @@ export function varSchemaThesaurus(schema: IRSForm): string {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isBasicConcept(item.cst_type)) {
|
if (isBasicConcept(item.cst_type)) {
|
||||||
result += `${item.term_resolved} - "${item.convention}"\n`;
|
result += `\n${item.term_resolved} - "${item.convention}"`;
|
||||||
} else {
|
} else {
|
||||||
result += `${item.term_resolved} - "${item.definition_resolved}"\n`;
|
result += `\n${item.term_resolved} - "${item.definition_resolved}"`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generates a prompt for a schema graph variable. */
|
||||||
|
export function varSchemaGraph(schema: IRSForm): string {
|
||||||
|
let result = `Название концептуальной схемы: ${schema.title}\n`;
|
||||||
|
result += `[${schema.alias}] Описание: "${schema.description}"\n\n`;
|
||||||
|
result += 'Узлы графа\n';
|
||||||
|
result += JSON.stringify(schema.items, null, PARAMETER.indentJSON);
|
||||||
|
result += '\n\nСвязи графа';
|
||||||
|
schema.graph.nodes.forEach(node => (result += `\n${node.id} -> ${node.outputs.join(', ')}`));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generates a prompt for a schema type graph variable. */
|
||||||
|
export function varSchemaTypeGraph(schema: IRSForm): string {
|
||||||
|
const graph = new TypificationGraph();
|
||||||
|
schema.items.forEach(item => graph.addConstituenta(item.alias, item.parse.typification, item.parse.args));
|
||||||
|
|
||||||
|
let result = `Название концептуальной схемы: ${schema.title}\n`;
|
||||||
|
result += `[${schema.alias}] Описание: "${schema.description}"\n\n`;
|
||||||
|
result += 'Ступени\n';
|
||||||
|
result += JSON.stringify(graph.nodes, null, PARAMETER.indentJSON);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** Generates a prompt for a OSS variable. */
|
/** Generates a prompt for a OSS variable. */
|
||||||
export function varOSS(oss: IOperationSchema): string {
|
export function varOSS(oss: IOperationSchema): string {
|
||||||
let result = `Название операционной схемы: ${oss.title}\n`;
|
let result = `Название операционной схемы: ${oss.title}\n`;
|
||||||
|
@ -86,7 +110,7 @@ export function varOSS(oss: IOperationSchema): string {
|
||||||
result += `\nОперация ${operation.id}: ${operation.alias}\n`;
|
result += `\nОперация ${operation.id}: ${operation.alias}\n`;
|
||||||
result += `Название: ${operation.title}\n`;
|
result += `Название: ${operation.title}\n`;
|
||||||
result += `Описание: ${operation.description}\n`;
|
result += `Описание: ${operation.description}\n`;
|
||||||
result += `Блок: ${operation.parent}\n`;
|
result += `Блок: ${operation.parent}`;
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +131,7 @@ export function varBlock(target: IBlock, oss: IOperationSchema): string {
|
||||||
operations.forEach(operation => {
|
operations.forEach(operation => {
|
||||||
result += `\nОперация ${operation.id}: ${operation.alias}\n`;
|
result += `\nОперация ${operation.id}: ${operation.alias}\n`;
|
||||||
result += `Название: "${operation.title}"\n`;
|
result += `Название: "${operation.title}"\n`;
|
||||||
result += `Описание: "${operation.description}"\n`;
|
result += `Описание: "${operation.description}"`;
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
export const PromptVariableType = {
|
export const PromptVariableType = {
|
||||||
SCHEMA: 'schema',
|
SCHEMA: 'schema',
|
||||||
SCHEMA_THESAURUS: 'schema.thesaurus',
|
SCHEMA_THESAURUS: 'schema.thesaurus',
|
||||||
// SCHEMA_GRAPH: 'schema.graph',
|
SCHEMA_GRAPH: 'schema.graph',
|
||||||
// SCHEMA_TYPE_GRAPH: 'schema.type-graph',
|
SCHEMA_TYPE_GRAPH: 'schema.type-graph',
|
||||||
|
|
||||||
CONSTITUENTA: 'constituenta',
|
CONSTITUENTA: 'constituenta',
|
||||||
CONSTITUENTA_SYNTAX_TREE: 'constituent.ast',
|
CONSTITUENTA_SYNTAX_TREE: 'constituenta.ast',
|
||||||
|
|
||||||
OSS: 'oss',
|
OSS: 'oss',
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ import {
|
||||||
varConstituenta,
|
varConstituenta,
|
||||||
varOSS,
|
varOSS,
|
||||||
varSchema,
|
varSchema,
|
||||||
|
varSchemaGraph,
|
||||||
varSchemaThesaurus,
|
varSchemaThesaurus,
|
||||||
|
varSchemaTypeGraph,
|
||||||
varSyntaxTree
|
varSyntaxTree
|
||||||
} from '../models/prompting-api';
|
} from '../models/prompting-api';
|
||||||
|
|
||||||
|
@ -68,6 +70,10 @@ export function evaluatePromptVariable(variableType: PromptVariableType, context
|
||||||
return context.currentSchema ? varSchema(context.currentSchema) : `!${variableType}!`;
|
return context.currentSchema ? varSchema(context.currentSchema) : `!${variableType}!`;
|
||||||
case PromptVariableType.SCHEMA_THESAURUS:
|
case PromptVariableType.SCHEMA_THESAURUS:
|
||||||
return context.currentSchema ? varSchemaThesaurus(context.currentSchema) : `!${variableType}!`;
|
return context.currentSchema ? varSchemaThesaurus(context.currentSchema) : `!${variableType}!`;
|
||||||
|
case PromptVariableType.SCHEMA_GRAPH:
|
||||||
|
return context.currentSchema ? varSchemaGraph(context.currentSchema) : `!${variableType}!`;
|
||||||
|
case PromptVariableType.SCHEMA_TYPE_GRAPH:
|
||||||
|
return context.currentSchema ? varSchemaTypeGraph(context.currentSchema) : `!${variableType}!`;
|
||||||
case PromptVariableType.BLOCK:
|
case PromptVariableType.BLOCK:
|
||||||
return context.currentBlock && context.currentOSS
|
return context.currentBlock && context.currentOSS
|
||||||
? varBlock(context.currentBlock, context.currentOSS)
|
? varBlock(context.currentBlock, context.currentOSS)
|
||||||
|
|
|
@ -10,8 +10,20 @@ export function useAvailableVariables(): PromptVariableType[] {
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(hasCurrentOSS ? [PromptVariableType.OSS] : []),
|
...(hasCurrentOSS ? [PromptVariableType.OSS] : []),
|
||||||
...(hasCurrentSchema ? [PromptVariableType.SCHEMA] : []),
|
...(hasCurrentSchema
|
||||||
|
? [
|
||||||
|
PromptVariableType.SCHEMA, //
|
||||||
|
PromptVariableType.SCHEMA_THESAURUS,
|
||||||
|
PromptVariableType.SCHEMA_GRAPH,
|
||||||
|
PromptVariableType.SCHEMA_TYPE_GRAPH
|
||||||
|
]
|
||||||
|
: []),
|
||||||
...(hasCurrentBlock ? [PromptVariableType.BLOCK] : []),
|
...(hasCurrentBlock ? [PromptVariableType.BLOCK] : []),
|
||||||
...(hasCurrentConstituenta ? [PromptVariableType.CONSTITUENTA] : [])
|
...(hasCurrentConstituenta
|
||||||
|
? [
|
||||||
|
PromptVariableType.CONSTITUENTA, //
|
||||||
|
PromptVariableType.CONSTITUENTA_SYNTAX_TREE
|
||||||
|
]
|
||||||
|
: [])
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
IconOwner,
|
IconOwner,
|
||||||
IconQR,
|
IconQR,
|
||||||
IconReader,
|
IconReader,
|
||||||
IconRobot,
|
|
||||||
IconShare,
|
IconShare,
|
||||||
IconUpload
|
IconUpload
|
||||||
} from '@/components/icons';
|
} from '@/components/icons';
|
||||||
|
@ -59,9 +58,6 @@ export function HelpRSMenu() {
|
||||||
<li>
|
<li>
|
||||||
<IconQR className='inline-icon' /> Отобразить QR-код схемы
|
<IconQR className='inline-icon' /> Отобразить QR-код схемы
|
||||||
</li>
|
</li>
|
||||||
<li>
|
|
||||||
<IconRobot className='inline-icon' /> Генерировать запрос для LLM
|
|
||||||
</li>
|
|
||||||
<li>
|
<li>
|
||||||
<IconClone className='inline-icon icon-green' /> Клонировать – создать копию схемы
|
<IconClone className='inline-icon icon-green' /> Клонировать – создать копию схемы
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { toast } from 'react-toastify';
|
|
||||||
import fileDownload from 'js-file-download';
|
import fileDownload from 'js-file-download';
|
||||||
|
|
||||||
import { urls, useConceptNavigation } from '@/app';
|
import { urls, useConceptNavigation } from '@/app';
|
||||||
|
@ -18,20 +17,18 @@ import {
|
||||||
IconNewItem,
|
IconNewItem,
|
||||||
IconOSS,
|
IconOSS,
|
||||||
IconQR,
|
IconQR,
|
||||||
IconRobot,
|
|
||||||
IconShare,
|
IconShare,
|
||||||
IconUpload
|
IconUpload
|
||||||
} from '@/components/icons';
|
} from '@/components/icons';
|
||||||
import { useDialogsStore } from '@/stores/dialogs';
|
import { useDialogsStore } from '@/stores/dialogs';
|
||||||
import { useModificationStore } from '@/stores/modification';
|
import { useModificationStore } from '@/stores/modification';
|
||||||
import { EXTEOR_TRS_FILE } from '@/utils/constants';
|
import { EXTEOR_TRS_FILE } from '@/utils/constants';
|
||||||
import { infoMsg, tooltipText } from '@/utils/labels';
|
import { tooltipText } from '@/utils/labels';
|
||||||
import { type RO } from '@/utils/meta';
|
import { type RO } from '@/utils/meta';
|
||||||
import { generatePageQR, promptUnsaved, sharePage } from '@/utils/utils';
|
import { generatePageQR, promptUnsaved, sharePage } from '@/utils/utils';
|
||||||
|
|
||||||
import { useDownloadRSForm } from '../../backend/use-download-rsform';
|
import { useDownloadRSForm } from '../../backend/use-download-rsform';
|
||||||
import { useMutatingRSForm } from '../../backend/use-mutating-rsform';
|
import { useMutatingRSForm } from '../../backend/use-mutating-rsform';
|
||||||
import { generatePrompt } from '../../models/rslang-api';
|
|
||||||
|
|
||||||
import { useRSEdit } from './rsedit-context';
|
import { useRSEdit } from './rsedit-context';
|
||||||
|
|
||||||
|
@ -111,16 +108,6 @@ export function MenuMain() {
|
||||||
sharePage();
|
sharePage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCopyPrompt() {
|
|
||||||
menu.hide();
|
|
||||||
|
|
||||||
const prompt = generatePrompt(schema);
|
|
||||||
navigator.clipboard
|
|
||||||
.writeText(prompt)
|
|
||||||
.then(() => toast.success(infoMsg.promptReady))
|
|
||||||
.catch(console.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleShowQR() {
|
function handleShowQR() {
|
||||||
menu.hide();
|
menu.hide();
|
||||||
showQR({ target: generatePageQR() });
|
showQR({ target: generatePageQR() });
|
||||||
|
@ -152,12 +139,6 @@ export function MenuMain() {
|
||||||
icon={<IconQR size='1rem' className='icon-primary' />}
|
icon={<IconQR size='1rem' className='icon-primary' />}
|
||||||
onClick={handleShowQR}
|
onClick={handleShowQR}
|
||||||
/>
|
/>
|
||||||
<DropdownButton
|
|
||||||
text='Запрос LLM'
|
|
||||||
title='Генерировать запрос для LLM'
|
|
||||||
icon={<IconRobot size='1rem' className='icon-primary' />}
|
|
||||||
onClick={handleCopyPrompt}
|
|
||||||
/>
|
|
||||||
{!isAnonymous ? (
|
{!isAnonymous ? (
|
||||||
<DropdownButton
|
<DropdownButton
|
||||||
text='Клонировать'
|
text='Клонировать'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user