数字人面试官项目中的短信服务与 GLM 调用测试
引言
在数字人面试官项目中,短信服务和与大语言模型(如 ChatGLM)的交互是两个重要的功能模块。短信服务可用于通知应聘者面试信息等,而与 GLM 的交互则可以用于生成面试结果等。本文将介绍项目中的短信服务实现以及 GLM 调用测试的相关内容。
短信服务实现
项目中使用腾讯云短信服务来实现短信发送功能,通过
SMSUtils 类封装了短信发送的逻辑。public void sendSMS(String phone, String code) throws Exception {
try {
Credential cred = new Credential(tencentCloudProperties.getSecretId(),
tencentCloudProperties.getSecretKey());
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("sms.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SmsClient client = new SmsClient(cred, "ap-nanjing", clientProfile);
SendSmsRequest req = new SendSmsRequest();
String[] phoneNumberSet1 = {"+86" + phone};
req.setPhoneNumberSet(phoneNumberSet1);
req.setSmsSdkAppId("1400568450");
req.setSignName("风间影月");
req.setTemplateId("1108902");
String[] templateParamSet1 = {code};
req.setTemplateParamSet(templateParamSet1);
SendSmsResponse resp = client.SendSms(req);
System.out.println(SendSmsResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
在实际应用中,可以在应聘者报名成功或者面试安排确定时调用该方法,向应聘者发送相关的短信通知,例如面试时间、地点等信息。
GLM 调用测试
项目中对 ChatGLM 的调用进行了测试,通过
MyGLMTestV3 和 MyGLMTestV4 类实现。以 MyGLMTestV4 为例,测试代码如下:java
@Test
public void test_completions() throws JsonProcessingException, InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
Request request = new Request.Builder()
.url(apiUrl)
.header("Authorization", GLMTokenUtils.generateToken())
.header("Content-Type", JSON_CONTENT_TYPE)
.header("User-Agent", DEFAULT_USER_AGENT)
.header("Accept", SSE_CONTENT_TYPE)
.post(RequestBody.create(MediaType.parse("application/json"), generateBodyString()))
.build();
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(connectTimeout, TimeUnit.SECONDS)
.writeTimeout(writeTimeout, TimeUnit.SECONDS)
.readTimeout(readTimeout, TimeUnit.SECONDS)
.build();
RealEventSource realEventSource = new RealEventSource(request, new EventSourceListener() {
@Override
public void onEvent(EventSource eventSource, @Nullable String id, @Nullable String type, String data) {
if (isDone(data)) {
System.out.println("结束事件");
} else {
GLMResponseV4 response = JsonUtils.jsonToPojo(data, GLMResponseV4.class);
System.out.println(response);
}
}
@Override
public void onClosed(EventSource eventSource) {
System.out.println("关闭链接事件");
countDownLatch.countDown();
}
@Override
public void onOpen(EventSource eventSource, Response response) {
System.out.println("打开链接事件");
}
@Override
public void onFailure(EventSource eventSource, @Nullable Throwable t, @Nullable
