1
This commit is contained in:
@@ -248,6 +248,25 @@
|
||||
[self.voiceToTextManager prepareConnection];
|
||||
}
|
||||
|
||||
- (NSInteger)currentCompanionId {
|
||||
if (self.personas.count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSInteger index = self.currentIndex;
|
||||
if (index < 0 || index >= self.personas.count) {
|
||||
NSIndexPath *indexPath = self.collectionView.indexPathsForVisibleItems.firstObject;
|
||||
if (indexPath) {
|
||||
index = indexPath.item;
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
KBPersonaModel *persona = self.personas[index];
|
||||
return persona.personaId;
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (UICollectionView *)collectionView {
|
||||
@@ -290,7 +309,21 @@
|
||||
}
|
||||
NSLog(@"[KBAIHomeVC] 语音识别结果:%@", text);
|
||||
|
||||
// TODO: 使用识别文本(例如发起聊天请求)
|
||||
NSInteger companionId = [self currentCompanionId];
|
||||
if (companionId <= 0) {
|
||||
NSLog(@"[KBAIHomeVC] companionId 无效,取消请求");
|
||||
return;
|
||||
}
|
||||
|
||||
[self.aiVM requestChatMessageWithContent:text
|
||||
companionId:companionId
|
||||
completion:^(KBAiMessageResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"[KBAIHomeVC] 请求聊天失败:%@", error.localizedDescription);
|
||||
return;
|
||||
}
|
||||
NSLog(@"[KBAIHomeVC] 聊天请求成功,code=%ld", (long)response.code);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)voiceToTextManager:(KBVoiceToTextManager *)manager
|
||||
|
||||
@@ -669,6 +669,7 @@
|
||||
|
||||
// 请求 chat/message 接口
|
||||
[self.aiVM requestChatMessageWithContent:finalText
|
||||
companionId:0
|
||||
completion:^(KBAiMessageResponse *_Nullable response,
|
||||
NSError *_Nullable error) {
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
|
||||
@@ -51,6 +51,7 @@ typedef void (^AiVMAudioURLCompletion)(NSString *_Nullable audioURL,
|
||||
completion:(AiVMSyncCompletion)completion;
|
||||
|
||||
- (void)requestChatMessageWithContent:(NSString *)content
|
||||
companionId:(NSInteger)companionId
|
||||
completion:(AiVMMessageCompletion)completion;
|
||||
|
||||
/// 根据 audioId 获取音频 URL
|
||||
|
||||
@@ -95,6 +95,7 @@ autoShowBusinessError:NO
|
||||
}
|
||||
|
||||
- (void)requestChatMessageWithContent:(NSString *)content
|
||||
companionId:(NSInteger)companionId
|
||||
completion:(AiVMMessageCompletion)completion {
|
||||
if (content.length == 0) {
|
||||
NSError *error = [NSError
|
||||
@@ -111,9 +112,12 @@ autoShowBusinessError:NO
|
||||
[content stringByAddingPercentEncodingWithAllowedCharacters:
|
||||
[NSCharacterSet URLQueryAllowedCharacterSet]];
|
||||
NSString *path = [NSString
|
||||
stringWithFormat:@"%@?content=%@", API_AI_CHAT_MESSAGE,
|
||||
encodedContent ?: @""];
|
||||
NSDictionary *params = @{ @"content" : content ?: @"" };
|
||||
stringWithFormat:@"%@?content=%@&companionId=%ld", API_AI_CHAT_MESSAGE,
|
||||
encodedContent ?: @"", (long)companionId];
|
||||
NSDictionary *params = @{
|
||||
@"content" : content ?: @"",
|
||||
@"companionId" : @(companionId)
|
||||
};
|
||||
[[KBNetworkManager shared]
|
||||
POST:path
|
||||
jsonBody:params
|
||||
|
||||
Reference in New Issue
Block a user