AnalyticsView - I call the function try await vm.analyseWeek()
AnswersAnalyticsVM:
private let api = ChatGPTAPI(apiKey: Constants.Keys.chatgpt)
private let gptModel = "gpt-3.5-turbo"
func analyseWeek() async throws {
do {
let weekAnswers = try await collectAllWeekAnswers() // Fetching the data to input ChatGPT
let analysisString = try await api.sendMessage(text: weekAnswers, model: gptModel)
if let userid = await Session.shared.user_id {
// Saving output to DB
} else {
throw CustomError.sessionError
}
} catch let err{
throw err
}
}
App crashes when I call api.sendMessage() with the message "Swift/RangeReplaceableCollection.swift:622: Fatal error: Can't remove first element from an empty collection".
AnalyticsView - I call the function
try await vm.analyseWeek()
AnswersAnalyticsVM:
App crashes when I call api.sendMessage() with the message "Swift/RangeReplaceableCollection.swift:622: Fatal error: Can't remove first element from an empty collection".
XCode crash trickle-down:
private func json``` Body(text: String, model: String, systemText: String, temperature: Double, stream: Bool = true) throws -> Data { let request = Request(model: model, temperature: temperature, messages: generateMessages(from: text, systemText: systemText), stream: stream) // Here return try JSONEncoder().encode(request) }
Why does it happen? I think it's a bug.