Example #1
0
        public async Task <ReasoningTaskResource> CreateTaskAsync(CreateReasoningTaskResource reasoningTaskResource)
        {
            var knowledgeBase = await _knowledgeBaseRepository.GetAsync(reasoningTaskResource.KnowledgeBaseId);

            if (knowledgeBase == null)
            {
                var message = $"Couldn't find knowledge base with id `{reasoningTaskResource.KnowledgeBaseId}`";

                _logger.LogInformation(message);
                throw new Exception(message);
            }

            var reasoningProcess = ReasoningProcessFactory.CreateInstance(
                await _knowledgeBaseRepository.GetAsync(reasoningTaskResource.KnowledgeBaseId),
                reasoningTaskResource.ReasoningMethod,
                reasoningTaskResource.Hypothesis
                );

            var result = ReasoningTaskFactory.CreateInstance(
                _reasoningService.ClearReasoning(reasoningProcess),
                reasoningTaskResource.Description,
                reasoningTaskResource.Sources,
                reasoningTaskResource.Actions
                );

            _reasoningTaskRepository.Create(result);

            _logger.LogInformation($"Reasoning task {result.Id} has been created");

            _reasoningTaskResolver.EnqueueReasoningTask(result.Id);

            return(GetReasoningTaskResource(result));
        }
        /// <summary>
        /// Retrieves unresolved tasks from database
        /// </summary>
        public void RetrieveTasks()
        {
            _logger.LogInformation($"Retrieving waiting tasks");

            var tasks = _reasoningTaskService.GetAllWaitingTasksAsync().Result;

            tasks.ToList().ForEach(task =>
            {
                _reasoningTaskResolver.EnqueueReasoningTask(task.Id);
            });

            _logger.LogInformation($"Waiting tasks have been retrieved");
        }