package com.ch.jedge.glm;

import static com.ch.jedge.jbot.JEJBotLLMConst.sval_modual_glm_llm;

import com.ch.jedge.utils.JEVdbConfigUtil;
import com.changhong.qlib.QData;
import com.changhong.qlib.intf.QIData;
import com.changhong.qlib.util.cmdline.ArgUtils;
import com.changhong.qlib.util.cmdline.CmdUtils;
import com.changhong.qlib.util.sync.SystemUtils;

public class JGlmJava extends QData implements CmdUtils.CmdController {

    private static final JGlmJava instance = new JGlmJava(sval_modual_glm_llm);

    public JGlmJava(String botName) {
        setName(botName);
    }

    @Override
    public String getControllerName() {
        return getName();
    }

    @Override
    public void setControllerName(String s) {
        setName(s);
    }


    public static void glm_main(String[] args) {

        JEVdbConfigUtil.loadConfigs();

        JedgeGlmDriverClient llmDriver = JedgeGlmDriverClient.getInstance();

        QIData param = ArgUtils.handleArgVList(args);

        //加载mgbus的服务器配置参数
        boolean runBack = JEVdbConfigUtil.setupInitConfigs(llmDriver, param, sval_modual_glm_llm);

        if(!llmDriver.start()) {
            llmDriver.errLog("Fail to start ap app : " + llmDriver.getName());
            return;
        }

        while(!llmDriver.isActive()) {
            //等待接入成功
            llmDriver.warnLog("Wait for apApp to connect to mgbus : " + llmDriver.getName());
            SystemUtils.tryWait(2000);
        }

        CmdUtils.run(instance, runBack, param);

        llmDriver.shutdown();

        JEVdbConfigUtil.releaseConfigs();
    }

}
