@@ -1,255 +1,245 @@
package com.newyetai ;
import com.newyetai .sdk.xf.config.XfProperties.XfAppProperties ;
import com.newyetai .sdk.xf.model.TranslateReq ;
import com.newyetai .sdk.xf.service.RtasrClientApp ;
import java.io.File ;
import java.io.FileIn putStream ;
import java.io.FileNotFound Exception ;
import java.io.FileOut putStream ;
import java.io.IOException ;
import java.io.InputStream ;
import java.io.OutputStream ;
import java.util.HashMap ;
import java.util.Map ;
import javax.sound.sampled.AudioFileFormat ;
import javax.sound.sampled.AudioFormat ;
import javax.sound.sampled.AudioInputStream ;
import javax.sound.sampled.AudioSystem ;
import javax.sound.sampled.UnsupportedAudioFileException ;
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream ;
import org.junit.jupiter.api.Test ;
import org.springframework.http.HttpEntity ;
import org.springframework.http.HttpHeader s;
import org.springframework.http.HttpMethod ;
import org.springframework.http.ResponseEntity ;
import com.google.common.collect.Lists ;
import com.newyetai.common.AlitaResult ;
import com.newyetai.common.exception.BusinessException ;
import com.newyetai.common.exception.util.Assert ;
import com.newyetai.common.util.JsonUtils ;
import c om.newyetai.component.file.entity.FileRecord ;
import com.newyetai.component.file.util.FileUtils ;
import com.newyetai.sdk.common.util.HttpUtils ;
import com.newyetai.sdk.xf.config.XfProperties ;
import com.newyetai.sdk.xf.model.ChatReq ;
import com.newyetai.sdk.xf.model.MessageDTO ;
import com.newyetai.sdk.xf.service.XfSparkProvi der;
import com.newyetai.sdk.xf.util.WebIATWS ;
import com.newyetai.sdk.xf.util.WebTtsWS ;
import lombok.extern.slf4j.Slf4j ;
@Slf4j
public class SparkTest {
static String httpAPIPassword = " " ;
static XfProperties xfProperties = XfProperties . builder ( )
. iatHostUrl ( " https://iat-api.xfyun.cn/v2/iat " )
. ttsHostUrl ( " https://tts-api.xfyun.cn/v2/tts " )
. otsHostUrl ( " https://ntrans.xfyun.cn/v2/ots " )
. httpAPIPassword ( " EfqszvaEEoTnUfQRRcvr:ohEYAwzpIiUeWFvZAqEk " )
. appI d ( " 83b8ddca " )
. apiSecret ( " ZWE2MjkzY2VmZDkwM2EwZGJhNGRhOWJm " )
. apiKey ( " e092f93e28ebe6d27f756bb2d884dcff " )
. rtasr ( XfAppProperties . builder ( ) . apiKey ( " 2e33d9128a73be21b294594e5377ca53 " ) . build ( ) )
. build ( ) ;
@Test
public void test ( ) {
HttpHeaders header = new HttpHeaders ( ) ;
heade r. add ( " Authorization " , " Bearer " + httpAPIPassword ) ;
header . add ( " Content-Type " , " application/json " ) ;
/ / 发送请求
Map < String , Object > data = new HashMap < String , Object > ( ) ;
data . put ( " model " , " 4.0Ultra " ) ;
Map < String , Object > r1 = new HashMap < String , Object > ( ) ;
r1 . put ( " role " , " system " ) ;
r1 . p ut( " content " , " 你是一位专业的HR。目标任务: 请根据我给出的position_name生成5个相关的面试中可能会问到的问题,并为每个问题都生成一个参考答案, 并从1开始生成问题序号 " ) ;
Map < String , Object > r2 = new HashMap < String , Object > ( ) ;
r2 . put ( " role " , " system " ) ;
r2 . put ( " content " , " 全部数据以JSON模版的形式返回, 格式为:{position_name:岗位信息, [{qno:问题序号,q:问题,a:参考答案}]} " ) ;
Map < String , Object > r3 = new HashMap < String , Object > ( ) ;
r3 . put ( " role " , " user " ) ;
r3 . put ( " content " , " { \" positionName \" : \" java开发 \" } " ) ;
data . put ( " messages " , Lists . newArrayList ( r1 , r2 , r3 ) ) ;
HttpEntity requestEntity = new HttpEntity ( data , header ) ;
ResponseEntity < String > response = HttpUtils . r estTemplate . exchange ( " https://spark-api-open.xf-yun.com/v1/chat/completions " , HttpMethod . POST , requestEntity , String . class ) ;
System . out . println ( JsonUtils . toDefaultJsonString ( response ) ) ;
}
@Test
public void testAlita ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的HR。目标任务: 请根据我给出的信息生成5个相关的面试中可能会问到的问题,并为每个问题都生成一个参考答案, 并从1开始生成问题序号 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 全部数据以JSON模版的形式返回, 格式为:[{qno:问题序号,q:问题,a:参考答案}] " ) . build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " jobName " ) . build ( ) ) . build ( ) ;
AlitaResult < ? > res = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , res ) ;
}
@Test
public void testEvaluate ( ) {
ChatReq req = ChatReq . builder ( )
. message ( M essageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历撰写专家。目标任务:请根据我给出的信息,生成指定的内容。需求说明:要求在与原文语意一致的基础上扩写内容,风格设定,简明扼要。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 根据我输入的信息, 输出1段自我评价, 包含学习能力、工作态度、团队协作等方面, 字数在300字左右 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 全部数据以JSON模版的形式返回, 格式为:{'selfEva': xxx} " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " 环卫工 " ) . build ( ) ) . build ( ) ;
AlitaResult < ? > r es = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , res ) ;
}
@Test
public void testWorkExperience ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历撰写专家。目标任务:请根据我给出的信息,生成一份履历丰富的简历。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 简历内容包含个人信息简介、工作经历、教育背景、掌握技能、自我评价。以JSON格式返回, 每个点作为一个对象。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 个人信息输出格式为:{姓名: xxx, 年龄: xxx, 联系电话: xxx, 联系邮箱: xxx} " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 工作经历以数组的形式返回。输出格式为:[{企业名称: xxx, 岗位: xxx, 工作职责: [xxx,xxx,xxx],工作时间:xxx-xxx}] " )
. build ( ) )
. message ( M essageDTO . builder ( ) . role ( " system " )
. content ( " 掌握技能必须作为数组输出 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 自我评价必须作为数组输出 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " )
/ / . content ( " { \" name \" : \" 小明 \" , \" gender \" :1, \" contactWay \" : \" 0717-123123 \" , \" birthDay \" : \" 1980-07 \" , \" work \" : \" 在一家科技公司干了4年 \" } " )
. content ( " 我是小明, 在一家科技公司干了4年 " )
. build ( ) ) . build ( ) ;
AlitaResult < String > result = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , result ) ;
}
@Test
public void testAnalyseResume ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历分析专家。目标任务: 请根据我给出的信息, 分析得出简历信息。不要自己填充json信息 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 请生成一个包含以下信息的 JSON 数据,根据用户给出的实际信息解析,值都可为空 : \ n "
+ " - name( 字符串类型) : 表示用户的姓名。 \ n "
+ " - sex( 字符串类型) : 表示用户的性别, 值为 \" 1 \" (男)或 \" 2 \" (女),身份证号倒数第二位,奇数是男,偶数是女。 \n "
+ " - phone( 字符串类型) : 表示用户的联系电话, 可为空, 不为空的格式为 以 1 开头,共 11 位数字。 \ n "
+ " - email( 字符串类型) : 表示用户的联系电子邮箱地址, 可为空, 不为空的格式为 包含 @ 符号,且 @ 前后至少有一个字符 及 域名部分至少包含一个 . 符号。 \ n "
+ " - intentionPosition( 字符串类型) : 表示用户的意向职位。 \ n "
+ " - major( 字符串类型) : 表示用户的专业。 \ n "
+ " - birthday( 日期类型) : 表示用户的出生日期, 格式为 YYYY-MM。 \ n "
+ " - jobTime( 日期类型) : 表示用户的参加工作时间, 格式为 YYYY-MM。 \ n "
+ " - school( 字符串类型) : 表示用户的毕业院校。 \ n "
+ " - education( 字符串类型) : 表示用户的学历, 值为: \ n "
+ " - \" 1 \" : \" 博士 \" \ n "
+ " - \" 2 \" : \" 硕士 \" \ n "
+ " - \" 3 \" : \" 本科 \" \ n "
+ " - \" 4 \" : \" 大专 \" \ n "
+ " - \" 5 \" : \" 中专 \" \ n "
+ " - \" 6 \" : \" 技校 \ "\ n "
+ " - \" 7 \" : \" 职高 \" \ n "
+ " - \ "9 \ ": \ "高中 \ "\ n "
+ " - \" 10 \" : \" 初中 \" \ n "
+ " - \" 11 \ ": \ "小学 \" \ n "
+ " - workExperience( 字符串类型) : 表示用户的工作经历, 格式为多行文本, 包含以下信息: \ n "
+ " - 企业名称 \ n "
+ " - 岗位 \ n "
+ " - 工作时间 \ n "
+ " - 工作职责 \ n "
+ " - selfEvaluation( 字符串类型) : 表示用户的自我评价, 格式为多行文本。 " )
. bu ild ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " 我是小明, 身份证号是110105199003071234, 小学毕业, 前年在一家科技公司干了1年, 现在想找个环卫工的活, 请用abc@33.com联系我 " ) . build ( ) ) . build ( ) ;
AlitaResult < String > result = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , result ) ;
}
@Test
public void iat ( ) throws IOException {
String file = " src/main/resources/iat/cn.pcm " ;
try ( InputStream is = new FileInputStream ( file ) ) {
AlitaResult < String > result = WebIATWS . execute ( is , xfProperties ) ;
log . info ( " {} " , result ) ;
}
/ / / / 示例的WebM文件路径 ( 请替换为实际的有效路径 )
String webmFilePath = " src/main/resources/iat/audio.webm " ;
/ / / / 示例的输出MP3文件路径 ( 请替换为实际的有效路径 )
/ / String mp3FilePath = " src/main/resources/iat/file.mp3 " ;
/ / try ( InputStream is = FileUtils . convertWebmToMp3 ( new File ( webmFilePath ) ) ) {
/ / AlitaResult < String > result = WebIATWS . execute ( is , xfProperties ) ;
/ / log . info ( " {} " , result ) ;
/ / }
}
@Test
public void tts ( ) throws Exception {
/ / try ( OutputStream outputStream = new FileOutputStream ( " src/main/resources/iat/2 23.mp3 " ) ; ) {
/ / WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
/ / }
/ / try ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ;
/ / OutputStream fs = new FileOutputStream ( " src/main/resources/iat/323.mp3 " ) ; ) {
/ / WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
/ / fs . write ( outputStream . toByteArray ( ) ) ;
/ / }
try ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ;
OutputStream fs = new FileOutputStream ( " src/main/resources/iat/323.mp3 " ) ; ) {
AlitaResult < Void > result = WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
Ass ert . isTrue ( result . getSuccess ( ) , result . getMsg ( ) ) ;
fs . write ( outputStream . toByteArray ( ) ) ;
} catch ( IOException e ) {
throw new BusinessException ( " 语音合成异常: " + e . getMessage ( ) ) ;
}
}
@Test
public void ots ( ) {
/ / AlitaResult < ? > result = XfSparkProvider . translate ( TranslateReq . builder ( ) . text ( " 欢迎#你啊,.;@#$你好 " ) . build ( ) , xfProperties ) ;
AlitaResult < ? > result = XfSparkProvider . translate ( TranslateReq . builder ( ) . text ( " تىيانەي ئەقىللىق خىزمەت مۇلازىمىتى بىرلەشمە سۇپىسىغا خوش ھەمرىيىڭىز. " ) . from ( " uy " ) . to ( " cn " ) . build ( ) , xfProperties ) ;
log . info ( " {} " , result ) ;
}
@Test
public void rtasr ( ) throws IOException {
String file = " src/main/resources/iat/ug.pcm " ;
try ( InputStream is = new FileInputStream ( file ) ) {
AlitaResult < String > result = RtasrClientApp . execute ( is , " cn_uyghur " , xfProperties ) ;
log . info ( " {} " , result ) ;
}
}
@Test
public void chat ( ) {
ChatReq req = ChatReq . builder ( ) . message ( MessageDTO . builder ( ) . role ( " system " ) . content (
" 你是一位专业的简历分析专家。目标任务: 请根据我给出的信息, 分析得出简历信息。不要自己填充json信息 " )
. role ( " user " ) . content ( " 我是大学生 " )
. build ( ) ) . build ( ) ;
AlitaResult < String > result = XfSparkProvider . httpChat ( req , xfProperties . getHttpAPIPassword ( ) ) ;
Assert . isTrue ( result . getSuccess ( ) , result . getMsg ( ) ) ;
log . info ( " {} " , result ) ;
}
}
package com.senmesh ;
import com.senmesh .sdk.xf.config.XfProperties.XfAppProperties ;
import com.senmesh .sdk.xf.model.TranslateReq ;
import com.senmesh .sdk.xf.service.RtasrClientApp ;
import java.io.FileInputStream ;
import java.io.FileOut putStream ;
import java.io.IO Exception ;
import java.io.In putStream ;
import java.io.OutputStream ;
import java.util.HashMap ;
import java.util.Map ;
import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream ;
import org.junit.jupiter.api.Test ;
import org.springframework.http.HttpEntity ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpMethod ;
import org.springframework.http.ResponseEntity ;
import com.google.common.collect.Lists ;
import com.senmesh.common.AlitaResult ;
import com.senmesh.common.exception.BusinessException ;
import com.senmesh.common.exception.util.Assert ;
import com.senmesh.common.util.JsonUtil s;
import com.senmesh.sdk.common.util.HttpUtils ;
import com.senmesh.sdk.xf.config.XfProperties ;
import com.senmesh.sdk.xf.model.ChatReq ;
import com.senmesh.sdk.xf.model.MessageDTO ;
import com.senmesh.sdk.xf.service.XfSparkProvider ;
import com.senmesh.sdk.xf.util.WebIATWS ;
import com.senmesh.sdk.xf.util.WebTtsWS ;
import l ombok.extern.slf4j.Slf4j ;
@Slf4j
public class SparkTest {
static String httpAPIPassword = " " ;
static XfProperties xfProperties = XfProperties . buil der( )
. iatHostUrl ( " https://iat-api.xfyun.cn/v2/iat " )
. ttsHostUrl ( " https://tts-api.xfyun.cn/v2/tts " )
. otsHostUrl ( " https://ntrans.xfyun.cn/v2/ots " )
. httpAPIPassword ( " EfqszvaEEoTnUfQRRcvr:ohEYAwzpIiUeWFvZAqEk " )
. appId ( " 83b8ddca " )
. apiSecret ( " ZWE2MjkzY2VmZDkwM2EwZGJhNGRhOWJm " )
. apiKey ( " e092f93e28ebe6d27f756bb2d884dcff " )
. rtasr ( XfAppProperties . builder ( ) . apiKey ( " 2e33d9128a73be21b294594e5377ca53 " ) . build ( ) )
. build ( ) ;
@Test
public void test ( ) {
HttpHeaders header = new HttpHeaders ( ) ;
header . add ( " Authorization " , " Bearer " + httpAPIPassword ) ;
header . ad d ( " Content-Type " , " application/json " ) ;
/ / 发送请求
Map < String , Object > data = new HashMap < String , Object > ( ) ;
data . put ( " model " , " 4.0Ultra " ) ;
Map < String , Object > r1 = new HashMap < String , Object > ( ) ;
r1 . put ( " role " , " system " ) ;
r1 . put ( " content " , " 你是一位专业的HR。目标任务: 请根据我给出的position_name生成5个相关的面试中可能会问到的问题,并为每个问题都生成一个参考答案, 并从1开始生成问题序号 " ) ;
Map < String , Object > r2 = new HashMap < String , Object > ( ) ;
r2 . put ( " role " , " system " ) ;
r2 . put ( " content " , " 全部数据以JSON模版的形式返回, 格式为:{position_name:岗位信息, [{qno:问题序号,q:问题,a:参考答案}]} " ) ;
Map < String , Object > r3 = new HashMap < String , Object > ( ) ;
r3 . put ( " role " , " user " ) ;
r3 . put ( " content " , " { \" positionName \" : \" java开发 \" } " ) ;
data . put ( " messages " , Lists . newArrayList ( r1 , r2 , r3 ) ) ;
HttpEntity requestEntity = new HttpEntity ( data , header ) ;
ResponseEntity < String > response = HttpUtils . restTemplate . exchange ( " https://spark-api-open.xf-yun.com/v1/chat/completions " , HttpMethod . POST , requestEntity , String . class ) ;
System . o ut. println ( JsonUtils . toDefaultJsonString ( response ) ) ;
}
@Test
public void testAlita ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的HR。目标任务: 请根据我给出的信息生成5个相关的面试中可能会问到的问题,并为每个问题都生成一个参考答案, 并从1开始生成问题序号 " )
. build ( ) )
. m essage ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 全部数据以JSON模版的形式返回, 格式为:[{qno:问题序号,q:问题,a:参考答案}] " ) . build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " jobName " ) . build ( ) ) . build ( ) ;
AlitaResult < ? > res = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , res ) ;
}
@Test
public void testEvaluate ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历撰写专家。目标任务:请根据我给出的信息,生成指定的内容。需求说明:要求在与原文语意一致的基础上扩写内容,风格设定,简明扼要。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 根据我输入的信息, 输出1段自我评价, 包含学习能力、工作态度、团队协作等方面, 字数在300字左右 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 全部数据以JSON模版的形式返回, 格式为:{'selfEva': xxx} " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " 环卫工 " ) . build ( ) ) . build ( ) ;
AlitaResult < ? > r es = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , res ) ;
}
@Test
public void testWorkExperience ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历撰写专家。目标任务:请根据我给出的信息,生成一份履历丰富的简历。 " )
. build ( ) )
. message ( M essageDTO . builder ( ) . role ( " system " )
. content ( " 简历内容包含个人信息简介、工作经历、教育背景、掌握技能、自我评价。以JSON格式返回, 每个点作为一个对象。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 个人信息输出格式为:{姓名: xxx, 年龄: xxx, 联系电话: xxx, 联系邮箱: xxx} " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 工作经历以数组的形式返回。输出格式为:[{企业名称: xxx, 岗位: xxx, 工作职责: [xxx,xxx,xxx],工作时间:xxx-xxx}] " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 掌握技能必须作为数组输出 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 自我评价必须作为数组输出 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " )
/ / . content ( " { \" name \" : \" 小明 \" , \" gender \" :1, \" contactWay \" : \" 0717-123123 \" , \" birthDay \" : \" 1980-07 \" , \" work \" : \" 在一家科技公司干了4年 \ "} " )
. content ( " 我是小明, 在一家科技公司干了4年 " )
. build ( ) ) . build ( ) ;
AlitaResult < String > r esult = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , result ) ;
}
@Test
public void testAnalyseResume ( ) {
ChatReq req = ChatReq . builder ( )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 你是一位专业的简历分析专家。目标任务: 请根据我给出的信息, 分析得出简历信息。不要自己填充json信息 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " system " )
. content ( " 请生成一个包含以下信息的 JSON 数据,根据用户给出的实际信息解析,值都可为空: \ n "
+ " - name( 字符串类型) : 表示用户的姓名。 \ n "
+ " - sex( 字符串类型) : 表示用户的性别, 值为 \" 1 \" (男)或 \" 2 \" (女),身份证号倒数第二位,奇数是男,偶数是女。 \ n "
+ " - phone( 字符串类型) : 表示用户的联系电话, 可为空, 不为空的格式为 以 1 开头,共 11 位数字。 \ n "
+ " - email( 字符串类型) : 表示用户的联系电子邮箱地址, 可为空, 不为空的格式为 包含 @ 符号,且 @ 前后至少有一个字符 及 域名部分至少包含一个 . 符号。 \ n "
+ " - intentionPosition( 字符串类型) : 表示用户的意向职位。 \ n "
+ " - major( 字符串类型) : 表示用户的专业。 \ n "
+ " - birthday( 日期类型) : 表示用户的出生日期, 格式为 YYYY-MM。 \ n "
+ " - jobTime( 日期类型) : 表示用户的参加工作时间, 格式为 YYYY-MM。 \ n "
+ " - school( 字符串类型) : 表示用户的毕业院校。 \ n "
+ " - education( 字符串类型) : 表示用户的学历, 值为 : \ n "
+ " - \" 1 \" : \" 博士 \" \ n "
+ " - \" 2 \" : \" 硕士 \" \ n "
+ " - \" 3 \" : \" 本科 \" \ n "
+ " - \" 4 \" : \" 大专 \" \ n "
+ " - \" 5 \" : \" 中专 \" \ n "
+ " - \" 6 \" : \" 技校 \" \ n "
+ " - \" 7 \" : \" 职高 \" \ n "
+ " - \" 9 \" : \" 高中 \" \ n "
+ " - \" 10 \" : \" 初中 \" \ n "
+ " - \" 11 \" : \" 小学 \" \ n "
+ " - workExperience( 字符串类型) : 表示用户的工作经历, 格式为多行文本, 包含以下信息: \ n "
+ " - 企业名称 \ n "
+ " - 岗位 \ n "
+ " - 工作时间 \ n "
+ " - 工作职责 \ n "
+ " - selfEvaluation( 字符串类型) : 表示用户的自我评价, 格式为多行文本。 " )
. build ( ) )
. message ( MessageDTO . builder ( ) . role ( " user " ) . content ( " 我是小明, 身份证号是110105199003071234, 小学毕业, 前年在一家科技公司干了1年, 现在想找个环卫工的活, 请用abc@33.com联系我 " ) . build ( ) ) . build ( ) ;
AlitaResult < String > result = XfSparkProvider . httpChat ( req , httpAPIPassword ) ;
log . info ( " {} " , result ) ;
}
@Test
public void iat ( ) throws IOException {
String file = " src/main/resources/iat/cn.pcm " ;
try ( InputStream is = new FileInputStream ( f ile ) ) {
AlitaResult < String > result = WebIATWS . execute ( is , xfProperties ) ;
log . info ( " {} " , result ) ;
}
/ / / / 示例的WebM文件路径 ( 请替换为实际的有效路径 )
String webmFilePath = " src/main/resources/iat/audio.webm " ;
/ / / / 示例的输出MP3文件路径 ( 请替换为实际的有效路径 )
/ / String mp3FilePath = " src/main/resources/iat/file.mp3 " ;
/ / try ( InputStream is = FileUtils . convertWebmToMp3 ( new File ( webmFilePath ) ) ) {
/ / AlitaResult < String > result = WebIATWS . execute ( is , xfProperties ) ;
/ / log . info ( " {} " , result ) ;
/ / }
}
@Test
public void tts ( ) throws Exception {
/ / try ( OutputStream outputStream = new FileOutputStream ( " src/main/resources/iat/223.mp3 " ) ; ) {
/ / WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
/ / }
/ / try ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ;
/ / OutputStream fs = new FileOutputStream ( " src/main/resources/iat/323.mp3 " ) ; ) {
/ / WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
/ / fs . write ( outputStream . toByteArray ( ) ) ;
/ / }
try ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ;
OutputStream fs = new FileOutputStream ( " src/main/resources/iat/3 23.mp3 " ) ; ) {
AlitaResult < Void > result = WebTtsWS . execute ( " 欢迎来到讯飞开放平台 " , xfProperties , outputStream ) ;
Assert . isTrue ( result . getSuccess ( ) , result . getMsg ( ) ) ;
fs . write ( outputStream . toByteArray ( ) ) ;
} catch ( IOException e ) {
throw new BusinessException ( " 语音合成异常: " + e . getMessage ( ) ) ;
}
}
@Test
public void ots ( ) {
/ / AlitaResult < ? > result = XfSparkProvider . translate ( TranslateReq . builder ( ) . text ( " 欢迎#你啊,.;@#$你好 " ) . build ( ) , xfProperties ) ;
AlitaResult < ? > result = XfSparkProvid er . translate ( TranslateReq . builder ( ) . text ( " تىيانەي ئەقىللىق خىزمەت مۇلازىمىتى بىرلەشمە سۇپىسىغا خوش ھەمرىيىڭىز. " ) . from ( " uy " ) . to ( " cn " ) . build ( ) , xfProperties ) ;
log . info ( " {} " , result ) ;
}
@Test
public void rtasr ( ) throws IOException {
String file = " src/main/resources/iat/ug.pcm " ;
try ( InputStream is = new FileInputStream ( file ) ) {
AlitaResult < String > result = RtasrClientApp . execute ( is , " cn_uyghur " , xfProperties ) ;
log . info ( " {} " , result ) ;
}
}
@Test
public void chat ( ) {
ChatReq req = ChatReq . builder ( ) . message ( MessageDTO . builder ( ) . role ( " system " ) . content (
" 你是一位专业的简历分析专家。目标任务: 请根据我给出的信息, 分析得出简历信息。不要自己填充json信息 " )
. role ( " user " ) . content ( " 我是大学生 " )
. build ( ) ) . build ( ) ;
AlitaResult < String > result = XfSparkProvider . httpChat ( req , xfProperties . getHttpAPIPassword ( ) ) ;
Assert . isTrue ( result . getSuccess ( ) , result . getMsg ( ) ) ;
log . info ( " {} " , result ) ;
}
}