package com.easyagents.spring.boot.llm.qwen;

import com.easyagents.llm.qwen.QwenChatModel;
import com.easyagents.llm.qwen.QwenChatConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Easy-Agents 大语言模型自动配置。
 *
 * @author 王帅
 * @since 2024-04-10
 */
@ConditionalOnClass(QwenChatModel.class)
@ConditionalOnProperty(prefix = "easy-agents.llm.qwen", name = "api-key")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(QwenProperties.class)
public class QwenAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public QwenChatModel qwenLlm(QwenProperties properties) {
        QwenChatConfig config = new QwenChatConfig();
        config.setApiKey(properties.getApiKey());
        config.setEndpoint(properties.getEndpoint());
        config.setModel(properties.getModel());
        return new QwenChatModel(config);
    }

}
