This commit is contained in:
2026-01-26 20:36:51 +08:00
parent 3a5a6395af
commit e8b4b2c58a
7 changed files with 338 additions and 170 deletions

View File

@@ -81,7 +81,7 @@
[self.view addSubview:self.voiceInputBar];
[self.voiceInputBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.bottom.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-20);
make.height.mas_equalTo(150); //
}];
}
@@ -267,6 +267,27 @@
return persona.personaId;
}
- (KBPersonaChatCell *)currentPersonaCell {
if (self.personas.count == 0) {
return nil;
}
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:self.currentIndex inSection:0];
KBPersonaChatCell *cell = (KBPersonaChatCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
if (cell) {
return cell;
}
for (NSIndexPath *visibleIndex in self.collectionView.indexPathsForVisibleItems) {
KBPersonaChatCell *visibleCell = (KBPersonaChatCell *)[self.collectionView cellForItemAtIndexPath:visibleIndex];
if (visibleCell) {
return visibleCell;
}
}
return nil;
}
#pragma mark - Lazy Load
- (UICollectionView *)collectionView {
@@ -315,14 +336,43 @@
return;
}
KBPersonaChatCell *currentCell = [self currentPersonaCell];
if (currentCell) {
[currentCell appendUserMessage:text];
}
__weak typeof(self) weakSelf = self;
[self.aiVM requestChatMessageWithContent:text
companionId:companionId
completion:^(KBAiMessageResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"[KBAIHomeVC] 请求聊天失败:%@", error.localizedDescription);
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
NSLog(@"[KBAIHomeVC] 聊天请求成功code=%ld", (long)response.code);
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
NSLog(@"[KBAIHomeVC] 请求聊天失败:%@", error.localizedDescription);
return;
}
if (!response || !response.data) {
NSLog(@"[KBAIHomeVC] 聊天响应为空");
return;
}
NSString *aiResponse = response.data.aiResponse ?: response.data.content ?: response.data.text ?: response.data.message ?: @"";
NSString *audioId = response.data.audioId;
if (aiResponse.length == 0) {
NSLog(@"[KBAIHomeVC] AI 回复为空");
return;
}
KBPersonaChatCell *cell = [strongSelf currentPersonaCell];
if (cell) {
[cell appendAssistantMessage:aiResponse audioId:audioId];
}
});
}];
}