Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LLM_API_KEY=
LLM_API_URL=
LLM_API_MODEL=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cmake-build-release
install
repo
/ConanPresets.json
.env

.venv
*.pyc
Expand Down
3 changes: 2 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def _run_tests(self):
return tools.get_env("CONAN_RUN_TESTS", False)

def requirements(self):
self.requires("sc-machine/0.10.2")
self.requires("sc-machine/0.10.0")
self.requires("nlohmann_json/3.11.3")
self.requires("libcurl/8.12.1")

def build_requirements(self):
self.test_requires("gtest/1.14.0")
Expand Down
8 changes: 6 additions & 2 deletions docs/build/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ Before launching ostis-metasystem:
- [extract sc-machine from GitHub Releases](https://ostis-ai.github.io/sc-machine/quick_start/#github-releases) or [build it](https://ostis-ai.github.io/sc-machine/build/quick_start/);
- [extract scp-machine from GitHub Releases](https://ostis-ai.github.io/scp-machine/quick_start/#github-releases) or [build it](https://ostis-ai.github.io/scp-machine/build/quick_start/);
- [extract sc-component-manager from GitHub Releases](https://ostis-ai.github.io/sc-component-manager/quick_start/#github-releases) or [build it](https://ostis-ai.github.io/sc-component-manager/build/quick_start/).
- [extract ps-common-lib from GitHub Releases](https://github.com/ostis-ai/ostis-ps-lib/releases) or [build it](https://ostis-ai.github.io/ostis-ps-lib/ps-common-lib/#installation-build).
- [extract non-atomic-action-interpreter-module from GitHub Releases](https://ostis-ai.github.io/ostis-ps-lib/non-atomic-action-interpreter-module/#using-module-as-an-extension-for-sc-machine) or [build it](https://ostis-ai.github.io/ostis-ps-lib/non-atomic-action-interpreter-module/#installation-build).

Firstly, build knowledge base:
Firstly, build knowledge base, make sure `repo.path` file contains paths to `section_subject_domain_of_messages` and `non_subject_domain_concepts` folders of [nika](https://github.com/ostis-apps/nika/):

```sh
./path/to/sc-builder/binary -i repo.path -o kb.bin --clear
Expand All @@ -226,11 +228,13 @@ After run C++ problem solver:

```sh
./path/to/sc-machine/binary -s kb.bin -c ostis-metasystem.ini \
-e "path/to/ostis-metasystem/lib/extensions;path/to/sc-machine/lib/extensions;path/to/scp-machine/lib/extensions;path/to/sc-component-manager/lib/extensions"
-e "path/to/ostis-metasystem/lib/extensions;path/to/sc-machine/lib/extensions;path/to/scp-machine/lib/extensions;path/to/sc-component-manager/lib/extensions;path/to/non-atomic-action-interpreter-module/lib/extensions"
# if several paths to extensions are provided then they should be separated
# by semicolon and wrapped in double quotes
```

Configure environment variables in `.env` to use any LLM for ask-ai replies.

Run Python problem solver in new terminal:

```sh
Expand Down
16 changes: 10 additions & 6 deletions docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
./scripts/install_cxx_problem_solver.sh
```

3. Build knowledge base:
3. Build knowledge base, make sure `repo.path` file contains paths to `section_subject_domain_of_messages` and `non_subject_domain_concepts` folders of [nika](https://github.com/ostis-apps/nika/):

```sh
./install/sc-machine/bin/sc-builder -i repo.path -o kb.bin --clear
Expand All @@ -26,8 +26,8 @@
4. Run C++ problem solver:

```sh
LD_LIBRARY_PATH=./install/sc-machine/lib ./install/sc-machine/bin/sc-machine -s kb.bin -c ostis-metasystem.ini \
-e "install/sc-machine/lib/extensions;install/sc-component-manager/lib/extensions;install/scp-machine/lib/extensions;install/problem-solver/lib/extensions"
LD_LIBRARY_PATH=./install/sc-machine/lib:./install/ps-common-lib/lib ./install/sc-machine/bin/sc-machine -s kb.bin -c ostis-metasystem.ini \
-e "install/sc-machine/lib/extensions;install/sc-component-manager/lib/extensions;install/scp-machine/lib/extensions;install/problem-solver/lib/extensions;install/non-atomic-action-interpreter-module/lib/extensions"
```

5. Download component specifications from repositories. Execute the following command in a running terminal:
Expand Down Expand Up @@ -64,21 +64,25 @@
pip3 install -r platform-dependent-components/problem-solver/py/requirements.txt
```

10. Run Python problem-solver:
10.

Configure environment variables in `.env` to use any LLM for ask-ai replies.

11. Run Python problem-solver:

```sh
python3 platform-dependent-components/problem-solver/py/server.py
```

11. Install and build react interface. Open new terminal and run:
12. Install and build react interface. Open new terminal and run:

```sh
cd platform-dependent-components/interface/react-sc-web
npm install
npm run build
```

12. Run react interface:
13. Run react interface:

```sh
npm run start
Expand Down
5 changes: 5 additions & 0 deletions ostis-metasystem.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
max_loaded_segments = 1000
max_threads = 32
max_events_and_agents_threads = 32
limit_max_threads_by_max_physical_cores=false

dump_memory_period = 3600
dump_memory_statistics_period = 1800
Expand Down Expand Up @@ -40,3 +41,7 @@ interface_components_path = platform-dependent-components/interface/install

[verification]
file_path = verification-results/duplication/

[wit-ai]
server_token = QLK76L2SNBDCXPMZHJLZQU7FAO745S52
url = https://api.wit.ai/message
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(cxx)
add_subdirectory(nlp-translators)
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
add_subdirectory(identifiers-module)
add_subdirectory(sections-module)
add_subdirectory(verification-module)
add_subdirectory(generate-response-module)
add_subdirectory(language-recognition-module)
add_subdirectory(local-common-module)
add_subdirectory(message-classification-module)
add_subdirectory(message-reply-module)
add_subdirectory(search-answer-module)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set(GENERATE_RESPONSE_MODULE_SRC "${CMAKE_CURRENT_LIST_DIR}")

set(HEADERS
"agent/generate-response-agent.hpp"
"constants/generate_response_constants.hpp"
"keynodes/generate_response_keynodes.hpp"
"generate_response_module.hpp"
)

set(SOURCES
"agent/generate-response-agent.cpp"
"constants/generate_response_constants.cpp"
"generate_response_module.cpp"
)

add_library(generate-response-module SHARED ${HEADERS} ${SOURCES})

target_link_libraries(generate-response-module
LINK_PUBLIC sc-machine::sc-memory
LINK_PUBLIC sc-machine::sc-agents-common
LINK_PUBLIC sc-machine::sc-core)
target_include_directories(generate-response-module
PUBLIC ${GENERATE_RESPONSE_MODULE_SRC}
PUBLIC ${SC_MEMORY_INCLUDE}
PUBLIC ${SC_CORE_INCLUDE}
PUBLIC ${SC_AGENTS_COMMON_INCLUDE}
)
set_target_properties(generate-response-module PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${SC_EXTENSIONS_DIRECTORY})


if(${SC_CLANG_FORMAT_CODE})
target_clangformat_setup(generate-response-module)
endif()

add_definitions(-DGENERATE_RESPONSE_MODULE_PATH="${CMAKE_CURRENT_LIST_DIR}/")
if(${SC_BUILD_TESTS})
include(${GENERATE_RESPONSE_MODULE_SRC}/test/tests.cmake)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* This source file is part of an OSTIS project. For the latest info, see http://ostis.net
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/

#include <sc-agents-common/utils/GenerationUtils.hpp>
#include <sc-agents-common/utils/CommonUtils.hpp>
#include "sc-memory/sc_addr.hpp"

#include "keynodes/generate_response_keynodes.hpp"
#include "constants/generate_response_constants.hpp"

#include "generate-response-agent.hpp"

using namespace generateResponseModule;

ScResult GenerateResponseAgent::DoProgram(ScActionInitiatedEvent const & event, ScAction & action)
{
SC_LOG_DEBUG(GenerateResponseConstants::generateAnswerAgentClassName + " started");

auto [messageAddr, answerAddr] = action.GetArguments<2>();

ScAddr messageAnswer;
ScAction actionToApply = createActionNode(messageAddr);
try
{
validateAddrWithInvalidParamException(messageAddr, GenerateResponseConstants::messageAddrParamName);
validateAddrWithInvalidParamException(answerAddr, GenerateResponseConstants::answerAddrParamName);
actionToApply.InitiateAndWait();
messageAnswer = actionToApply.GetResult();
}
catch (utils::ScException const & exception)
{
SC_LOG_ERROR(GenerateResponseConstants::generateAnswerAgentClassName << ": " << exception.Message());
return action.FinishWithError();
}

attachAnswer(messageAnswer, messageAddr, answerAddr);

SC_LOG_DEBUG(GenerateResponseConstants::generateAnswerAgentClassName << " finished");
return action.FinishSuccessfully();
}

void GenerateResponseAgent::validateAddrWithInvalidParamException(ScAddr const & addr, std::string const & paramName)
{
SC_CHECK_PARAM(addr, "parameter '" + paramName + "' is not valid");
}

bool GenerateResponseAgent::checkAction(ScAddr const & actionAddr)
{
return m_context.CheckConnector(
GenerateResponseKeynodes::action_generate_response, actionAddr, ScType::ConstPermPosArc);
}

void GenerateResponseAgent::attachAnswer(
ScAddr const & messageAnswer,
ScAddr const & messageAddr,
ScAddr const & answerAddr)
{
utils::GenerationUtils::generateRelationBetween(
&m_context, messageAddr, messageAnswer, GenerateResponseKeynodes::nrel_reply_structure);
m_context.GenerateConnector(ScType::ConstPermPosArc, answerAddr, messageAnswer);
}

ScAction GenerateResponseAgent::createActionNode(ScAddr const & message)
{
ScAddr const actionClass = FindResponseActionClass(message);

ScAction actionNode = m_context.GenerateAction(actionClass);

ScAddrSet mappedRelations;

processParamsFromMessage(message, actionClass, actionNode, mappedRelations);

return actionNode;
}

ScAddr GenerateResponseAgent::FindResponseActionClass(ScAddr const & message)
{
ScAddr actionClass;

ScTemplate responseActionTemplate;
responseActionTemplate.Triple(
GenerateResponseKeynodes::concept_intent_possible_class,
ScType::VarPermPosArc,
ScType::VarNodeClass >> GenerateResponseConstants::messageClassVarName);
responseActionTemplate.Quintuple(
GenerateResponseConstants::messageClassVarName,
ScType::VarCommonArc,
ScType::VarNode >> GenerateResponseConstants::actionClassVarName,
ScType::VarPermPosArc,
GenerateResponseKeynodes::nrel_response_action);
responseActionTemplate.Triple(GenerateResponseConstants::messageClassVarName, ScType::VarPermPosArc, message);

m_context.SearchByTemplateInterruptibly(
responseActionTemplate,
[&actionClass](ScTemplateResultItem const & resultItem) -> ScTemplateSearchRequest
{
actionClass = resultItem[GenerateResponseConstants::actionClassVarName];
return ScTemplateSearchRequest::STOP;
});

if (!m_context.IsElement(actionClass))
SC_THROW_EXCEPTION(utils::ExceptionItemNotFound, "response action class not found");

SC_LOG_INFO("\n\n\n\nFound action " << m_context.GetElementSystemIdentifier(actionClass));
return actionClass;
}

void GenerateResponseAgent::processParamsFromMessage(
ScAddr const & message,
ScAddr const & action,
ScAddr const & actionNode,
ScAddrSet & mappedRelations)
{
ScTemplateParams params;
params.Add(GenerateResponseConstants::messageVarName, message);
params.Add(GenerateResponseConstants::actionClassVarName, action);

SC_LOG_DEBUG(m_context.GetElementSystemIdentifier(action));

ScTemplate templ;
m_context.BuildTemplate(
templ,
m_context.SearchElementBySystemIdentifier(GenerateResponseConstants::roleRelationMappingTemplateName),
params);

m_context.SearchByTemplate(
templ,
[this, &actionNode, &mappedRelations](ScTemplateResultItem const & resultItem)
{
ScAddr const param = resultItem[GenerateResponseConstants::paramVarName];
ScAddr const targetRole = resultItem[GenerateResponseConstants::targetRoleRelationVarName];

ScAddr actionNodeToParamEdge = m_context.GenerateConnector(ScType::ConstPermPosArc, actionNode, param);
m_context.GenerateConnector(ScType::ConstPermPosArc, targetRole, actionNodeToParamEdge);

mappedRelations.insert(targetRole);
});
}

ScAddr GenerateResponseAgent::GetActionClass() const
{
return GenerateResponseKeynodes::action_generate_response;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This source file is part of an OSTIS project. For the latest info, see http://ostis.net
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/

#pragma once

#include <sc-memory/sc_agent.hpp>

namespace generateResponseModule
{
class GenerateResponseAgent : public ScActionInitiatedAgent
{
public:
ScAddr GetActionClass() const override;

ScResult DoProgram(ScActionInitiatedEvent const & event, ScAction & action) override;

private:
using ScAddrSet = std::set<ScAddr, ScAddrLessFunc>;

bool checkAction(ScAddr const & actionAddr);

ScAction createActionNode(ScAddr const & message);

ScAddr FindResponseActionClass(ScAddr const & message);

void processParamsFromMessage(
ScAddr const & message,
ScAddr const & action,
ScAddr const & actionNode,
ScAddrSet & mappedRelations);

void attachAnswer(ScAddr const & messageAnswer, ScAddr const & messageAddr, ScAddr const & answerAddr);

static void validateAddrWithInvalidParamException(ScAddr const & addr, std::string const & paramName);
};

} // namespace generateResponseModule
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This source file is part of an OSTIS project. For the latest info, see http://ostis.net
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/

#include "generate_response_constants.hpp"

namespace generateResponseModule
{
std::string const GenerateResponseConstants::generateAnswerAgentClassName = "GenerateAnswerAgent";
std::string const GenerateResponseConstants::messageAddrParamName = "messageAddr";
std::string const GenerateResponseConstants::answerAddrParamName = "answerAddr";
std::string const GenerateResponseConstants::roleRelationMappingTemplateName = "role_relation_mapping_search_template";
std::string const GenerateResponseConstants::targetRoleRelationVarName = "_target_role";
std::string const GenerateResponseConstants::paramVarName = "_param";
std::string const GenerateResponseConstants::messageVarName = "_message";
std::string const GenerateResponseConstants::messageClassVarName = "_message_class";
std::string const GenerateResponseConstants::actionClassVarName = "_action";

} // namespace generateResponseModule
Loading
Loading