Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stream service like OpenAI trigger multi Alert issue #393

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extension ServiceSecretConfigreValidatable {
extension QueryService: ServiceSecretConfigreValidatable {
func validate(completion: @escaping (EZQueryResult, Error?) -> Void) {
resetServiceResult()
translate("hello world!", from: .english, to: .simplifiedChinese, completion: completion)
/**
To reduce output text, save cost, a simple translation example is enough.

1. use zh -> en to avoid analyze English sentence.
2. if Chinese text length > 5, it won't query dict.
*/
translate("曾经沧海难为水", from: .simplifiedChinese, to: .english, completion: completion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct ServiceConfigurationSecretSectionView<Content: View>: View {
}
.alert(viewModel.alertMessage, isPresented: $viewModel.isAlertPresented, actions: {
Button("ok") {
viewModel.isAlertPresented = false
viewModel.reset()
}
})
}
Expand All @@ -70,10 +70,11 @@ struct ServiceConfigurationSecretSectionView<Content: View>: View {
viewModel.isValidating.toggle()
service.validate { _, error in
DispatchQueue.main.async {
guard viewModel.isValidating else { return }
viewModel.isValidating = false
viewModel.alertMessage = error == nil ? "service.configuration.validation_success" : "service.configuration.validation_fail"
print("\(service.serviceType()) validate \(error == nil ? "success" : "fail")!")
viewModel.isValidating.toggle()
viewModel.isAlertPresented.toggle()
viewModel.isAlertPresented = true
}
}
}
Expand Down Expand Up @@ -103,6 +104,12 @@ private class ServiceValidationViewModel: ObservableObject {
}
)
}

func reset() {
isValidating = false
alertMessage = ""
isAlertPresented = false
}
}

@available(macOS 13.0, *)
Expand Down