首页 > 其他分享 >基于阿里云百炼创建一个知识库应用

基于阿里云百炼创建一个知识库应用

时间:2024-06-30 22:58:57浏览次数:1  
标签:知识库 dashscope 阿里 result 云百炼 import

概述

基于大模型做一个知识库,可以自己搭建一个本地大模型,然后做RAG.

  • 将知识库库进行向量化
  • 查询根据向量查询知识库
  • 将知识库作为提示词丢给大模型,大模型处理后返回结果
    在本地部署大模型,资源要求比较高,还需要做程序定制。

阿里云百炼方案

我们可以在阿里云百炼开通一个大模型,它可以创建应用

  • 在阿里云百炼创建知识库
    image

我们可以在知识库,上传文档。

  • 创建一个应用指向改知识库

image

集成到应用中

做好应用后,我们可以通过 阿里云百炼提供的接口,查询我们的知识库了。

package org.example;



import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import java.util.List;


public class BaiLianExample{
    public static void callAgentApp()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
				//使用自己的apikey
                .apiKey("sk-b8d405687fd74a81889195a41da78FF")
                .appId("6bfe00af4fb34ab4b1dfc8387e57f8fc")
                .prompt("jpaas 如何在某个java 方法上记录日志")
                .temperature(0F)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

    public static void main(String[] args) {
        try {
            callAgentApp();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}

上传了两个文档,并测试了一下,我们查询文档是生效的。

标签:知识库,dashscope,阿里,result,云百炼,import
From: https://www.cnblogs.com/yg_zhang/p/18277120

相关文章