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

import com.easyagents.llm.ollama.OllamaChatModel;
import com.easyagents.llm.ollama.OllamaChatConfig;
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 Ollama自动配置。
 *
 * @author hustlelr
 * @since 2025-02-11
 */
@ConditionalOnClass(OllamaChatModel.class)
@ConditionalOnProperty(prefix = "easy-agents.llm.ollama", name = "model")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(OllamaProperties.class)
public class OllamaAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public OllamaChatModel ollamaLlm(OllamaProperties properties) {
        OllamaChatConfig config = new OllamaChatConfig();
        config.setApiKey(properties.getApiKey());
        config.setEndpoint(properties.getEndpoint());
        config.setModel(properties.getModel());
        config.setThinkingEnabled(Boolean.TRUE.equals(properties.getThink()));
        return new OllamaChatModel(config);
    }

}
