1
This commit is contained in:
@@ -268,7 +268,7 @@
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Network Streaming (GET)
|
||||
#pragma mark - Network Streaming (POST)
|
||||
|
||||
// 后端测试地址(内网)。若被 ATS 拦截,请在扩展 target 的 Info.plist 中允许 HTTP 或添加例外域。
|
||||
//static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk";
|
||||
@@ -278,23 +278,42 @@
|
||||
if (![[KBFullAccessManager shared] hasFullAccess]) { return; }
|
||||
|
||||
NSString *apiUrl = [NSString stringWithFormat:@"%@%@", KB_BASE_URL, API_AI_TALK];
|
||||
// 将选中的标签文案作为 seed 透传给后端(通过 query 参数)
|
||||
if (seedTitle.length > 0) {
|
||||
NSString *encodedSeed = [seedTitle stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @"";
|
||||
if (encodedSeed.length > 0) {
|
||||
if ([apiUrl containsString:@"?"]) {
|
||||
apiUrl = [apiUrl stringByAppendingFormat:@"&userInput=%@", encodedSeed];
|
||||
} else {
|
||||
apiUrl = [apiUrl stringByAppendingFormat:@"?userInput=%@", encodedSeed];
|
||||
}
|
||||
}
|
||||
}
|
||||
NSURL *url = [NSURL URLWithString:apiUrl];
|
||||
if (!url) { return; }
|
||||
|
||||
// 组装 POST Body
|
||||
NSInteger characterId = 0;
|
||||
if (self.loadingTagIndex != nil) {
|
||||
NSInteger idx = self.loadingTagIndex.integerValue;
|
||||
if (idx >= 0 && idx < self.modelArray.count) {
|
||||
KBTagItemModel *model = self.modelArray[idx];
|
||||
characterId = model.characterId;
|
||||
}
|
||||
}
|
||||
NSString *message = seedTitle.length > 0 ? seedTitle : @"";
|
||||
NSInteger resolvedCharacterId = (characterId > 0) ? characterId : 75;
|
||||
NSDictionary *payload = @{
|
||||
@"characterId": @(resolvedCharacterId),
|
||||
@"message": message.length > 0 ? message : @"aliqua non cupidatat"
|
||||
};
|
||||
NSError *bodyError = nil;
|
||||
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&bodyError];
|
||||
if (bodyError || bodyData.length == 0) {
|
||||
NSLog(@"[KBFunction] build body failed: %@", bodyError);
|
||||
return;
|
||||
}
|
||||
|
||||
self.streamHasOutput = NO; // 重置首段处理标记
|
||||
__weak typeof(self) weakSelf = self;
|
||||
KBStreamFetcher *fetcher = [KBStreamFetcher fetcherWithURL:url];
|
||||
fetcher.httpMethod = @"POST";
|
||||
fetcher.httpBody = bodyData;
|
||||
NSMutableDictionary *headers = [@{ @"Content-Type": @"application/json" } mutableCopy];
|
||||
NSString *token = KBAuthManager.shared.current.accessToken ?: @"";
|
||||
if (token.length > 0) {
|
||||
headers[@"auth-token"] = token;
|
||||
}
|
||||
fetcher.extraHeaders = headers;
|
||||
// 由本类统一做 /t->\t 与首段去 \t,fetcher 只负责增量与协议解析
|
||||
fetcher.disableCompression = YES;
|
||||
fetcher.acceptEventStream = NO; // 响应头若是 SSE 仍会自动解析
|
||||
|
||||
Reference in New Issue
Block a user