package com.cmvr.llm.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.cmvr.llm.service.LLMAiAgentPlatformService;
import com.cmvr.llm.util.LlmChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class LLMAiAgentPlatformServiceImpl  implements LLMAiAgentPlatformService {
    private final LlmChatService llmChatService;
    @Override
    public JSONObject query(String action, String text, String apiKey, Boolean invokeTts, JSONObject config) {
        Map<String, Object> body = new HashMap<>();
        body.put("Query", text);
        long startTime = System.currentTimeMillis();
        String result = null;
        try {
            result = llmChatService.chat(
                    apiKey,  // apiKey (header用)
                    apiKey,  // apiId (body的AppKey)
                    "user_123",               // userId
                    body,
                    invokeTts,
                    config
            );
            System.out.println( result);
            System.out.println("总耗时：" + (System.currentTimeMillis() - startTime));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new JSONObject().fluentPut("result", result);
    }
}
