package com.cmvr.test.flow.runtime.operator.llm;

import com.cmvr.common.exception.GlobalException;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteMessage;
import com.cmvr.test.flow.runtime.message.TaskNodeExecuteResult;
import com.cmvr.test.flow.runtime.operator.AbstractNodeOperateHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component("LLM")
@RequiredArgsConstructor
public class LLMNodeOperateHandler extends AbstractNodeOperateHandler {

    private final List<LLMOperateService> llmOperateServices;

    @Override
    protected TaskNodeExecuteResult doExecute(TaskNodeExecuteMessage message) {
        return llmOperateServices.stream()
                .filter(s -> s.supports(message.getAction()))
                .findFirst()
                .map(s -> s.execute(message))
                .orElseThrow(() -> new GlobalException("不支持的大模型操作: " + message.getAction()));
    }
}
