spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
2.84k stars 710 forks source link

ERNIE Bot LLM supporting Qianfan #514

Closed fanjia1024 closed 2 days ago

fanjia1024 commented 5 months ago

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior

package baidu.com;

import okhttp3.*; import org.json.JSONObject;

import java.io.*;

/**

class Sample { public static final String API_KEY = "R0LQW1U1nD8zDB1vWNuSjKWs"; public static final String SECRET_KEY = "nH1t28SijaehHDGxtFoQQHFtzJt5qqWE";

static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();

public static void main(String []args) throws IOException{
    MediaType mediaType = MediaType.parse("application/json");
    RequestBody body = RequestBody.create(mediaType, "{\"disable_search\":false,\"enable_citation\":false}");
    Request request = new Request.Builder()
        .url("https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=" + getAccessToken())
        .method("POST", body)
        .addHeader("Content-Type", "application/json")
        .build();
    Response response = HTTP_CLIENT.newCall(request).execute();
    System.out.println(response.body().string());

}

/**
 * 从用户的AK,SK生成鉴权签名(Access Token)
 *
 * @return 鉴权签名(Access Token)
 * @throws IOException IO异常
 */
static String getAccessToken() throws IOException {
    MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
    RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials&client_id=" + API_KEY
            + "&client_secret=" + SECRET_KEY);
    Request request = new Request.Builder()
            .url("https://aip.baidubce.com/oauth/2.0/token")
            .method("POST", body)
            .addHeader("Content-Type", "application/x-www-form-urlencoded")
            .build();
    Response response = HTTP_CLIENT.newCall(request).execute();
    return new JSONObject(response.body().string()).getString("access_token");
}

}

Current Behavior

now The current springai does not support Qianfan's ERNIE Bot model

Context

Now we use Qianfan's ERNIE Bot, but it can't be integrated through springai I hope to integrate using the starter approach in Springai so that I can use more large models to complete the development of intelligent agents Now we can use the SDK provided by Qianfan, but we need to do a lot of compatibility work, which is not a good design. The current Langchain4j has already been integrated, but we have chosen Springai as our preferred framework

markpollack commented 1 month ago

There is now support for QianFan does this meet your needs?

@mxsl-gr What are your thoughts?

mxsl-gr commented 1 month ago

@markpollack Sorry, I've been busy with other projects lately. I didn't notice this issue when implementing the QianFan model, i think can be closed.  Hi, @fanjia1024 the version 1.0.0-M2 has not been released yet. I suggest you pull the main branch code, run mvn install or mvn deploy it to your private repo, and use version 1.0.0-SNAPSHOT.  for QianFan's specific configurations, you can refer to the documentation at /spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/qianfan-chat.adoc