Skip to content

Latest commit

 

History

History
145 lines (112 loc) · 6.09 KB

README-EN.md

File metadata and controls

145 lines (112 loc) · 6.09 KB
中文  |  EN

gear-wenxinworkshop-starter

LICENSE Spring Boot JDK Maven

COMMIT LANG

# Gear-WenXinWorkShop-Starter

How to get access-token?

Apply for WenxinYiyan & WenxinQianfan Big model API qualification, get access_token, and use SpringBoot to access WenxinYiyan API

  1. Go to WenXinYiYan qualification application

  2. Fill out the questionnaire,and wait for approval (it took me one and a half days)

  3. After approval,enter the console,clickCreate Application

  4. Enter the left side Application List,copyAPI Key and Secret Key

  5. Replace your API Key and Secret Key with [Key] in the link and visit the following address

https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=[API-Key]&client_secret=[Secret-Key]

📖 Project Introduction

  • 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 ErnieBotERNIE-Bot-turboBLOOMZ-7BErnie-Bot-VilGVisualGLM-6BLlama-2Linly-Chinese-LLaMA-2-7BLinly-Chinese-LLaMA-2-13BChatGLM2-6BRWKV-4-WorldOpenLLaMA-7BFalcon-7BDolly-12BMPT-7B-InstructStable-Diffusion-v1.5RWKV-4-pile-14BRWKV-5-WorldRWKV-Raven-14BFalcon-40BMPT-30B-instructFlan-UL2Cerebras-GPT-13BCerebras-GPT-6.7BPythia-12BPythia-6.9BGPT-J-6BGPT-NeoX-20BOA-Pythia-12B-SFT-4GPT4All-JStableLM-Alpha-7BStarCoderPrompt Template models (single round conversation, continuous conversation, streaming return).
  • Support formore models will be added in behind version.

🚀 Quick Start

Project demo

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.

1、Add Dependencies

  • 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' 
}

2、Add access-token

  • 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

3、Invoke Example

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

}

📑Documentation

Click => Documents

Open Source License

LICENSE