如何让finereport连接智能问答大模型,用户在决策系统运行报表时,直接进行问答??

如何让finereport连接智能问答deepseek大模型,用户在决策系统运行报表时,直接进行问答??(思路

用户在报表文本框中输入问题  → 调用DeepSeek API(估计是写个自定义函数) → 返回结果 → FineReport展示答案

)谁能帮我写个自定义函数 class文件 实现这个功能?成功后有偿的谢谢大家!

FineReport 落花满目不问归途 发布于 前天 11:58
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于前天 12:40
最佳回答
0
华莉星宸Lv7专家互助
发布于前天 13:30
最佳回答
0
Y时光Lv5见习互助
发布于前天 19:32
package com.fr.function;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

//调用AI模型工具类
public class DeepSeekAIClientWithHttpClient {

		//AI模型接口
    private static final String API_URL = "https://api.deepseek.com/v1/chat/completions";
		//接口秘钥
    private static final String API_KEY = "your_api_key_here";


    public static String askDeepSeekAI(String question) throws Exception {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(API_URL);
            
            // 设置请求头
            httpPost.setHeader("Content-Type", "application/json");
            httpPost.setHeader("Authorization", "Bearer " + API_KEY);
            
            // 构建请求体
            JSONObject requestBody = new JSONObject();
            requestBody.put("model", "deepseek-chat");
            
            JSONObject message = new JSONObject();
            message.put("role", "user");
            message.put("content", question);
            
            requestBody.put("messages", new JSONObject[] {message});
            requestBody.put("temperature", 0.7);
            
            httpPost.setEntity(new StringEntity(requestBody.toString()));
            
            // 发送请求并处理响应
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                HttpEntity entity = response.getEntity();
                String responseString = EntityUtils.toString(entity);
                
                // 解析JSON响应
                JSONObject jsonResponse = new JSONObject(responseString);
                return jsonResponse.getJSONArray("choices")
                    .getJSONObject(0)
                    .getJSONObject("message")
                    .getString("content");
            }
        }
    }
}

package com.fr.function;
import com.fr.script.AbstractFunction;
import com.fr.log.FineLoggerFactory;
import java.io.File;

//帆软自定义函数,调用这个函数,返回AI模型回答结果
public class GetFileAbsPath extends AbstractFunction {
    public  Object run(Object[] args) {
		
	//用户输入问题
        String para = args[0].toString().trim();
        //返回AI模型回答结果
        return  DeepSeekAIClientWithHttpClient(para);
    }
		
}

  • 落花满目不问归途 落花满目不问归途(提问者) 您好,您能帮我生成这个class文件吗,自定义函数,我这里不太会弄。感谢。
    2025-08-11 08:47 
  • Y时光 Y时光 回复 落花满目不问归途(提问者) 你去申请一下AI模型的秘钥来
    2025-08-11 09:30 
  • 落花满目不问归途 落花满目不问归途(提问者) 回复 Y时光 您好 加我微信 您方便的时候 我来联系您 15552179607
    2025-08-11 09:32 
  • 3关注人数
  • 51浏览人数
  • 最后回答于:前天 19:32
    请选择关闭问题的原因
    确定 取消
    返回顶部