package io.github.qifan777.knowledge.ai.agent.userAgent;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import io.github.qifan777.knowledge.ai.agent.AbstractAgent;
import io.github.qifan777.knowledge.ai.agent.Agent;
import io.github.qifan777.knowledge.context.UserContext;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

/**
 * <p>
 *
 * </p>
 *
 * @author taohongrun
 * @since 2025/3/14
 */
@Agent
@Description("回答用户关于我的成绩，查询成绩，获取成绩相关问题")
@AllArgsConstructor
@Slf4j
public class UserInfo extends AbstractAgent implements Function<UserInfo.Request, String> {
    private final ChatModel chatModel;

    @Override
    public String apply(Request request) {
        System.out.println(request.userName);
        return ChatClient.create(chatModel)
                .prompt()
                .system(s -> s.text("用户名为{userName}，需要查询成绩信息。问题：{query}")
                        .param("userName", request.userName)
                        .param("query", request.query()))
                .functions(getFunctions(UserNameFunction.class))
                .user(userSpec -> userSpec
                        .param("userName", request.userName) // 传递参数
                        .text(request.query()))
                .call()
                .content();
    }

    public record Request(
            @JsonProperty(required = true) @JsonPropertyDescription(value = "用户原始的提问") String query,
            @JsonProperty(required = true)
            @JsonPropertyDescription("this param is user's name")
            String userName) {
    }
}
