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