feat: Add classifier listing functionality

- Added a new function to list available classifiers.
- Extended the Jina client with `list_classifiers()` method.
- Added unit tests to verify the new functionality.
This commit is contained in:
Mahmoud Emad
2025-03-11 21:38:06 +02:00
parent ad300c068f
commit cf27e7880e
3 changed files with 39 additions and 0 deletions

View File

@@ -55,3 +55,6 @@ classify_result := jina_client.classify(
) or { panic('Error while classifying: ${err}') }
println('Classification result: ${classify_result}')
classifiers := jina_client.list_classifiers() or { panic('Error fetching classifiers: ${err}') }
println('Classifiers: ${classifiers}')

View File

@@ -260,3 +260,32 @@ pub fn (mut j Jina) classify(params ClassifyParams) !ClassificationOutput {
result := json.decode(ClassificationOutput, response)!
return result
}
// Define the Classifier struct
pub struct Classifier {
pub mut:
classifier_id string
model_name string
labels []string
access string
updated_number int
used_number int
created_at string
updated_at string
used_at ?string
metadata map[string]string
}
// Implement the list_classifiers function
pub fn (mut j Jina) list_classifiers() ![]Classifier {
req := httpconnection.Request{
method: .get
prefix: 'v1/classifiers'
}
mut httpclient := j.httpclient()!
response := httpclient.get(req)!
println('response: ${response}')
classifiers := json.decode([]Classifier, response)!
return classifiers
}

View File

@@ -78,3 +78,10 @@ fn test_classify() {
assert classify_result.data[0].object == 'classification'
assert classify_result.data[1].object == 'classification'
}
fn test_get_classifiers() {
time.sleep(1 * time.second)
mut client := setup_client()!
classifiers := client.list_classifiers() or { panic('Error fetching classifiers: ${err}') }
assert classifiers.len != 0
}