package com.sonic.cow.utils;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.byteplus.ark.runtime.model.completion.chat.ChatCompletionRequest;

public class ChatResponseFormatUtils {



    /**
     * 获取响应格式
     * @param jsonSchema
     * @param name
     * @param desc
     * @return
     * @throws Exception
     */
    public static ChatCompletionRequest.ChatCompletionRequestResponseFormat getResponseFormat(String jsonSchema, String name, String desc) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        JsonNode schemaNode = mapper.readTree(jsonSchema);
        // 创建响应格式对象，指定返回数据应符合JSON Schema格式，用于定义结构化输出 type值只能为：text、json_schema、json_object
        return new ChatCompletionRequest.ChatCompletionRequestResponseFormat("json_object",
                new ResponseFormatJSONSchemaJSONSchemaParam(name, desc, schemaNode, true));
    }


}
