package com.xueyi.nlt.nlt.domain;

import com.alibaba.fastjson2.JSONArray;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class LlmContext implements Serializable {

    List<Context> contextList;

    @Data
    public class Context {
        private String role;
        private String content;

    }

    public LlmContext(String message) {
        contextList = new ArrayList<>();
        Context ctx = new Context();
        ctx.setRole("user");
        ctx.setContent(message);
        contextList.add(ctx);
    }
    public JSONArray toJson() {
        //解释一下代码
        //1. contextList.stream() 生成一个流
        //2. collect(Collectors.toCollection(JSONArray::new)) 将流转换成JSONArray
        return contextList.stream().collect(Collectors.toCollection(JSONArray::new));
    }


}
