Ejemplo n.º 1
0
        /// <summary>
        /// Load agent meta
        /// </summary>
        /// <param name="agentName"></param>
        /// <param name="agentDir"></param>
        /// <returns></returns>
        public Agent LoadAgent(AgentImportHeader agentHeader)
        {
            // load agent profile
            string data  = File.ReadAllText(Path.Combine(AgentDir, "agent.json"));
            var    agent = JsonConvert.DeserializeObject <DialogflowAgent>(data);

            agent.Name = agentHeader.Name;
            agent.Id   = agentHeader.Id;

            var result = agent.ToObject <Agent>();

            result.ClientAccessToken    = agentHeader.ClientAccessToken;
            result.DeveloperAccessToken = agentHeader.DeveloperAccessToken;

            result.MlConfig = agent.ToObject <AgentMlConfig>();
            result.MlConfig.MinConfidence = agent.MlMinConfidence;
            result.MlConfig.AgentId       = agent.Id;
            if (agentHeader.Integrations != null)
            {
                agentHeader.Integrations.ForEach(x => x.AgentId = agent.Id);
                result.Integrations = agentHeader.Integrations;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Restore a agent instance from backup json files
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="agentHeader"></param>
        /// <param name="dataDir"></param>
        /// <returns></returns>
        public bool RestoreAgent <TAgentImporter>(AgentImportHeader agentHeader) where TAgentImporter : IAgentImporter, new()
        {
            string dataDir = Path.Combine(DbInitializerPath, "Agents");

            int row = dc.DbTran(() => {
                LoadAgentFromFile <TAgentImporter>(dataDir, agentHeader);
                SaveAgent();
            });

            return(row > 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load agent meta
        /// </summary>
        /// <param name="agentDir"></param>
        /// <returns></returns>
        public Agent LoadAgent(AgentImportHeader agentHeader)
        {
            // load agent profile
            string data  = File.ReadAllText(Path.Combine(AgentDir, "Sebis", $"{agentHeader.Name}{Path.DirectorySeparatorChar}agent.json"));
            var    agent = JsonConvert.DeserializeObject <SebisAgent>(data);

            agent.Name = agentHeader.Name;
            agent.Id   = agentHeader.Id;

            var result = agent.ToObject <Agent>();

            result.ClientAccessToken    = agentHeader.ClientAccessToken;
            result.DeveloperAccessToken = agentHeader.DeveloperAccessToken;

            return(result);
        }
Ejemplo n.º 4
0
        public Agent LoadAgentFromFile <TAgentImporter>(string dataDir, AgentImportHeader agentHeader) where TAgentImporter : IAgentImporter, new()
        {
            var importer = new TAgentImporter();

            importer.AgentDir = dataDir;

            // Load agent summary
            agent = importer.LoadAgent(agentHeader);

            // Load user custom entities
            importer.LoadCustomEntities(agent);

            // Load agent intents
            importer.LoadIntents(agent);

            // Load system buildin entities
            importer.LoadBuildinEntities(agent);

            // Generate corpus
            importer.AssembleTrainData(agent);

            return(agent);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Restore a agent instance from backup json files
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="agentHeader"></param>
        /// <param name="dataDir"></param>
        /// <returns></returns>
        public bool RestoreAgent <TAgentImporter>(AgentImportHeader agentHeader) where TAgentImporter : IAgentImporter, new()
        {
            var importer = new TAgentImporter();

            string dataDir = Path.Join(DbInitializerPath, "Agents");

            int row = dc.DbTran(() => {
                // Load agent summary
                agent = importer.LoadAgent(agentHeader, dataDir);

                // Load user custom entities
                importer.LoadCustomEntities(agent, dataDir);

                // Load agent intents
                importer.LoadIntents(agent, dataDir);

                // Load system buildin entities
                importer.LoadBuildinEntities(agent, dataDir);

                SaveAgent();
            });

            return(row > 0);
        }