Skip to content

Commit

Permalink
fix: stream service like OpenAI trigger multi Alert issue (#393)
Browse files Browse the repository at this point in the history
* fix: stream service like OpenAI trigger multi Alert issue

* fix: stream validation issue

* perf: improve validation request case

---------

Co-authored-by: tisfeng <[email protected]>
  • Loading branch information
phlpsong and tisfeng authored Feb 9, 2024
1 parent 213f092 commit adee5f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit adee5f7

Please sign in to comment.