package tech.easyflow.ai.easyagentsflow.llm;

import com.easyagents.flow.support.provider.EasyAgentsLlm;
import com.easyagents.flow.core.llm.Llm;
import com.easyagents.flow.core.llm.LlmProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import tech.easyflow.ai.entity.Model;
import tech.easyflow.ai.service.ModelService;

import javax.annotation.Resource;
import java.math.BigInteger;

@Component
public class LlmProviderImpl implements LlmProvider {

    private static final Logger log = LoggerFactory.getLogger(LlmProviderImpl.class);
    @Resource
    private ModelService modelService;

    @Override
    public Llm getChatModel(Object modelId) {
        Model model = modelService.getModelInstance(new BigInteger(modelId.toString()));
        if (model == null) {
            log.error("LlmProviderImpl.getChatModel: modelId not found: {}", modelId);
            return null;
        }
        EasyAgentsLlm llm = new EasyAgentsLlm();
        llm.setChatModel(model.toChatModel());
        return llm;
    }
}
