2
This commit is contained in:
@@ -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];
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user