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 lombok.AllArgsConstructor;
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
public class UserInfo extends AbstractAgent implements Function<UserInfo.Request, String> {
    private final ChatModel chatModel;
    @Override
    public String apply(Request request) {
        return ChatClient.create(chatModel)
                .prompt()
                .functions(getFunctions(UserNameFunction.class))
                .user(request.query())
                .call()
                .content();
    }

    public record Request(
            @JsonProperty(required = true) @JsonPropertyDescription(value = "用户原始的提问") String query) {
    }
}
