智能大模型

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

FineReport 落花满目不问归途 发布于 4 天前
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
用户k6280494Lv6专家互助
发布于4 天前

不支持

最佳回答
0
Y时光Lv5见习互助
发布于4 天前(编辑于 4 天前

做一个问答界面,然后调用AI大模型的接口,将问题输入给AI,结果返回到帆软报表界面

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);
    }
		
}

  • 落花满目不问归途 落花满目不问归途(提问者) 您好 您调用成功过吗??
    2025-08-08 16:00 
  • Y时光 Y时光 回复 落花满目不问归途(提问者) 我没有试过,但是我看过别人操作过,不难
    2025-08-08 16:08 
  • Y时光 Y时光 回复 落花满目不问归途(提问者) 可以参考上述代码,写个自定义函数,正常的话,就可以实现你的需求
    2025-08-08 16:19 
最佳回答
0
snrtuemcLv8专家互助
发布于4 天前(编辑于 4 天前

BI的有支持的

FineChatBI 使用说明 https://help.fanruan.com/finebi/doc-view-2580.html

  • 4关注人数
  • 62浏览人数
  • 最后回答于:4 天前
    请选择关闭问题的原因
    确定 取消
    返回顶部