AI 요약
텍스트에서 간결한 요약을 생성하고, 선택한 서비스 제공자가 순차적으로 결과를 반환할 때마다 UI를 갱신합니다.
사전 요구 사항
AIBudsAISDK가 초기화되어 있고 등록된 서비스 제공자를 선택해야 합니다.- 서비스 제공자가
AISummaryServiceAPI를 지원해야 합니다. - 필요한 경우 서비스 제공자 인증과 네트워크 연결을 사용할 수 있어야 합니다.
- 입력 텍스트가 비어 있지 않아야 합니다.
AI를 활용해 구현
AI로 구현
AI로 이 워크플로 구현
공식 “AIBuds AI 요약 구현” 스킬을 사용해 앱에 맞게 구현하세요.
https://docs-aibuds.github.io/ko/skills/implement-aibuds-ai-summary을 읽고 지침을 따르세요. 이 스킬로 “AIBuds AI 요약 구현”을 이 iOS 프로젝트에 구현하고 검증하세요.API Reference
프레임워크
AIBudsAI.xcframework
가져오기
- Swift
- Objective-C
import AIBudsAI#import <AIBudsAI/AIBudsAI-Swift.h>선언
- Swift
- Objective-C
/// Generates a concise summary for the provided text.
/// - Parameters:
/// - text: The text to summarize.
/// - streamResultHandler: Called repeatedly with the current summary.
/// - isFinal: `true` when the summary is complete; otherwise `false`.
/// - transcript: The current incremental summary text.
/// - error: The operation error, or `nil` when no error occurred.
public static func summary(withText text: String,
streamResultHandler: ((_ isFinal: Bool, _ transcript: String?, _ error: Error?) -> Void)? = nil)
/// Cancels the current summary operation before it completes.
public static func cancelSummary()/// Generates a concise summary for the provided text.
/// - Parameters:
/// - text: The text to summarize.
/// - streamResultHandler: Called repeatedly with the current summary.
/// - isFinal: `YES` when the summary is complete; otherwise `NO`.
/// - transcript: The current incremental summary text.
/// - error: The operation error, or `nil` when no error occurred.
+ (void)summaryWithText:(NSString * _Nonnull)text
streamResultHandler:(void (^ _Nullable)(BOOL, NSString * _Nullable, NSError * _Nullable))streamResultHandler;
/// Cancels the current summary operation before it completes.
+ (void)cancelSummary;summary 및 cancelSummary를 참고하세요.
사용 예제
- Swift
- Objective-C
let sourceText = """
The AIBuds SDK connects supported devices to an iOS application and exposes
device control, media, AI, voice assistant, and diagnostic capabilities.
"""
AIBudsAISDK.summary(withText: sourceText) { isFinal, transcript, error in
DispatchQueue.main.async {
if let error {
summaryLabel.text = "Summary failed: \(error.localizedDescription)"
return
}
if let transcript {
summaryLabel.text = transcript
}
if isFinal {
summaryActivityIndicator.stopAnimating()
}
}
}NSString *sourceText = @"The AIBuds SDK connects supported devices to an iOS application and "
"exposes device control, media, AI, voice assistant, and diagnostic "
"capabilities.";
[AIBudsAISDK summaryWithText:sourceText
streamResultHandler:^(BOOL isFinal, NSString *transcript, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil) {
self.summaryLabel.text = [NSString
stringWithFormat:@"Summary failed: %@", error.localizedDescription];
return;
}
if (transcript != nil) {
self.summaryLabel.text = transcript;
}
if (isFinal) {
[self.summaryActivityIndicator stopAnimating];
}
});
}];진행 중인 요청의 결과가 더 이상 필요하지 않다면 다음과 같이 취소합니다.
- Swift
- Objective-C
AIBudsAISDK.cancelSummary()[AIBudsAISDK cancelSummary];참고
- 이 API는 텍스트만 요약합니다. 파일 경로를 입력으로 받지 않으며
maxLength매개변수도 제공하지 않습니다. - 서비스 제공자는 점차 완성되는 요약을 반환하므로, 각 transcript로 이전 표시 값을 교체할 수 있습니다.
- 앞서 transcript를 받았더라도 error가
nil이 아니면 실패로 처리하세요. cancelSummary()는 완료 콜백을 제공하지 않습니다. 취소를 요청할 때 앱 상태를 함께 갱신하세요.