feat: Add Jina server health check
- Added a health check to the Jina client to verify server availability. - Improved error handling and messaging for failed health checks. - Enhanced client robustness by providing feedback on server status.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import freeflowuniverse.herolib.clients.jina
|
||||
|
||||
mut jina_client := jina.get()!
|
||||
health := jina_client.health()!
|
||||
println('Server health: ${health}')
|
||||
|
||||
// Create embeddings
|
||||
embeddings := jina_client.create_embeddings(
|
||||
|
||||
@@ -210,3 +210,31 @@ pub fn (mut j Jina) create_embeddings(params CreateEmbeddingParams) !ModelEmbedd
|
||||
response := httpclient.post_json_str(req)!
|
||||
return json.decode(ModelEmbeddingOutput, response)!
|
||||
}
|
||||
|
||||
pub struct HealthResponse {
|
||||
pub mut:
|
||||
status string
|
||||
message string
|
||||
healthy bool
|
||||
}
|
||||
|
||||
pub fn (mut j Jina) health() !HealthResponse {
|
||||
req := httpconnection.Request{
|
||||
method: .get
|
||||
}
|
||||
|
||||
mut httpclient := j.httpclient()!
|
||||
response := httpclient.send(req)!
|
||||
if response.code == 200 {
|
||||
return HealthResponse{
|
||||
status: response.code.str()
|
||||
message: '200 Service available'
|
||||
healthy: true
|
||||
}
|
||||
}
|
||||
return HealthResponse{
|
||||
status: response.code.str()
|
||||
message: '${response.code} Service Unavailable'
|
||||
healthy: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ module jina
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
jina_global map[string]&Jina
|
||||
|
||||
Reference in New Issue
Block a user