Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb212905

Browse files
authored
Merge pull request#303 from muverystrong/feat/jf-endpoint
feat: support batch cost
2 parentsb02e297 +38b1b1c commitb212905

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

‎api/server/src/main/java/com/ke/bella/openapi/protocol/asr/diarization/SpeakerDiarizationLogHandler.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
importcom.ke.bella.openapi.EndpointProcessData;
44
importcom.ke.bella.openapi.protocol.asr.diarization.SpeakerDiarizationResponse;
5+
importcom.ke.bella.openapi.protocol.embedding.EmbeddingResponse;
56
importcom.ke.bella.openapi.protocol.log.EndpointLogHandler;
67
importcom.ke.bella.openapi.utils.DateTimeUtils;
8+
importcom.ke.bella.openapi.utils.JacksonUtils;
9+
importorg.apache.commons.lang3.StringUtils;
710
importorg.springframework.stereotype.Component;
811

912
importjava.util.HashMap;
@@ -16,9 +19,15 @@ public class SpeakerDiarizationLogHandler implements EndpointLogHandler {
1619
publicvoidprocess(EndpointProcessDataprocessData) {
1720
// 基于音频时长计费(秒)
1821
SpeakerDiarizationUsageusage =newSpeakerDiarizationUsage();
19-
20-
if(processData.getResponse()instanceofSpeakerDiarizationResponse &&processData.getResponse().getError() ==null) {
21-
SpeakerDiarizationResponseresponse = (SpeakerDiarizationResponse)processData.getResponse();
22+
SpeakerDiarizationResponseresponse =null;
23+
if(processData.getResponse()instanceofSpeakerDiarizationResponse) {
24+
response = (SpeakerDiarizationResponse)processData.getResponse();
25+
}
26+
if(StringUtils.isNotBlank(processData.getResponseRaw()) &&response ==null) {
27+
response =JacksonUtils.deserialize(processData.getResponseRaw(),SpeakerDiarizationResponse.class);
28+
}
29+
30+
if(response !=null &&processData.getResponse().getError() ==null) {
2231
// 音频时长(秒)
2332
intaudioDurationSeconds = (int)Math.ceil(response.getDuration());
2433
intspeakerCount =response.getNumSpeakers();
@@ -73,4 +82,4 @@ public void setSpeakerCount(int speakerCount) {
7382
this.speakerCount =speakerCount;
7483
}
7584
}
76-
}
85+
}

‎api/server/src/main/java/com/ke/bella/openapi/protocol/embedding/EmbeddingLogHandler.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
importcom.ke.bella.openapi.EndpointProcessData;
44
importcom.ke.bella.openapi.RequestMetrics;
55
importcom.ke.bella.openapi.protocol.OpenapiResponse;
6+
importcom.ke.bella.openapi.protocol.completion.CompletionRequest;
7+
importcom.ke.bella.openapi.protocol.completion.CompletionResponse;
68
importcom.ke.bella.openapi.protocol.log.EndpointLogHandler;
79
importcom.ke.bella.openapi.utils.DateTimeUtils;
10+
importcom.ke.bella.openapi.utils.JacksonUtils;
811
importcom.ke.bella.openapi.utils.TokenCalculationUtils;
912
importcom.knuddels.jtokkit.api.EncodingType;
1013
importlombok.extern.slf4j.Slf4j;
14+
importorg.apache.commons.lang3.StringUtils;
1115
importorg.springframework.stereotype.Component;
1216

1317
importjava.util.HashMap;
@@ -24,7 +28,13 @@ public void process(EndpointProcessData processData) {
2428
if(processData.getResponse()instanceofEmbeddingResponse) {
2529
response = (EmbeddingResponse)processData.getResponse();
2630
}
27-
31+
if(StringUtils.isNotBlank(processData.getResponseRaw()) &&response ==null) {
32+
response =JacksonUtils.deserialize(processData.getResponseRaw(),EmbeddingResponse.class);
33+
}
34+
if(StringUtils.isNotBlank(processData.getRequestRaw())) {
35+
EmbeddingRequestrequest =JacksonUtils.deserialize(processData.getRequestRaw(),EmbeddingRequest.class);
36+
processData.setRequest(request);
37+
}
2838
// 获取usage - 优先使用预计算的值
2939
EmbeddingResponse.TokenUsageusage =getTokenUsage(processData,response,encodingType);
3040

‎api/server/src/main/java/com/ke/bella/openapi/protocol/speaker/SpeakerEmbeddingLogHandler.java‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,36 @@
44
importcom.ke.bella.openapi.protocol.OpenapiResponse;
55
importcom.ke.bella.openapi.protocol.log.EndpointLogHandler;
66
importcom.ke.bella.openapi.utils.DateTimeUtils;
7+
importcom.ke.bella.openapi.utils.JacksonUtils;
8+
importorg.apache.commons.lang3.StringUtils;
79
importorg.springframework.stereotype.Component;
810

911
importjava.util.HashMap;
1012
importjava.util.Map;
1113

1214
@Component
1315
publicclassSpeakerEmbeddingLogHandlerimplementsEndpointLogHandler {
14-
16+
1517
@Override
1618
publicvoidprocess(EndpointProcessDataprocessData) {
1719
// Create usage object for speaker embeddings - 基于音频时长
1820
SpeakerEmbeddingUsageusage =newSpeakerEmbeddingUsage();
19-
20-
if(processData.getResponse()instanceofSpeakerEmbeddingResponse &&processData.getResponse().getError() ==null) {
21-
SpeakerEmbeddingResponseresponse = (SpeakerEmbeddingResponse)processData.getResponse();
21+
22+
SpeakerEmbeddingResponseresponse =null;
23+
if(processData.getResponse()instanceofSpeakerEmbeddingResponse) {
24+
response = (SpeakerEmbeddingResponse)processData.getResponse();
25+
}
26+
if(StringUtils.isNotBlank(processData.getResponseRaw()) &&response ==null) {
27+
response =JacksonUtils.deserialize(processData.getResponseRaw(),SpeakerEmbeddingResponse.class);
28+
}
29+
30+
if(response !=null &&processData.getResponse().getError() ==null) {
2231
intdurationUnits =calculateDurationUnits(response);
2332
usage.setDurationUnits(durationUnits);
2433
}else {
2534
usage.setDurationUnits(0);
2635
}
27-
36+
2837
longstartTime =processData.getRequestTime();
2938
intttlt = (int) (DateTimeUtils.getCurrentSeconds() -startTime);
3039
Map<String,Object>map =newHashMap<>();
@@ -43,28 +52,28 @@ private int calculateDurationUnits(SpeakerEmbeddingResponse response) {
4352
publicStringendpoint() {
4453
return"/v1/audio/speaker/embedding";
4554
}
46-
55+
4756
/**
4857
* Speaker embedding usage统计类
4958
* 专门用于记录音频时长的使用情况
5059
*/
5160
publicstaticclassSpeakerEmbeddingUsage {
5261
/** 音频时长单位(毫秒) */
5362
privateintdurationUnits;
54-
55-
publicintgetDurationUnits() {
56-
returndurationUnits;
63+
64+
publicintgetDurationUnits() {
65+
returndurationUnits;
5766
}
58-
59-
publicvoidsetDurationUnits(intdurationUnits) {
60-
this.durationUnits =durationUnits;
67+
68+
publicvoidsetDurationUnits(intdurationUnits) {
69+
this.durationUnits =durationUnits;
6170
}
62-
71+
6372
/**
6473
* 获取时长(秒)
6574
*/
6675
publicdoublegetDurationSeconds() {
6776
returndurationUnits /1000.0;
6877
}
6978
}
70-
}
79+
}

‎api/server/src/main/java/com/ke/bella/openapi/protocol/tts/TtsLogHandler.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
importcom.ke.bella.openapi.EndpointProcessData;
44
importcom.ke.bella.openapi.RequestMetrics;
55
importcom.ke.bella.openapi.protocol.OpenapiResponse;
6+
importcom.ke.bella.openapi.protocol.embedding.EmbeddingRequest;
67
importcom.ke.bella.openapi.protocol.tts.TtsRequest;
78
importcom.ke.bella.openapi.protocol.log.EndpointLogHandler;
89
importcom.ke.bella.openapi.utils.DateTimeUtils;
10+
importcom.ke.bella.openapi.utils.JacksonUtils;
911
importlombok.extern.slf4j.Slf4j;
12+
importorg.apache.commons.lang3.StringUtils;
1013
importorg.springframework.stereotype.Component;
1114

1215
importjava.util.HashMap;
@@ -26,6 +29,11 @@ public void process(EndpointProcessData processData) {
2629
processData.setDuration(ttlt);
2730
}
2831

32+
if(StringUtils.isNotBlank(processData.getRequestRaw())) {
33+
TtsRequestrequest =JacksonUtils.deserialize(processData.getRequestRaw(),TtsRequest.class);
34+
processData.setRequest(request);
35+
}
36+
2937
// 获取inputLength - 优先使用预计算的RequestMetrics
3038
intinputLength =getInputLength(processData);
3139
processData.setUsage(inputLength);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp