package com.qingyun.service.agent;

import com.agentsflex.core.llm.Llm;
import com.agentsflex.core.llm.response.AiMessageResponse;
import com.agentsflex.core.message.SystemMessage;
import com.agentsflex.core.prompt.TextPrompt;
import com.agentsflex.llm.deepseek.DeepseekConfig;
import com.agentsflex.llm.deepseek.DeepseekLlm;

import java.util.Map;

public class DeepseekLlmStrategy implements LlmStrategy {
    public final Llm llm;

    public DeepseekLlmStrategy(DeepseekConfig config) {
        this.llm = new DeepseekLlm(config);
    }

    @Override
    public AiMessageResponse chat(String promptTemplate, Map<String, String> variables) {
        String resolvedPrompt = resolveTemplate(promptTemplate, variables);
        TextPrompt prompt = new TextPrompt();
        prompt.setContent(resolvedPrompt);
        prompt.setSystemMessage(new SystemMessage(promptTemplate));
        return llm.chat(prompt);
    }

    private String resolveTemplate(String template, Map<String, String> variables) {
        for (Map.Entry<String, String> entry : variables.entrySet()) {
            template = template.replace("${" + entry.getKey() + "}", entry.getValue());
        }
        return template;
    }
}
