This commit is contained in:
2026-01-26 18:51:37 +08:00
parent a22599feda
commit 3a5a6395af
4 changed files with 43 additions and 4 deletions

View File

@@ -248,6 +248,25 @@
[self.voiceToTextManager prepareConnection]; [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 #pragma mark - Lazy Load
- (UICollectionView *)collectionView { - (UICollectionView *)collectionView {
@@ -290,7 +309,21 @@
} }
NSLog(@"[KBAIHomeVC] 语音识别结果:%@", text); 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 - (void)voiceToTextManager:(KBVoiceToTextManager *)manager

View File

@@ -669,6 +669,7 @@
// chat/message // chat/message
[self.aiVM requestChatMessageWithContent:finalText [self.aiVM requestChatMessageWithContent:finalText
companionId:0
completion:^(KBAiMessageResponse *_Nullable response, completion:^(KBAiMessageResponse *_Nullable response,
NSError *_Nullable error) { NSError *_Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf; __strong typeof(weakSelf) strongSelf = weakSelf;

View File

@@ -51,6 +51,7 @@ typedef void (^AiVMAudioURLCompletion)(NSString *_Nullable audioURL,
completion:(AiVMSyncCompletion)completion; completion:(AiVMSyncCompletion)completion;
- (void)requestChatMessageWithContent:(NSString *)content - (void)requestChatMessageWithContent:(NSString *)content
companionId:(NSInteger)companionId
completion:(AiVMMessageCompletion)completion; completion:(AiVMMessageCompletion)completion;
/// 根据 audioId 获取音频 URL /// 根据 audioId 获取音频 URL

View File

@@ -95,6 +95,7 @@ autoShowBusinessError:NO
} }
- (void)requestChatMessageWithContent:(NSString *)content - (void)requestChatMessageWithContent:(NSString *)content
companionId:(NSInteger)companionId
completion:(AiVMMessageCompletion)completion { completion:(AiVMMessageCompletion)completion {
if (content.length == 0) { if (content.length == 0) {
NSError *error = [NSError NSError *error = [NSError
@@ -111,9 +112,12 @@ autoShowBusinessError:NO
[content stringByAddingPercentEncodingWithAllowedCharacters: [content stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet URLQueryAllowedCharacterSet]]; [NSCharacterSet URLQueryAllowedCharacterSet]];
NSString *path = [NSString NSString *path = [NSString
stringWithFormat:@"%@?content=%@", API_AI_CHAT_MESSAGE, stringWithFormat:@"%@?content=%@&companionId=%ld", API_AI_CHAT_MESSAGE,
encodedContent ?: @""]; encodedContent ?: @"", (long)companionId];
NSDictionary *params = @{ @"content" : content ?: @"" }; NSDictionary *params = @{
@"content" : content ?: @"",
@"companionId" : @(companionId)
};
[[KBNetworkManager shared] [[KBNetworkManager shared]
POST:path POST:path
jsonBody:params jsonBody:params