package com.gxwebsoft.ai.factory;

import com.aliyun.bailian20231229.Client;
import com.aliyun.teaopenapi.models.Config;
import com.gxwebsoft.ai.config.KnowledgeBaseConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class KnowledgeBaseClientFactory {

    @Autowired
    private KnowledgeBaseConfig config;
    
    private Client client;

    public Client createClient() throws Exception {
    	if(client == null) {
    		com.aliyun.teaopenapi.models.Config authConfig = new com.aliyun.teaopenapi.models.Config()
    				.setAccessKeyId(config.getAccessKeyId())
    				.setAccessKeySecret(config.getAccessKeySecret());
    		// 下方接入地址以公有云的公网接入地址为例，可按需更换接入地址。
    		authConfig.endpoint = "bailian.cn-beijing.aliyuncs.com";
    		client = new com.aliyun.bailian20231229.Client(authConfig);
    	}
    	
		return client;
    }
}