//
//  TSAIChatVM.swift
//  AIEmoji
//
//  Created by 100Years on 2025/2/9.
//
import Alamofire
class TSAIChatVM {
    
    
    var streamRequest:StreamPostRequest?
    
    var sessionId = "001"

    func sendChatMessage(
        message:String,
        streamHandler:@escaping (String) -> Void,
        completion: @escaping (Any?, Error?) -> Void
    ) {
        // URL 和请求参数
        let url = "http://ai.100yearslater.com/api/text/chat"
        let parameters: [String: String] = [
            "sessionId": sessionId,
            "message": message
        ]
        streamRequest = TSNetworkShared.postStream(urlType: .chat,parameters: parameters) { string in
            streamHandler(string)
        } completion: { result in
            switch result {
            case .success(let data):
                completion(data,nil)
            case .failure(let error):
                completion(nil,error)
            }
        }
    }
    
    func stopAiGenerate () {
        streamRequest?.stopRequest()
    }

}



let kAIErrorString = "Server is busy, please try again later".localized
