ERNIE Bot LLM supporting Qianfan
fanjia1024 opened this issue · comments
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.*;
/**
- 需要添加依赖
-
<groupId>com.squareup.okhttp3</groupId>
-
<artifactId>okhttp</artifactId>
-
<version>4.12.0</version>
*/
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