From a28ec9b57841a588bc58209a73adc413ee726d2b Mon Sep 17 00:00:00 2001 From: Eugene Date: Fri, 8 Mar 2024 23:24:17 +0300 Subject: [PATCH 01/18] CP 3 --- interface/src/api/sc/agents/helper.ts | 77 ++++++ interface/src/pages/Demo/Demo.tsx | 92 +++++- interface/src/pages/Demo/styled.ts | 151 ++++++++++ kb/1.scs | 3 + .../examples/message_processing_program.gwf | 261 ++++++++++-------- ...ncept_phrase_about_unknown_subdividing.gwf | 32 --- nika.ini | 2 +- .../cxx/interfaceModule/CMakeLists.txt | 5 +- .../cxx/interfaceModule/InterfaceModule.cpp | 10 + .../cxx/interfaceModule/InterfaceModule.hpp | 1 + .../agent/CreateAnswerTemplate.cpp | 190 +++++++++++++ .../agent/CreateAnswerTemplate.hpp | 31 +++ .../keynodes/InterfaceKeynodes.cpp | 7 + .../keynodes/InterfaceKeynodes.hpp | 21 ++ scripts/data.db | Bin 0 -> 28672 bytes scripts/secret.txt | 1 + 16 files changed, 737 insertions(+), 147 deletions(-) create mode 100644 interface/src/api/sc/agents/helper.ts create mode 100644 kb/1.scs delete mode 100644 kb/section_subject_domain_of_messages/subject_domain_of_phrases/examples/concept_phrase_about_subdividing/concept_phrase_about_unknown_subdividing.gwf create mode 100644 problem-solver/cxx/interfaceModule/agent/CreateAnswerTemplate.cpp create mode 100644 problem-solver/cxx/interfaceModule/agent/CreateAnswerTemplate.hpp create mode 100644 scripts/data.db create mode 100644 scripts/secret.txt diff --git a/interface/src/api/sc/agents/helper.ts b/interface/src/api/sc/agents/helper.ts new file mode 100644 index 000000000..5665dd3a5 --- /dev/null +++ b/interface/src/api/sc/agents/helper.ts @@ -0,0 +1,77 @@ +import { ScAddr, ScTemplate, ScType } from 'ts-sc-client'; +import { client } from '@api/sc/client'; +import { ScConstruction, ScLinkContent, ScLinkContentType } from 'ts-sc-client'; + +const nrelSystemIdentifier = 'nrel_system_identifier'; + +const baseKeynodes = [ + { id: nrelSystemIdentifier, type: ScType.NodeConstNoRole}, +]; + +const setSystemIdtf = async (addr: ScAddr, systemIdtf: string) => { + const keynodes = await client.resolveKeynodes(baseKeynodes); + + const template = new ScTemplate(); + const linkAlias = "_link"; + + const sysIdtfLinkConstruction = new ScConstruction(); + sysIdtfLinkConstruction.createLink( + ScType.LinkConst, + new ScLinkContent(systemIdtf, ScLinkContentType.String) + ); + const [sysIdtfLinkNode] = await client.createElements(sysIdtfLinkConstruction); + + template.tripleWithRelation( + addr, + ScType.EdgeDCommonVar, + sysIdtfLinkNode, + ScType.EdgeAccessVarPosPerm, + keynodes[nrelSystemIdentifier] + ); + const result = await client.templateGenerate(template, {}); +}; + +export const handleSave = async ( + systemIdentifierRef: React.RefObject, + russianIdentifierRef: React.RefObject, + englishIdentifierRef: React.RefObject, + chipsValues: string[] +) => { + const inputValues = { + systemIdentifier: systemIdentifierRef.current?.value || '', + russianIdentifier: russianIdentifierRef.current?.value || '', + englishIdentifier: englishIdentifierRef.current?.value || '', + }; + + const phrases = chipsValues.join(', '); + + const inputs = [ + 'System Identifier: ' + inputValues['systemIdentifier'], + 'Russian Identifier: ' + inputValues['russianIdentifier'], + 'English Identifier: ' + inputValues['englishIdentifier'], + 'Answer Templates: ' + phrases + ]; + + const inputsConstruction = new ScConstruction(); + + for(let inputText of inputs) + { + inputsConstruction.createLink( + ScType.LinkConst, + new ScLinkContent(inputText, ScLinkContentType.String) + ); + } + + const inputsLinks = await client.createElements(inputsConstruction); + + const success = new ScConstruction(); + + success.createNode(ScType.NodeConstClass, 'success'); + + const [statusSuccess] = await client.createElements(success); + + setSystemIdtf(statusSuccess, 'Success'); + + console.log(inputValues); +}; + diff --git a/interface/src/pages/Demo/Demo.tsx b/interface/src/pages/Demo/Demo.tsx index f5d1f829c..e7c3097ee 100644 --- a/interface/src/pages/Demo/Demo.tsx +++ b/interface/src/pages/Demo/Demo.tsx @@ -1,18 +1,29 @@ import { useCallback, useEffect, useState, Fragment } from 'react'; -import { Wrapper, ChatWrapper, SCgViewerWrapper } from "./styled"; +import { Wrapper, ChatWrapper, SCgViewerWrapper, PopupWrapper} from "./styled"; import { Message } from '@components/Chat/Message'; import { Chat } from '@components/Chat'; import { Date } from '@components/Chat/Date'; -import { ScAddr } from 'ts-sc-client'; +import { ScAddr, ScConstruction, ScLinkContent, ScLinkContentType, ScTemplate, ScType } from 'ts-sc-client'; import { resolveUserAgent } from '@agents/resolveUserAgent'; +import { handleSave } from '@agents/helper'; import { useChat } from '@hooks/useChat'; import * as React from "react"; +import { useRef } from 'react'; import { SC_WEB_URL } from "@constants"; +import { ScClient } from 'ts-sc-client'; +import { SC_URL } from '@constants'; +const client = new ScClient(SC_URL); + export const Demo = () => { const [user, setUser] = useState(null); const [isLoading, setIsLoading] = useState(false); + const systemIdentifierRef = useRef(null); + const russianIdentifierRef = useRef(null); + const englishIdentifierRef = useRef(null); + const answerTemplatesRef = useRef(null); + const { initChat, sendMessage, isAgentAnswer, onFetching, messages, chatRef } = useChat(user); const onSend = useCallback( async (text: string) => { @@ -35,6 +46,77 @@ export const Demo = () => { })(); }, [initChat]); + + const Popup = () => { + const [chipsValues, setChipsValues] = useState([]); + const handleChipAdd = (value: string) => { + setChipsValues([...chipsValues, value]); + }; + + const handleChipDelete = (index: number) => { + const newChipsValues = [...chipsValues]; + newChipsValues.splice(index, 1); + setChipsValues(newChipsValues); + }; + + const handleClick: React.MouseEventHandler = async (event) => { + await handleSave(systemIdentifierRef, russianIdentifierRef, englishIdentifierRef, chipsValues); + }; + + return ( +
+

Создание шаблона ответов

+ + + +
+ {chipsValues.map((value, index) => ( +
+
+ {value} +
+ handleChipDelete(index)} + > + X + +
+ ))} + ) => { + if (e.key === 'Enter') { + handleChipAdd(e.currentTarget.value); + e.currentTarget.value = ''; + } + }} + /> +
+ +
+ ); + }; + return ( @@ -72,6 +154,12 @@ export const Demo = () => {