-
Fill out the questionnaire,and wait for approval (it took me one and a half days)
-
After approval,enter the console,clickCreate Application
-
Enter the left side Application List,copy
API Key
andSecret Key
-
Replace your
API Key
andSecret Key
with [Key] in the link and visit the following address
- The spring-boot-starter of Baidu's "Wenxin Qianfan WENXINWORKSHOP" large model can help you quickly access Baidu's AI capabilities. You can call Baidu's Wenxin Qianfan large model with only one line of code.
- Complete docking with the official API documentation of WenxinQianfan.
- Support streaming back of conversations.
- Full API support for
ErnieBot
、ERNIE-Bot-turbo
、BLOOMZ-7B
、Ernie-Bot-VilG
、VisualGLM-6B
、Llama-2
、Linly-Chinese-LLaMA-2-7B
、Linly-Chinese-LLaMA-2-13B
、ChatGLM2-6B
、RWKV-4-World
、OpenLLaMA-7B
、Falcon-7B
、Dolly-12B
、MPT-7B-Instruct
、Stable-Diffusion-v1.5
、RWKV-4-pile-14B
、RWKV-5-World
、RWKV-Raven-14B
、Falcon-40B
、MPT-30B-instruct
、Flan-UL2
、Cerebras-GPT-13B
、Cerebras-GPT-6.7B
、Pythia-12B
、Pythia-6.9B
、GPT-J-6B
、GPT-NeoX-20B
、OA-Pythia-12B-SFT-4
、GPT4All-J
、StableLM-Alpha-7B
、StarCoder
、Prompt Template
models (single round conversation, continuous conversation, streaming return). - Support formore models will be added in behind version.
This version almost refactoring the entire project, the path between the client and the parameter class has changed, there is a certain incompatibility with the previous version, the method has not changed, just re-guide the package.
"Bloomz7BClient" -> "BloomZ7BClient"
Except "ErnieBot" and "Prompt", the receiving parameter class of the other conversational models is unified as ChatBaseRequest, and the response class is ChatResponse
The receiving parameter class of the image generation model is unified as ChatImageRequest, the response class is ImageBaseRequest, and the content is base64 encoded image.
- Maven
<dependency>
<groupId>io.github.gemingjia</groupId>
<artifactId>gear-wenxinworkshop-starter</artifactId>
<version>1.1.1</version>
</dependency>
- Gradle
dependencies {
implementation 'io.github.gemingjia:gear-wenxinworkshop-starter:1.1.1'
}
- application.yml & application.yaml
gear: wenxin: access-token: xx.xxxxxxxxxx.xxxxxx.xxxxxxx.xxxxx-xxxx
- application.properties
gear.wenxin.access-token=xx.xxxxxxxxxx.xxxxxx.xxxxxxx.xxxxx-xxxx
@RestController
public class ChatController {
// 要调用的模型的客户端
@Resource
private ErnieBotClient ernieBotClient;
// 单次对话
@PostMapping("/chat")
public Mono<ChatResponse> chatSingle(String msg) {
return ernieBotClient.chatSingle(msg);
}
// 连续对话
@PostMapping("/chats")
public Mono<ChatResponse> chatCont(String msg) {
String chatUID = "test-user-1001";
return ernieBotClient.chatCont(msg, chatUID);
}
// 流式返回,单次对话
@GetMapping(value = "/stream/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> chatSingleStream(@RequestParam String msg) {
Flux<ChatResponse> chatResponse = ernieBotClient.chatSingleOfStream(msg);
return chatResponse.map(response -> "data: " + response.getResult() + "\n\n");
}
// 流式返回,连续对话
@GetMapping(value = "/stream/chats", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> chatContStream(@RequestParam String msg, @RequestParam String msgUid) {
Flux<ChatResponse> chatResponse = ernieBotClient.chatContOfStream(msg, msgUid);
return chatResponse.map(response -> "data: " + response.getResult() + "\n\n");
}
// 模板对话
@PostMapping("/prompt")
public Mono<PromptResponse> chatSingle() {
Map<String, String> map = new HashMap<>();
map.put("article", "我看见过波澜壮阔的大海,玩赏过水平如镜的西湖,却从没看见过漓江这样的水。漓江的水真静啊,静得让你感觉不到它在流动。");
map.put("number", "20");
PromptRequest promptRequest = new PromptRequest();
promptRequest.setId(1234);
promptRequest.setParamMap(map);
return promptBotClient.chatPrompt(promptRequest);
}
}
Click =>
Documents