├── .gitattributes ├── sbom.yaml ├── lib ├── api_dart_io_import.dart ├── api_web_import.dart ├── src │ ├── http │ │ ├── browser_client.dart │ │ ├── io_client.dart │ │ ├── src │ │ │ ├── client_stub.dart │ │ │ ├── multipart_file_stub.dart │ │ │ ├── exception.dart │ │ │ ├── multipart_file_io.dart │ │ │ ├── streamed_response.dart │ │ │ ├── io_streamed_response.dart │ │ │ ├── boundary_characters.dart │ │ │ ├── byte_stream.dart │ │ │ ├── base_response.dart │ │ │ ├── streamed_request.dart │ │ │ ├── utils.dart │ │ │ ├── response.dart │ │ │ ├── mock_client.dart │ │ │ └── browser_client.dart │ │ └── testing.dart │ ├── openapi │ │ ├── api │ │ │ ├── endpoint_api.dart │ │ │ ├── endpoint_provider_api.dart │ │ │ └── v2provider_api.dart │ │ ├── doc │ │ │ ├── Status.md │ │ │ ├── Accelerator.md │ │ │ ├── MetricName.md │ │ │ ├── EndpointState.md │ │ │ ├── EndpointTask.md │ │ │ ├── EndpointType.md │ │ │ ├── EndpointFramework.md │ │ │ ├── EndpointAccelerator.md │ │ │ ├── ApiResponseError.md │ │ │ ├── Vendors.md │ │ │ ├── VendorList.md │ │ │ ├── EndpointAccount.md │ │ │ ├── RegionList.md │ │ │ ├── EndpointProvider.md │ │ │ ├── ComputeList.md │ │ │ ├── EndpointModelImageOneOf.md │ │ │ ├── EndpointImageCredentials.md │ │ │ ├── EndpointStatusPrivate.md │ │ │ ├── EndpointWithStatusList.md │ │ │ ├── EndpointModelImageOneOf1.md │ │ │ ├── EndpointModelImageUpdateOneOf.md │ │ │ ├── MetricsParams.md │ │ │ ├── EndpointScaling.md │ │ │ ├── Vendor.md │ │ │ ├── EndpointUpdate.md │ │ │ ├── EndpointScalingUpdate.md │ │ │ ├── EndpointModelImage.md │ │ │ ├── EndpointModelImageUpdate.md │ │ │ ├── Region.md │ │ │ ├── EndpointCompute.md │ │ │ ├── EndpointComputeUpdate.md │ │ │ ├── EndpointModel.md │ │ │ ├── EndpointModelImageOneOf1Custom.md │ │ │ ├── EndpointModelUpdate.md │ │ │ ├── EndpointModelImageUpdateOneOfCustom.md │ │ │ ├── Endpoint.md │ │ │ ├── EndpointWithStatus.md │ │ │ ├── EndpointStatus.md │ │ │ ├── Compute.md │ │ │ └── V2providerApi.md │ │ ├── auth │ │ │ ├── authentication.dart │ │ │ ├── oauth.dart │ │ │ ├── http_basic_auth.dart │ │ │ ├── api_key_auth.dart │ │ │ └── http_bearer_auth.dart │ │ ├── api_exception.dart │ │ ├── model │ │ │ ├── status.dart │ │ │ ├── accelerator.dart │ │ │ ├── endpoint_accelerator.dart │ │ │ ├── endpoint_type.dart │ │ │ ├── endpoint_framework.dart │ │ │ ├── vendors.dart │ │ │ ├── vendor_list.dart │ │ │ ├── region_list.dart │ │ │ └── compute_list.dart │ │ └── api.dart │ ├── api │ │ ├── endpoint_api_client.dart │ │ ├── endpoint_provider_api_client.dart │ │ ├── api │ │ │ └── response_transformers.dart │ │ └── model │ │ │ ├── api_response_nlp_sentence_similarity.dart │ │ │ ├── api_response_nlp_feature_extraction.dart │ │ │ └── inference_options.dart │ └── huggingface_client.dart └── huggingface_client.dart ├── example ├── audio │ ├── test │ │ ├── ac.wav │ │ ├── asr.mp3 │ │ ├── textToImage.jpeg │ │ └── asrtext.txt │ ├── inference_asr_api.dart │ └── inference_classification_api.dart ├── vision │ ├── test │ │ ├── flower.jpg │ │ └── predict-dog.png │ ├── inference_object_detection_api.dart │ ├── inference_image_classification_api.dart │ └── inference_image_segmentation_api.dart ├── screenshots │ └── hugging-face.png ├── api_key.dart ├── example.md ├── inference_endpoint_provider_api.dart ├── inference_api.dart ├── nlp │ ├── inference_qa_task_api.dart │ ├── inference_fill_mask_task_api.dart │ ├── inference_sentence_similarity_task_api.dart │ ├── inference_translation_task_api.dart │ ├── inference_text_classification_task_api.dart │ ├── inference_chat_completion_task_api.dart │ ├── inference_token_classification_api.dart │ ├── inference_text_to_image_api.dart │ ├── inference_text_generation_task_api.dart │ ├── inference_conversational_task_api.dart │ ├── inference_table_qa_task_api.dart │ ├── inference_feature_extraction_task_api.dart │ ├── inference_zero_shot_classification_api.dart │ └── inference_summarisation_task_api.dart ├── inference_api_using_endpoint_translation.dart └── inference_api_using_endpoint_conversational.dart ├── CHANGELOG.md ├── .vscode └── launch.json ├── analysis_options.yaml ├── test ├── status_test.dart ├── accelerator_test.dart ├── metric_name_test.dart ├── endpoint_task_test.dart ├── endpoint_type_test.dart ├── endpoint_state_test.dart ├── endpoint_framework_test.dart ├── endpoint_accelerator_test.dart ├── api_response_error_test.dart ├── vendors_test.dart ├── vendor_list_test.dart ├── region_list_test.dart ├── compute_list_test.dart ├── endpoint_model_image_one_of1_test.dart ├── endpoint_with_status_list_test.dart ├── endpoint_model_image_update_one_of_test.dart ├── endpoint_status_private_test.dart ├── endpoint_model_image_one_of_test.dart ├── endpoint_update_test.dart ├── endpoint_account_test.dart ├── v2provider_api_test.dart ├── endpoint_provider_test.dart ├── endpoint_image_credentials_test.dart ├── endpoint_model_image_test.dart ├── endpoint_scaling_test.dart ├── endpoint_scaling_update_test.dart ├── endpoint_model_image_update_test.dart ├── vendor_test.dart ├── metrics_params_test.dart ├── region_test.dart ├── endpoint_compute_test.dart ├── endpoint_compute_update_test.dart ├── endpoint_model_test.dart ├── v1provider_api_test.dart ├── endpoint_model_update_test.dart ├── endpoint_model_image_one_of1_custom_test.dart ├── endpoint_model_image_update_one_of_custom_test.dart ├── endpoint_test.dart ├── endpoint_with_status_test.dart ├── endpoint_status_test.dart ├── v1endpoint_api_test.dart ├── compute_test.dart └── v2endpoint_api_test.dart ├── .gitignore ├── pubspec.yaml ├── .github └── workflows │ ├── ci.yml │ └── pana.yml ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | coverage/* linguist-vendored -------------------------------------------------------------------------------- /sbom.yaml: -------------------------------------------------------------------------------- 1 | type: spdx 2 | 3 | spdx: 4 | SPDXFormat: 'tagvalue' -------------------------------------------------------------------------------- /lib/api_dart_io_import.dart: -------------------------------------------------------------------------------- 1 | // Conditional export for build runner. 2 | export 'dart:io' show HttpStatus; 3 | -------------------------------------------------------------------------------- /example/audio/test/ac.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/audio/test/ac.wav -------------------------------------------------------------------------------- /example/audio/test/asr.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/audio/test/asr.mp3 -------------------------------------------------------------------------------- /lib/api_web_import.dart: -------------------------------------------------------------------------------- 1 | // Conditional export for build runner. 2 | export 'package:web/web.dart' show HttpStatus; 3 | -------------------------------------------------------------------------------- /example/vision/test/flower.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/vision/test/flower.jpg -------------------------------------------------------------------------------- /example/audio/test/textToImage.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/audio/test/textToImage.jpeg -------------------------------------------------------------------------------- /example/screenshots/hugging-face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/screenshots/hugging-face.png -------------------------------------------------------------------------------- /example/vision/test/predict-dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shamblett/huggingface_client/HEAD/example/vision/test/predict-dog.png -------------------------------------------------------------------------------- /example/audio/test/asrtext.txt: -------------------------------------------------------------------------------- 1 | 2 | “My dear Fanny, you feel these things a great deal too much. I am most happy that you like the chain, 3 | -------------------------------------------------------------------------------- /lib/src/http/browser_client.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | export 'src/browser_client.dart' show BrowserClient; 6 | -------------------------------------------------------------------------------- /example/api_key.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | /// Your Hugging Face API key 9 | const inferenceApiKey = 'hf_xxxxxxxxxxxxxxxxx...'; 10 | const endpointApiKey = 'hf_xxxxxxxxxxxxxxxxx...'; 11 | -------------------------------------------------------------------------------- /lib/src/http/io_client.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | export 'src/io_client.dart' show IOClient; 6 | export 'src/io_streamed_response.dart' show IOStreamedResponse; 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.6.2 2 | PR 28 3 | 4 | # 1.6.1 5 | Issue 26 6 | 7 | # 1.6.0 8 | Issue 22 9 | 10 | # 1.5.0 11 | Issue 15 12 | 13 | # 1.4.0 14 | Issue 17 15 | 16 | # 1.3.0 17 | Issue 11 18 | 19 | # 1.2.3 20 | Issue 10 21 | 22 | # 1.2.2 23 | Issue 6 24 | 25 | # 1.2.1 26 | Issue 5 27 | 28 | # 1.2.0 29 | Inference and provider endpoints 30 | 31 | # 1.1.0 32 | Audio and Vision inference 33 | 34 | # 1.0.0 35 | Initial release 36 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "huggingface_client", 9 | "request": "launch", 10 | "type": "dart" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /lib/src/openapi/api/endpoint_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | /// 11 | /// The inference endpoint API 12 | /// 13 | class EndpointApi extends V2endpointApi { 14 | EndpointApi(EndpointApiClient? apiClient) : super(apiClient); 15 | } 16 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file allows you to configure the Dart analyzer. 2 | # 3 | # The commented part below is just for inspiration. Read the guide here: 4 | # https://www.dartlang.org/guides/language/analysis-options 5 | 6 | include: package:lints/recommended.yaml 7 | 8 | analyzer: 9 | exclude: 10 | - test/issues/** 11 | 12 | linter: 13 | rules: 14 | - use_string_in_part_of_directives: false 15 | - unnecessary_library_name: false 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/api/endpoint_provider_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | /// 11 | /// The inference endpoint provider API 12 | /// 13 | class EndpointProviderApi extends V2providerApi { 14 | EndpointProviderApi(EndpointProviderApiClient? super.apiClient); 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Status.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Status 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/http/src/client_stub.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'base_client.dart'; 6 | 7 | /// Implemented in `browser_client.dart` and `io_client.dart`. 8 | BaseClient createClient() => throw UnsupportedError( 9 | 'Cannot create a client without package:web or dart:io.'); 10 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Accelerator.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Accelerator 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/MetricName.md: -------------------------------------------------------------------------------- 1 | # openapi.model.MetricName 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointState.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointState 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointTask.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointTask 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointType.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointType 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/status_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Status 14 | void main() { 15 | group('test Status', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointFramework.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointFramework 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointAccelerator.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointAccelerator 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/accelerator_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Accelerator 14 | void main() { 15 | group('test Accelerator', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /test/metric_name_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for MetricName 14 | void main() { 15 | group('test MetricName', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /test/endpoint_task_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointTask 14 | void main() { 15 | group('test EndpointTask', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /test/endpoint_type_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointType 14 | void main() { 15 | group('test EndpointType', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /test/endpoint_state_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointState 14 | void main() { 15 | group('test EndpointState', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/ApiResponseError.md: -------------------------------------------------------------------------------- 1 | # openapi.model.ApiResponseError 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **error** | **String** | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/endpoint_framework_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointFramework 14 | void main() { 15 | group('test EndpointFramework', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /test/endpoint_accelerator_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointAccelerator 14 | void main() { 15 | group('test EndpointAccelerator', () {}); 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Vendors.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Vendors 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **vendors** | [**List**](Vendor.md) | Vendors list | [default to const []] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/VendorList.md: -------------------------------------------------------------------------------- 1 | # openapi.model.VendorList 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **items** | [**List**](Vendor.md) | Vendors list | [default to const []] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointAccount.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointAccount 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **id** | **String** | Account id | 12 | **name** | **String** | Account name | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/RegionList.md: -------------------------------------------------------------------------------- 1 | # openapi.model.RegionList 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **items** | [**List**](Region.md) | Vendor regions list | [default to const []] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointProvider.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointProvider 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **region** | **String** | Provider region | 12 | **vendor** | **String** | Provider vendor | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/ComputeList.md: -------------------------------------------------------------------------------- 1 | # openapi.model.ComputeList 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **items** | [**List**](Compute.md) | Vendor region compute resources list | [default to const []] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageOneOf.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageOneOf 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **huggingface** | [**Object**](.md) | Model served by an Hugging Face container | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/http/src/multipart_file_stub.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'package:http_parser/http_parser.dart'; 6 | 7 | import 'multipart_file.dart'; 8 | 9 | Future multipartFileFromPath(String field, String filePath, 10 | {String? filename, MediaType? contentType}) => 11 | throw UnsupportedError( 12 | 'MultipartFile is only supported where dart:io is available.'); 13 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointImageCredentials.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointImageCredentials 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **password** | **String** | | 12 | **username** | **String** | Registry username | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointStatusPrivate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointStatusPrivate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **serviceName** | **String** | VPC service name used to add the private link | [optional] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointWithStatusList.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointWithStatusList 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **items** | [**List**](EndpointWithStatus.md) | | [default to const []] 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageOneOf1.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageOneOf1 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **custom** | [**EndpointModelImageOneOf1Custom**](EndpointModelImageOneOf1Custom.md) | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /example/example.md: -------------------------------------------------------------------------------- 1 | 2 | This directory contains working examples of the Hugging Face inference API, inference endpoint and provider API. 3 | 4 | The examples are grouped into Natural Language Processing, Audio and Video inference task examples 5 | inference endpoint and provider examples. 6 | 7 | The inference_api_using_endpoint_conversational.dart and inference_api_using_endpoint_translation.dart files show 8 | how to use your own inference endpoint for inference tasks. 9 | 10 | To run the examples either edit them to use your own Hugging Face API key or edit the api_key file with the API 11 | keys as needed. 12 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageUpdateOneOf.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageUpdateOneOf 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **custom** | [**EndpointModelImageUpdateOneOfCustom**](EndpointModelImageUpdateOneOfCustom.md) | | 12 | 13 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 14 | 15 | 16 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/MetricsParams.md: -------------------------------------------------------------------------------- 1 | # openapi.model.MetricsParams 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **dnsPrefix** | **String** | | 12 | **from** | **int** | | 13 | **step** | **String** | | [optional] 14 | **to** | **int** | | 15 | 16 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointScaling.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointScaling 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **maxReplica** | **int** | Maximum number of endpoint replica | 12 | **minReplica** | **int** | Minimum number of endpoint replica | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/auth/authentication.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | // ignore: one_member_abstracts 13 | abstract class Authentication { 14 | /// Apply authentication settings to header and query params. 15 | Future applyToParams( 16 | List queryParams, Map headerParams); 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Vendor.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Vendor 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **name** | **String** | | 12 | **regions** | [**List**](Region.md) | Vendor regions list | [default to const []] 13 | **status** | [**Status**](Status.md) | | 14 | 15 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 16 | 17 | 18 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointUpdate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointUpdate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **compute** | [**EndpointComputeUpdate**](EndpointComputeUpdate.md) | | [optional] 12 | **model** | [**EndpointModelUpdate**](EndpointModelUpdate.md) | | [optional] 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointScalingUpdate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointScalingUpdate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **maxReplica** | **int** | Maximum number of endpoint replica | [optional] 12 | **minReplica** | **int** | Minimum number of endpoint replica | [optional] 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImage.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImage 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **huggingface** | [**Object**](.md) | Model served by an Hugging Face container | 12 | **custom** | [**EndpointModelImageOneOf1Custom**](EndpointModelImageOneOf1Custom.md) | | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageUpdate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageUpdate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **huggingface** | [**Object**](.md) | Model served by an Hugging Face container | 12 | **custom** | [**EndpointModelImageUpdateOneOfCustom**](EndpointModelImageUpdateOneOfCustom.md) | | 13 | 14 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/api_response_error_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for ApiResponseError 14 | void main() { 15 | // final instance = ApiResponseError(); 16 | 17 | group('test ApiResponseError', () { 18 | // String error 19 | test('to test the property `error`', () async { 20 | // TODO 21 | }); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Region.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Region 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **computes** | [**List**](Compute.md) | Vendor region compute resources list | [default to const []] 12 | **label** | **String** | | 13 | **name** | **String** | Region name | 14 | **status** | [**Status**](Status.md) | | 15 | 16 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/src/api/endpoint_api_client.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | /// 11 | /// The Inference endpoint API client just extends the Open API client 12 | /// 13 | class EndpointApiClient extends ApiClient { 14 | EndpointApiClient( 15 | {String basePath = 'http://localhost', 16 | Authentication? authentication, 17 | required String endpointScope}) 18 | : super( 19 | basePath: basePath, 20 | authentication: authentication, 21 | endpointScope: endpointScope); 22 | } 23 | -------------------------------------------------------------------------------- /test/vendors_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Vendors 14 | void main() { 15 | // final instance = Vendors(); 16 | 17 | group('test Vendors', () { 18 | // Vendors list 19 | // List vendors (default value: const []) 20 | test('to test the property `vendors`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/vendor_list_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for VendorList 14 | void main() { 15 | // final instance = VendorList(); 16 | 17 | group('test VendorList', () { 18 | // Vendors list 19 | // List items (default value: const []) 20 | test('to test the property `items`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/region_list_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for RegionList 14 | void main() { 15 | // final instance = RegionList(); 16 | 17 | group('test RegionList', () { 18 | // Vendor regions list 19 | // List items (default value: const []) 20 | test('to test the property `items`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointCompute.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointCompute 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **accelerator** | [**EndpointAccelerator**](EndpointAccelerator.md) | | 12 | **instanceSize** | **String** | | 13 | **instanceType** | **String** | Compute instance type | 14 | **scaling** | [**EndpointScaling**](EndpointScaling.md) | | 15 | 16 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/src/api/endpoint_provider_api_client.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | /// 11 | /// The Inference endpoint provider API client just extends the Open API client 12 | /// 13 | class EndpointProviderApiClient extends ApiClient { 14 | EndpointProviderApiClient( 15 | {String basePath = 'http://localhost', 16 | Authentication? authentication, 17 | required String endpointScope}) 18 | : super( 19 | basePath: basePath, 20 | authentication: authentication, 21 | endpointScope: endpointScope); 22 | } 23 | -------------------------------------------------------------------------------- /lib/src/http/src/exception.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | /// An exception caused by an error in a pkg/http client. 6 | class ClientException implements Exception { 7 | final String message; 8 | 9 | /// The URL of the HTTP request or response that failed. 10 | final Uri? uri; 11 | 12 | ClientException(this.message, [this.uri]); 13 | 14 | @override 15 | String toString() { 16 | if (uri != null) { 17 | return 'ClientException: $message, uri=$uri'; 18 | } else { 19 | return 'ClientException: $message'; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/compute_list_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for ComputeList 14 | void main() { 15 | // final instance = ComputeList(); 16 | 17 | group('test ComputeList', () { 18 | // Vendor region compute resources list 19 | // List items (default value: const []) 20 | test('to test the property `items`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/endpoint_model_image_one_of1_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageOneOf1 14 | void main() { 15 | // final instance = EndpointModelImageOneOf1(); 16 | 17 | group('test EndpointModelImageOneOf1', () { 18 | // EndpointModelImageOneOf1Custom custom 19 | test('to test the property `custom`', () async { 20 | // TODO 21 | }); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /test/endpoint_with_status_list_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointWithStatusList 14 | void main() { 15 | // final instance = EndpointWithStatusList(); 16 | 17 | group('test EndpointWithStatusList', () { 18 | // List items (default value: const []) 19 | test('to test the property `items`', () async { 20 | // TODO 21 | }); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /lib/src/openapi/auth/oauth.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class OAuth implements Authentication { 13 | OAuth({this.accessToken = ''}); 14 | 15 | String accessToken; 16 | 17 | @override 18 | Future applyToParams( 19 | List queryParams, 20 | Map headerParams, 21 | ) async { 22 | if (accessToken.isNotEmpty) { 23 | headerParams['Authorization'] = 'Bearer $accessToken'; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/endpoint_model_image_update_one_of_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageUpdateOneOf 14 | void main() { 15 | // final instance = EndpointModelImageUpdateOneOf(); 16 | 17 | group('test EndpointModelImageUpdateOneOf', () { 18 | // EndpointModelImageUpdateOneOfCustom custom 19 | test('to test the property `custom`', () async { 20 | // TODO 21 | }); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /test/endpoint_status_private_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointStatusPrivate 14 | void main() { 15 | // final instance = EndpointStatusPrivate(); 16 | 17 | group('test EndpointStatusPrivate', () { 18 | // VPC service name used to add the private link 19 | // String serviceName 20 | test('to test the property `serviceName`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/endpoint_model_image_one_of_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageOneOf 14 | void main() { 15 | // final instance = EndpointModelImageOneOf(); 16 | 17 | group('test EndpointModelImageOneOf', () { 18 | // Model served by an Hugging Face container 19 | // Object huggingface 20 | test('to test the property `huggingface`', () async { 21 | // TODO 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointComputeUpdate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointComputeUpdate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **accelerator** | [**EndpointAccelerator**](EndpointAccelerator.md) | | [optional] 12 | **instanceSize** | **String** | | [optional] 13 | **instanceType** | **String** | Compute instance type | [optional] 14 | **scaling** | [**EndpointScalingUpdate**](EndpointScalingUpdate.md) | | [optional] 15 | 16 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 17 | 18 | 19 | -------------------------------------------------------------------------------- /lib/src/api/api/response_transformers.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 13/10/2024 5 | * Copyright : Huzaif ansari 6 | */ 7 | 8 | import 'dart:async'; 9 | import 'dart:convert'; 10 | 11 | class StreamResponseTransformer 12 | extends StreamTransformerBase, Map> { 13 | const StreamResponseTransformer(); 14 | 15 | @override 16 | Stream> bind(final Stream> stream) { 17 | return stream // 18 | .transform(utf8.decoder) // 19 | .transform(const LineSplitter()) // 20 | .where((final i) => i.startsWith('data: ') && !i.endsWith('[DONE]')) 21 | .map((final item) => item.substring(6)) 22 | .map((js) => json.decode(js)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/endpoint_update_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointUpdate 14 | void main() { 15 | // final instance = EndpointUpdate(); 16 | 17 | group('test EndpointUpdate', () { 18 | // EndpointComputeUpdate compute 19 | test('to test the property `compute`', () async { 20 | // TODO 21 | }); 22 | 23 | // EndpointModelUpdate model 24 | test('to test the property `model`', () async { 25 | // TODO 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /test/endpoint_account_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointAccount 14 | void main() { 15 | // final instance = EndpointAccount(); 16 | 17 | group('test EndpointAccount', () { 18 | // Account id 19 | // String id 20 | test('to test the property `id`', () async { 21 | // TODO 22 | }); 23 | 24 | // Account name 25 | // String name 26 | test('to test the property `name`', () async { 27 | // TODO 28 | }); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /test/v2provider_api_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | /// tests for V2providerApi 14 | void main() { 15 | // final instance = V2providerApi(); 16 | 17 | group('tests for V2providerApi', () { 18 | // List vendors, regions and compute resources available 19 | // 20 | // List vendors, regions and compute resources available 21 | // 22 | //Future listVendors() async 23 | test('test listVendors', () async { 24 | // TODO 25 | }); 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModel.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModel 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **framework** | [**EndpointFramework**](EndpointFramework.md) | | 12 | **image** | [**EndpointModelImage**](EndpointModelImage.md) | | 13 | **repository** | **String** | HuggingFace repository | 14 | **revision** | **String** | Model commit hash, if not set the latest commit will be used | [optional] 15 | **task** | [**EndpointTask**](EndpointTask.md) | | [optional] 16 | 17 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/endpoint_provider_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointProvider 14 | void main() { 15 | // final instance = EndpointProvider(); 16 | 17 | group('test EndpointProvider', () { 18 | // Provider region 19 | // String region 20 | test('to test the property `region`', () async { 21 | // TODO 22 | }); 23 | 24 | // Provider vendor 25 | // String vendor 26 | test('to test the property `vendor`', () async { 27 | // TODO 28 | }); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /test/endpoint_image_credentials_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointImageCredentials 14 | void main() { 15 | // final instance = EndpointImageCredentials(); 16 | 17 | group('test EndpointImageCredentials', () { 18 | // String password 19 | test('to test the property `password`', () async { 20 | // TODO 21 | }); 22 | 23 | // Registry username 24 | // String username 25 | test('to test the property `username`', () async { 26 | // TODO 27 | }); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://www.dartlang.org/guides/libraries/private-files 2 | 3 | # Files and directories created by pub 4 | .dart_tool/ 5 | .packages 6 | build/ 7 | # If you're building an application, you may want to check-in your pubspec.lock 8 | pubspec.lock 9 | 10 | # Directory created by dartdoc 11 | # If you don't generate documentation locally you can remove this line. 12 | doc/api/ 13 | 14 | # dotenv environment variables file 15 | .env* 16 | 17 | # Avoid committing generated Javascript files: 18 | *.dart.js 19 | *.info.json # Produced by the --dump-info flag. 20 | *.js # When generated by dart2js. Don't specify *.js if your 21 | # project includes source files written in JavaScript. 22 | *.js_ 23 | *.js.deps 24 | *.js.map 25 | 26 | .flutter-plugins 27 | .flutter-plugins-dependencies 28 | 29 | # Local 30 | .idea 31 | .vscode 32 | .DS_Store 33 | .directory 34 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: 'huggingface_client' 2 | version: '1.6.2' 3 | description: 'A server and browser based Hugging Face inference and inference endpoint API REST client' 4 | repository: https://github.com/shamblett/huggingface_client 5 | homepage: https://github.com/shamblett/huggingface_client 6 | 7 | funding: 8 | - https://www.darticulate.com/#funding 9 | 10 | environment: 11 | sdk: '>=3.0.0 <4.0.0' 12 | 13 | 14 | dependencies: 15 | async: '^2.12.0' 16 | http_parser: '^4.1.2' 17 | intl: '^0.20.1' 18 | meta: '^1.12.0' 19 | web: '^1.1.0' 20 | 21 | dev_dependencies: 22 | test: '^1.25.14' 23 | lints: '^5.1.1' 24 | build_runner: '^2.4.14' 25 | build_test: '^2.2.3' 26 | build_web_compilers: '^4.1.0' 27 | 28 | topics: 29 | - ai 30 | - data 31 | - llm 32 | - api 33 | 34 | screenshots: 35 | - description: 'Hugging Face' 36 | path: example/screenshots/hugging-face.png 37 | -------------------------------------------------------------------------------- /lib/src/http/src/multipart_file_io.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:io'; 6 | 7 | import 'package:http_parser/http_parser.dart'; 8 | 9 | import 'byte_stream.dart'; 10 | import 'multipart_file.dart'; 11 | 12 | Future multipartFileFromPath(String field, String filePath, 13 | {String? filename, MediaType? contentType}) async { 14 | late var segments = Uri.file(filePath).pathSegments; 15 | filename ??= segments.isEmpty ? '' : segments.last; 16 | var file = File(filePath); 17 | var length = await file.length(); 18 | var stream = ByteStream(file.openRead()); 19 | return MultipartFile(field, stream, length, 20 | filename: filename, contentType: contentType); 21 | } 22 | -------------------------------------------------------------------------------- /test/endpoint_model_image_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImage 14 | void main() { 15 | // final instance = EndpointModelImage(); 16 | 17 | group('test EndpointModelImage', () { 18 | // Model served by an Hugging Face container 19 | // Object huggingface 20 | test('to test the property `huggingface`', () async { 21 | // TODO 22 | }); 23 | 24 | // EndpointModelImageOneOf1Custom custom 25 | test('to test the property `custom`', () async { 26 | // TODO 27 | }); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /test/endpoint_scaling_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointScaling 14 | void main() { 15 | // final instance = EndpointScaling(); 16 | 17 | group('test EndpointScaling', () { 18 | // Maximum number of endpoint replica 19 | // int maxReplica 20 | test('to test the property `maxReplica`', () async { 21 | // TODO 22 | }); 23 | 24 | // Minimum number of endpoint replica 25 | // int minReplica 26 | test('to test the property `minReplica`', () async { 27 | // TODO 28 | }); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageOneOf1Custom.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageOneOf1Custom 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **credentials** | [**EndpointImageCredentials**](EndpointImageCredentials.md) | | [optional] 12 | **env** | **Map** | Container environment variables | [optional] [default to const {}] 13 | **healthRoute** | **String** | Container health route | [optional] 14 | **port** | **int** | Endpoint API port | [optional] [default to 80] 15 | **url** | **String** | URL fo the container | 16 | 17 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 18 | 19 | 20 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelUpdate.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelUpdate 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **framework** | [**EndpointFramework**](EndpointFramework.md) | | [optional] 12 | **image** | [**EndpointModelImageUpdate**](EndpointModelImageUpdate.md) | | [optional] 13 | **repository** | **String** | HuggingFace repository | [optional] 14 | **revision** | **String** | Model commit hash, if not set the latest commit will be used | [optional] 15 | **task** | [**EndpointTask**](EndpointTask.md) | | [optional] 16 | 17 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 18 | 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build Status 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: dart-lang/setup-dart@v1 16 | 17 | - name: Install dependencies 18 | run: dart pub get 19 | 20 | - name: Verify formatting 21 | run: dart format --output=none --set-exit-if-changed . 22 | 23 | - name: Analyze project source 24 | run: dart analyze 25 | 26 | - name: Run tests with coverage 27 | run: dart run coverage:test_with_coverage 28 | 29 | - name: Upload to codecov.io 30 | uses: codecov/codecov-action@v2 31 | with: 32 | token: ${{ secrets.CODECOV_TOKEN }} 33 | file: coverage/lcov.info 34 | name: Upload to codecov.io 35 | verbose: true 36 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointModelImageUpdateOneOfCustom.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointModelImageUpdateOneOfCustom 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **credentials** | [**EndpointImageCredentials**](EndpointImageCredentials.md) | | [optional] 12 | **env** | **Map** | Container environment variables | [optional] [default to const {}] 13 | **healthRoute** | **String** | Container health route | [optional] 14 | **port** | **int** | Endpoint API port | [optional] [default to 80] 15 | **url** | **String** | URL fo the container | [optional] 16 | 17 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/endpoint_scaling_update_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointScalingUpdate 14 | void main() { 15 | // final instance = EndpointScalingUpdate(); 16 | 17 | group('test EndpointScalingUpdate', () { 18 | // Maximum number of endpoint replica 19 | // int maxReplica 20 | test('to test the property `maxReplica`', () async { 21 | // TODO 22 | }); 23 | 24 | // Minimum number of endpoint replica 25 | // int minReplica 26 | test('to test the property `minReplica`', () async { 27 | // TODO 28 | }); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /test/endpoint_model_image_update_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageUpdate 14 | void main() { 15 | // final instance = EndpointModelImageUpdate(); 16 | 17 | group('test EndpointModelImageUpdate', () { 18 | // Model served by an Hugging Face container 19 | // Object huggingface 20 | test('to test the property `huggingface`', () async { 21 | // TODO 22 | }); 23 | 24 | // EndpointModelImageUpdateOneOfCustom custom 25 | test('to test the property `custom`', () async { 26 | // TODO 27 | }); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/openapi/auth/http_basic_auth.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class HttpBasicAuth implements Authentication { 13 | HttpBasicAuth({this.username = '', this.password = ''}); 14 | 15 | String username; 16 | String password; 17 | 18 | @override 19 | Future applyToParams( 20 | List queryParams, 21 | Map headerParams, 22 | ) async { 23 | if (username.isNotEmpty && password.isNotEmpty) { 24 | final credentials = '$username:$password'; 25 | headerParams['Authorization'] = 26 | 'Basic ${base64.encode(utf8.encode(credentials))}'; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /test/vendor_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Vendor 14 | void main() { 15 | // final instance = Vendor(); 16 | 17 | group('test Vendor', () { 18 | // String name 19 | test('to test the property `name`', () async { 20 | // TODO 21 | }); 22 | 23 | // Vendor regions list 24 | // List regions (default value: const []) 25 | test('to test the property `regions`', () async { 26 | // TODO 27 | }); 28 | 29 | // Status status 30 | test('to test the property `status`', () async { 31 | // TODO 32 | }); 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Endpoint.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Endpoint 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **accountId** | **String** | Account ID used to link a VPC to a private endpoint | [optional] 12 | **compute** | [**EndpointCompute**](EndpointCompute.md) | | 13 | **model** | [**EndpointModel**](EndpointModel.md) | | 14 | **name** | **String** | Endpoint name. Must only contains lowercase alphanumeric characters or '-' and have a length of 32 characters maximum | 15 | **provider** | [**EndpointProvider**](EndpointProvider.md) | | 16 | **type** | [**EndpointType**](EndpointType.md) | | 17 | 18 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib/src/openapi/api_exception.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class ApiException implements Exception { 13 | ApiException(this.code, this.message); 14 | 15 | ApiException.withInner( 16 | this.code, this.message, this.innerException, this.stackTrace); 17 | 18 | int code = 0; 19 | String? message; 20 | Exception? innerException; 21 | StackTrace? stackTrace; 22 | 23 | @override 24 | String toString() { 25 | if (message == null) { 26 | return 'ApiException'; 27 | } 28 | if (innerException == null) { 29 | return 'ApiException $code: $message'; 30 | } 31 | return 'ApiException $code: $message (Inner exception: $innerException)\n\n$stackTrace'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/metrics_params_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for MetricsParams 14 | void main() { 15 | // final instance = MetricsParams(); 16 | 17 | group('test MetricsParams', () { 18 | // String dnsPrefix 19 | test('to test the property `dnsPrefix`', () async { 20 | // TODO 21 | }); 22 | 23 | // int from 24 | test('to test the property `from`', () async { 25 | // TODO 26 | }); 27 | 28 | // String step 29 | test('to test the property `step`', () async { 30 | // TODO 31 | }); 32 | 33 | // int to 34 | test('to test the property `to`', () async { 35 | // TODO 36 | }); 37 | }); 38 | } 39 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointWithStatus.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointWithStatus 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **accountId** | **String** | Account ID used to link a VPC to a private endpoint | [optional] 12 | **compute** | [**EndpointCompute**](EndpointCompute.md) | | 13 | **model** | [**EndpointModel**](EndpointModel.md) | | 14 | **name** | **String** | Endpoint name. Must only contains lowercase alphanumeric characters or '-' and have a length of 32 characters maximum | 15 | **provider** | [**EndpointProvider**](EndpointProvider.md) | | 16 | **status** | [**EndpointStatus**](EndpointStatus.md) | | 17 | **type** | [**EndpointType**](EndpointType.md) | | 18 | 19 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/src/http/src/streamed_response.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'base_response.dart'; 6 | import 'byte_stream.dart'; 7 | import 'utils.dart'; 8 | 9 | /// An HTTP response where the response body is received asynchronously after 10 | /// the headers have been received. 11 | class StreamedResponse extends BaseResponse { 12 | /// The stream from which the response body data can be read. 13 | /// 14 | /// This should always be a single-subscription stream. 15 | final ByteStream stream; 16 | 17 | /// Creates a new streaming response. 18 | /// 19 | /// [stream] should be a single-subscription stream. 20 | StreamedResponse(Stream> stream, super.statusCode, 21 | {super.contentLength, 22 | super.request, 23 | super.headers, 24 | super.isRedirect, 25 | super.persistentConnection, 26 | super.reasonPhrase}) 27 | : stream = toByteStream(stream); 28 | } 29 | -------------------------------------------------------------------------------- /.github/workflows/pana.yml: -------------------------------------------------------------------------------- 1 | name: Pana Analysis 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - development 7 | 8 | jobs: 9 | 10 | package-analysis: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - uses: axel-op/dart-package-analyzer@v3 18 | id: analysis # set an id for the current step 19 | with: 20 | githubToken: ${{ secrets.GITHUB_TOKEN }} 21 | 22 | # You can then use this id to retrieve the outputs in the next steps. 23 | # The following step shows how to exit the workflow with an error if a score is below 100: 24 | - name: Check scores 25 | env: 26 | # NB: "analysis" is the id set above. Replace it with the one you used if different. 27 | TOTAL: ${{ steps.analysis.outputs.total }} 28 | TOTAL_MAX: ${{ steps.analysis.outputs.total_max }} 29 | run: | 30 | PERCENTAGE=$(( $TOTAL * 100 / $TOTAL_MAX )) 31 | if (( $PERCENTAGE < 50 )) 32 | then 33 | echo Score too low! 34 | exit 1 35 | fi 36 | -------------------------------------------------------------------------------- /test/region_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Region 14 | void main() { 15 | // final instance = Region(); 16 | 17 | group('test Region', () { 18 | // Vendor region compute resources list 19 | // List computes (default value: const []) 20 | test('to test the property `computes`', () async { 21 | // TODO 22 | }); 23 | 24 | // String label 25 | test('to test the property `label`', () async { 26 | // TODO 27 | }); 28 | 29 | // Region name 30 | // String name 31 | test('to test the property `name`', () async { 32 | // TODO 33 | }); 34 | 35 | // Status status 36 | test('to test the property `status`', () async { 37 | // TODO 38 | }); 39 | }); 40 | } 41 | -------------------------------------------------------------------------------- /test/endpoint_compute_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointCompute 14 | void main() { 15 | // final instance = EndpointCompute(); 16 | 17 | group('test EndpointCompute', () { 18 | // EndpointAccelerator accelerator 19 | test('to test the property `accelerator`', () async { 20 | // TODO 21 | }); 22 | 23 | // String instanceSize 24 | test('to test the property `instanceSize`', () async { 25 | // TODO 26 | }); 27 | 28 | // Compute instance type 29 | // String instanceType 30 | test('to test the property `instanceType`', () async { 31 | // TODO 32 | }); 33 | 34 | // EndpointScaling scaling 35 | test('to test the property `scaling`', () async { 36 | // TODO 37 | }); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Steve Hamblett 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/endpoint_compute_update_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointComputeUpdate 14 | void main() { 15 | // final instance = EndpointComputeUpdate(); 16 | 17 | group('test EndpointComputeUpdate', () { 18 | // EndpointAccelerator accelerator 19 | test('to test the property `accelerator`', () async { 20 | // TODO 21 | }); 22 | 23 | // String instanceSize 24 | test('to test the property `instanceSize`', () async { 25 | // TODO 26 | }); 27 | 28 | // Compute instance type 29 | // String instanceType 30 | test('to test the property `instanceType`', () async { 31 | // TODO 32 | }); 33 | 34 | // EndpointScalingUpdate scaling 35 | test('to test the property `scaling`', () async { 36 | // TODO 37 | }); 38 | }); 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/http/testing.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | /// This library contains testing classes for the HTTP library. 6 | /// 7 | /// The [MockClient] class is a drop-in replacement for `http.Client` that 8 | /// allows test code to set up a local request handler in order to fake a server 9 | /// that responds to HTTP requests: 10 | /// 11 | /// import 'dart:convert'; 12 | /// import 'package:http/testing.dart'; 13 | /// 14 | /// var client = MockClient((request) async { 15 | /// if (request.url.path != "/data.json") { 16 | /// return Response("", 404); 17 | /// } 18 | /// return Response( 19 | /// json.encode({ 20 | /// 'numbers': [1, 4, 15, 19, 214] 21 | /// }), 22 | /// 200, 23 | /// headers: {'content-type': 'application/json'}); 24 | /// }); 25 | // ignore: unnecessary_library_name 26 | library http.testing; 27 | 28 | import 'src/mock_client.dart'; 29 | 30 | export 'src/mock_client.dart'; 31 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/EndpointStatus.md: -------------------------------------------------------------------------------- 1 | # openapi.model.EndpointStatus 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **createdAt** | [**DateTime**](DateTime.md) | Date of creation | 12 | **createdBy** | [**EndpointAccount**](EndpointAccount.md) | | 13 | **message** | **String** | Information about the state of the endpoint | 14 | **private** | [**EndpointStatusPrivate**](EndpointStatusPrivate.md) | | [optional] 15 | **readyReplica** | **int** | Number of replica ready to handle requests | 16 | **state** | [**EndpointState**](EndpointState.md) | | 17 | **targetReplica** | **int** | Target number of replica to handle requests | 18 | **updatedAt** | [**DateTime**](DateTime.md) | Date of last update | 19 | **updatedBy** | [**EndpointAccount**](EndpointAccount.md) | | 20 | **url** | **String** | URL the endpoint is reachable at | [optional] 21 | 22 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/inference_endpoint_provider_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import 'api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference endpoint provider API to perform 12 | /// inference endpoint provider tasks. 13 | 14 | void main() async { 15 | // Get an inference endpoint provider API client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getEndpointProviderClient( 17 | endpointApiKey, 'shamblett', HuggingFaceClient.endpointBasePath); 18 | 19 | // Get an instance of the inference endpoint API using our client 20 | final apiInstance = EndpointProviderApi(client); 21 | 22 | // 23 | // List vendors, regions and compute resources available 24 | // 25 | print(''); 26 | print('*** Endpoint Provider API ***'); 27 | print(''); 28 | try { 29 | final result = await apiInstance.listVendors(); 30 | print(result); 31 | } catch (e) { 32 | print('Exception when calling Endpoint Provider API : $e - exiting'); 33 | return; 34 | } 35 | 36 | return; 37 | } 38 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/Compute.md: -------------------------------------------------------------------------------- 1 | # openapi.model.Compute 2 | 3 | ## Load the model package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | ## Properties 9 | Name | Type | Description | Notes 10 | ------------ | ------------- | ------------- | ------------- 11 | **accelerator** | [**Accelerator**](Accelerator.md) | | 12 | **architecture** | **String** | Compute accelerator architecture | 13 | **gpuMemoryGb** | **int** | Amount of memory per GPU in GB | [optional] 14 | **instanceSize** | **String** | Compute accelerator instance size | 15 | **instanceType** | **String** | Compute accelerator instance type | 16 | **memoryGb** | **int** | Amount of RAM which can be requested per endpoint replica | 17 | **numAccelerators** | **int** | Number of accelerator units which can be requested per endpoint replica | 18 | **numCpus** | **int** | Number of CPUs which can be requested per endpoint replica | [optional] 19 | **pricePerHour** | **double** | Price per hour in dollar of an endpoint replica | 20 | **status** | [**Status**](Status.md) | | 21 | 22 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 23 | 24 | 25 | -------------------------------------------------------------------------------- /lib/src/http/src/io_streamed_response.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:io'; 6 | 7 | import 'streamed_response.dart'; 8 | 9 | /// An HTTP response where the response body is received asynchronously after 10 | /// the headers have been received. 11 | class IOStreamedResponse extends StreamedResponse { 12 | final HttpClientResponse? _inner; 13 | 14 | /// Creates a new streaming response. 15 | /// 16 | /// [stream] should be a single-subscription stream. 17 | /// 18 | /// If [inner] is not provided, [detachSocket] will throw. 19 | IOStreamedResponse(super.stream, super.statusCode, 20 | {super.contentLength, 21 | super.request, 22 | super.headers, 23 | super.isRedirect, 24 | super.persistentConnection, 25 | super.reasonPhrase, 26 | HttpClientResponse? inner}) 27 | : _inner = inner; 28 | 29 | /// Detaches the underlying socket from the HTTP server. 30 | /// 31 | /// Will throw if `inner` was not set or `null` when `this` was created. 32 | Future detachSocket() async => _inner!.detachSocket(); 33 | } 34 | -------------------------------------------------------------------------------- /test/endpoint_model_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModel 14 | void main() { 15 | // final instance = EndpointModel(); 16 | 17 | group('test EndpointModel', () { 18 | // EndpointFramework framework 19 | test('to test the property `framework`', () async { 20 | // TODO 21 | }); 22 | 23 | // EndpointModelImage image 24 | test('to test the property `image`', () async { 25 | // TODO 26 | }); 27 | 28 | // HuggingFace repository 29 | // String repository 30 | test('to test the property `repository`', () async { 31 | // TODO 32 | }); 33 | 34 | // Model commit hash, if not set the latest commit will be used 35 | // String revision 36 | test('to test the property `revision`', () async { 37 | // TODO 38 | }); 39 | 40 | // EndpointTask task 41 | test('to test the property `task`', () async { 42 | // TODO 43 | }); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /test/v1provider_api_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | /// tests for V1providerApi 14 | void main() { 15 | // final instance = V1providerApi(); 16 | 17 | group('tests for V1providerApi', () { 18 | // List compute resources available for this provider region\\ 19 | // 20 | // List compute resources available for this provider region\\ 21 | // 22 | //Future listComputes(String vendor, String region) async 23 | test('test listComputes', () async { 24 | // TODO 25 | }); 26 | 27 | // List vendor regions 28 | // 29 | // List vendor regions 30 | // 31 | //Future listRegions(String vendor) async 32 | test('test listRegions', () async { 33 | // TODO 34 | }); 35 | 36 | // List vendors 37 | // 38 | // List vendors 39 | // 40 | //Future listVendors() async 41 | test('test listVendors', () async { 42 | // TODO 43 | }); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /test/endpoint_model_update_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelUpdate 14 | void main() { 15 | // final instance = EndpointModelUpdate(); 16 | 17 | group('test EndpointModelUpdate', () { 18 | // EndpointFramework framework 19 | test('to test the property `framework`', () async { 20 | // TODO 21 | }); 22 | 23 | // EndpointModelImageUpdate image 24 | test('to test the property `image`', () async { 25 | // TODO 26 | }); 27 | 28 | // HuggingFace repository 29 | // String repository 30 | test('to test the property `repository`', () async { 31 | // TODO 32 | }); 33 | 34 | // Model commit hash, if not set the latest commit will be used 35 | // String revision 36 | test('to test the property `revision`', () async { 37 | // TODO 38 | }); 39 | 40 | // EndpointTask task 41 | test('to test the property `task`', () async { 42 | // TODO 43 | }); 44 | }); 45 | } 46 | -------------------------------------------------------------------------------- /example/inference_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import 'api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform basic 12 | /// model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Standard no task based inference query using the gpt2 model 24 | // 25 | print(''); 26 | print('*** Inference API standard query ***'); 27 | print(''); 28 | try { 29 | final result = 30 | await apiInstance.query(queryString: 'Where is Paris?', model: 'gpt2'); 31 | if (result!.isNotEmpty) { 32 | print(result); 33 | } else { 34 | print('Inference API standard query returned empty result'); 35 | } 36 | } catch (e) { 37 | print('Exception when calling Inference API standard query: $e - exiting'); 38 | return; 39 | } 40 | 41 | return; 42 | } 43 | -------------------------------------------------------------------------------- /lib/src/openapi/auth/api_key_auth.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class ApiKeyAuth implements Authentication { 13 | ApiKeyAuth(this.location, this.paramName); 14 | 15 | final String location; 16 | final String paramName; 17 | 18 | String apiKeyPrefix = ''; 19 | String apiKey = ''; 20 | 21 | @override 22 | Future applyToParams( 23 | List queryParams, 24 | Map headerParams, 25 | ) async { 26 | final paramValue = apiKeyPrefix.isEmpty ? apiKey : '$apiKeyPrefix $apiKey'; 27 | 28 | if (paramValue.isNotEmpty) { 29 | if (location == 'query') { 30 | queryParams.add(QueryParam(paramName, paramValue)); 31 | } else if (location == 'header') { 32 | headerParams[paramName] = paramValue; 33 | } else if (location == 'cookie') { 34 | headerParams.update( 35 | 'Cookie', 36 | (existingCookie) => '$existingCookie; $paramName=$paramValue', 37 | ifAbsent: () => '$paramName=$paramValue', 38 | ); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /example/nlp/inference_qa_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Question and answer task 24 | // 25 | print(''); 26 | print('*** Question and Answer Task ***'); 27 | print(''); 28 | try { 29 | final input = ApiQuestionContext( 30 | question: 'What is my name?', 31 | context: 'My name is Clara and I live in Berkeley.'); 32 | final params = ApiQueryNLPQA(inputs: input); 33 | final result = await apiInstance.queryNLPQA( 34 | taskParameters: params, model: 'deepset/roberta-base-squad2'); 35 | print(result!); 36 | } catch (e) { 37 | print( 38 | 'Exception when calling Inference task API Question Answer: $e - exiting'); 39 | return; 40 | } 41 | 42 | return; 43 | } 44 | -------------------------------------------------------------------------------- /test/endpoint_model_image_one_of1_custom_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageOneOf1Custom 14 | void main() { 15 | // final instance = EndpointModelImageOneOf1Custom(); 16 | 17 | group('test EndpointModelImageOneOf1Custom', () { 18 | // EndpointImageCredentials credentials 19 | test('to test the property `credentials`', () async { 20 | // TODO 21 | }); 22 | 23 | // Container environment variables 24 | // Map env (default value: const {}) 25 | test('to test the property `env`', () async { 26 | // TODO 27 | }); 28 | 29 | // Container health route 30 | // String healthRoute 31 | test('to test the property `healthRoute`', () async { 32 | // TODO 33 | }); 34 | 35 | // Endpoint API port 36 | // int port (default value: 80) 37 | test('to test the property `port`', () async { 38 | // TODO 39 | }); 40 | 41 | // URL fo the container 42 | // String url 43 | test('to test the property `url`', () async { 44 | // TODO 45 | }); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/http/src/boundary_characters.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | /// All character codes that are valid in multipart boundaries. 6 | /// 7 | /// This is the intersection of the characters allowed in the `bcharsnospace` 8 | /// production defined in [RFC 2046][] and those allowed in the `token` 9 | /// production defined in [RFC 1521][]. 10 | /// 11 | /// [RFC 2046]: http://tools.ietf.org/html/rfc2046#section-5.1.1. 12 | /// [RFC 1521]: https://tools.ietf.org/html/rfc1521#section-4 13 | const List boundaryCharacters = [ 14 | 43, 15 | 95, 16 | 45, 17 | 46, 18 | 48, 19 | 49, 20 | 50, 21 | 51, 22 | 52, 23 | 53, 24 | 54, 25 | 55, 26 | 56, 27 | 57, 28 | 65, 29 | 66, 30 | 67, 31 | 68, 32 | 69, 33 | 70, 34 | 71, 35 | 72, 36 | 73, 37 | 74, 38 | 75, 39 | 76, 40 | 77, 41 | 78, 42 | 79, 43 | 80, 44 | 81, 45 | 82, 46 | 83, 47 | 84, 48 | 85, 49 | 86, 50 | 87, 51 | 88, 52 | 89, 53 | 90, 54 | 97, 55 | 98, 56 | 99, 57 | 100, 58 | 101, 59 | 102, 60 | 103, 61 | 104, 62 | 105, 63 | 106, 64 | 107, 65 | 108, 66 | 109, 67 | 110, 68 | 111, 69 | 112, 70 | 113, 71 | 114, 72 | 115, 73 | 116, 74 | 117, 75 | 118, 76 | 119, 77 | 120, 78 | 121, 79 | 122 80 | ]; 81 | -------------------------------------------------------------------------------- /test/endpoint_model_image_update_one_of_custom_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointModelImageUpdateOneOfCustom 14 | void main() { 15 | // final instance = EndpointModelImageUpdateOneOfCustom(); 16 | 17 | group('test EndpointModelImageUpdateOneOfCustom', () { 18 | // EndpointImageCredentials credentials 19 | test('to test the property `credentials`', () async { 20 | // TODO 21 | }); 22 | 23 | // Container environment variables 24 | // Map env (default value: const {}) 25 | test('to test the property `env`', () async { 26 | // TODO 27 | }); 28 | 29 | // Container health route 30 | // String healthRoute 31 | test('to test the property `healthRoute`', () async { 32 | // TODO 33 | }); 34 | 35 | // Endpoint API port 36 | // int port (default value: 80) 37 | test('to test the property `port`', () async { 38 | // TODO 39 | }); 40 | 41 | // URL fo the container 42 | // String url 43 | test('to test the property `url`', () async { 44 | // TODO 45 | }); 46 | }); 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/api/model/api_response_nlp_sentence_similarity.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | class ApiResponseNLPSentenceSimilarity { 11 | /// Returns a new [ApiResponseNLPSentenceSimilarity] instance. 12 | ApiResponseNLPSentenceSimilarity({ 13 | required this.scores, 14 | }); 15 | 16 | /// The associated similarity score for each of the given strings. 17 | List scores; 18 | 19 | @override 20 | bool operator ==(Object other) => 21 | identical(this, other) || 22 | other is ApiResponseNLPSentenceSimilarity && other.scores == scores; 23 | 24 | @override 25 | int get hashCode => 26 | // ignore: unnecessary_parenthesis 27 | (scores.hashCode); 28 | 29 | @override 30 | String toString() => 'ApiResponseNLPSentenceSimilarity - [Scores=$scores]'; 31 | 32 | List toJson() => scores; 33 | 34 | /// Returns a new [ApiResponseNLPSentenceSimilarity] instance and imports its values from 35 | /// [value] if it's a [List], null otherwise. 36 | // ignore: prefer_constructors_over_static_methods 37 | static ApiResponseNLPSentenceSimilarity? fromJson(dynamic value) { 38 | if (value is List) { 39 | return ApiResponseNLPSentenceSimilarity(scores: value.cast()); 40 | } 41 | return null; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/endpoint_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Endpoint 14 | void main() { 15 | // final instance = Endpoint(); 16 | 17 | group('test Endpoint', () { 18 | // Account ID used to link a VPC to a private endpoint 19 | // String accountId 20 | test('to test the property `accountId`', () async { 21 | // TODO 22 | }); 23 | 24 | // EndpointCompute compute 25 | test('to test the property `compute`', () async { 26 | // TODO 27 | }); 28 | 29 | // EndpointModel model 30 | test('to test the property `model`', () async { 31 | // TODO 32 | }); 33 | 34 | // Endpoint name. Must only contains lowercase alphanumeric characters or '-' and have a length of 32 characters maximum 35 | // String name 36 | test('to test the property `name`', () async { 37 | // TODO 38 | }); 39 | 40 | // EndpointProvider provider 41 | test('to test the property `provider`', () async { 42 | // TODO 43 | }); 44 | 45 | // EndpointType type 46 | test('to test the property `type`', () async { 47 | // TODO 48 | }); 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /lib/src/openapi/doc/V2providerApi.md: -------------------------------------------------------------------------------- 1 | # openapi.api.V2providerApi 2 | 3 | ## Load the API package 4 | ```dart 5 | import 'package:huggingface_client/huggingface_client.dart'; 6 | ``` 7 | 8 | All URIs are relative to *http://localhost* 9 | 10 | Method | HTTP request | Description 11 | ------------- | ------------- | ------------- 12 | [**listVendors**](V2providerApi.md#listvendors) | **GET** /v2/provider | List vendors, regions and compute resources available 13 | 14 | 15 | # **listVendors** 16 | > VendorList listVendors() 17 | 18 | List vendors, regions and compute resources available 19 | 20 | List vendors, regions and compute resources available 21 | 22 | ### Example 23 | ```dart 24 | import 'package:huggingface_client/huggingface_client.dart'; 25 | 26 | final api_instance = V2providerApi(); 27 | 28 | try { 29 | final result = api_instance.listVendors(); 30 | print(result); 31 | } catch (e) { 32 | print('Exception when calling V2providerApi->listVendors: $e\n'); 33 | } 34 | ``` 35 | 36 | ### Parameters 37 | This endpoint does not need any parameter. 38 | 39 | ### Return type 40 | 41 | [**VendorList**](VendorList.md) 42 | 43 | ### Authorization 44 | 45 | No authorization required 46 | 47 | ### HTTP request headers 48 | 49 | - **Content-Type**: Not defined 50 | - **Accept**: application/json 51 | 52 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 53 | 54 | -------------------------------------------------------------------------------- /example/nlp/inference_fill_mask_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Fill mask task 24 | // 25 | print(''); 26 | print('*** Fill Mask Task ***'); 27 | print(''); 28 | try { 29 | final input = 'The answer to the universe is [MASK].'; 30 | final params = ApiQueryNLPFillMask(inputs: [input]); 31 | final result = await apiInstance.queryNLPFillMask( 32 | taskParameters: params, model: 'bert-base-uncased'); 33 | if (result!.isNotEmpty) { 34 | for (final row in result) { 35 | print(row); 36 | } 37 | } else { 38 | print('Inference task API Fill Mask returned empty result'); 39 | } 40 | } catch (e) { 41 | print('Exception when calling Inference task API Fill Mask: $e - exiting'); 42 | return; 43 | } 44 | 45 | return; 46 | } 47 | -------------------------------------------------------------------------------- /lib/src/openapi/auth/http_bearer_auth.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | typedef HttpBearerAuthProvider = String Function(); 13 | 14 | class HttpBearerAuth implements Authentication { 15 | HttpBearerAuth(); 16 | 17 | dynamic _accessToken; 18 | 19 | dynamic get accessToken => _accessToken; 20 | 21 | set accessToken(dynamic accessToken) { 22 | if (accessToken is! String && accessToken is! HttpBearerAuthProvider) { 23 | throw ArgumentError( 24 | 'accessToken value must be either a String or a String Function().'); 25 | } 26 | _accessToken = accessToken; 27 | } 28 | 29 | @override 30 | Future applyToParams( 31 | List queryParams, 32 | Map headerParams, 33 | ) async { 34 | if (_accessToken == null) { 35 | return; 36 | } 37 | 38 | String accessToken; 39 | 40 | if (_accessToken is String) { 41 | accessToken = _accessToken; 42 | } else if (_accessToken is HttpBearerAuthProvider) { 43 | accessToken = _accessToken!(); 44 | } else { 45 | return; 46 | } 47 | 48 | if (accessToken.isNotEmpty) { 49 | headerParams['Authorization'] = 'Bearer $accessToken'; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/src/http/src/byte_stream.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:convert'; 7 | import 'dart:typed_data'; 8 | 9 | /// A stream of chunks of bytes representing a single piece of data. 10 | final class ByteStream extends StreamView> { 11 | const ByteStream(super.stream); 12 | 13 | /// Returns a single-subscription byte stream that will emit the given bytes 14 | /// in a single chunk. 15 | factory ByteStream.fromBytes(List bytes) => 16 | ByteStream(Stream.value(bytes)); 17 | 18 | /// Collects the data of this stream in a [Uint8List]. 19 | Future toBytes() { 20 | var completer = Completer(); 21 | var sink = ByteConversionSink.withCallback( 22 | (bytes) => completer.complete(Uint8List.fromList(bytes))); 23 | listen(sink.add, 24 | onError: completer.completeError, 25 | onDone: sink.close, 26 | cancelOnError: true); 27 | return completer.future; 28 | } 29 | 30 | /// Collect the data of this stream in a [String], decoded according to 31 | /// [encoding], which defaults to `UTF8`. 32 | Future bytesToString([Encoding encoding = utf8]) => 33 | encoding.decodeStream(this); 34 | 35 | Stream toStringStream([Encoding encoding = utf8]) => 36 | encoding.decoder.bind(this); 37 | } 38 | -------------------------------------------------------------------------------- /example/nlp/inference_sentence_similarity_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Sentence Similarity task 24 | // 25 | print(''); 26 | print('*** Sentence Similarity Task ***'); 27 | print(''); 28 | try { 29 | final sentences = [ 30 | 'That is a happy dog', 31 | 'That is a very happy person', 32 | 'Today is a sunny day' 33 | ]; 34 | final params = ApiQueryNLPSentenceSimilarity( 35 | sourceSentence: '"That is a happy person', sentences: sentences); 36 | final result = await apiInstance.queryNLPSentenceSimilarity( 37 | taskParameters: params, 38 | model: 'sentence-transformers/all-MiniLM-L6-v2'); 39 | print(result!); 40 | } catch (e) { 41 | print( 42 | 'Exception when calling Inference task API Sentence Similarity : $e - exiting'); 43 | return; 44 | } 45 | 46 | return; 47 | } 48 | -------------------------------------------------------------------------------- /example/nlp/inference_translation_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Text translation task 24 | // 25 | print(''); 26 | print('*** Text Translation Task ***'); 27 | print(''); 28 | try { 29 | final input = 'Меня зовут Вольфганг и я живу в Берлине'; 30 | final params = ApiQueryNLPTranslation(inputs: [input]); 31 | final result = await apiInstance.queryNLPTranslation( 32 | taskParameters: params, model: 'Helsinki-NLP/opus-mt-ru-en'); 33 | if (result!.isNotEmpty) { 34 | for (final row in result) { 35 | print(row?.translationText); 36 | } 37 | } else { 38 | print('Inference task API Text Translation returned empty result'); 39 | } 40 | } catch (e) { 41 | print( 42 | 'Exception when calling Inference task API Text Translation: $e - exiting'); 43 | return; 44 | } 45 | 46 | return; 47 | } 48 | -------------------------------------------------------------------------------- /example/nlp/inference_text_classification_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Text Classification task 24 | // 25 | print(''); 26 | print('*** Text Classification Task ***'); 27 | print(''); 28 | try { 29 | final input = 'I like you. I love you'; 30 | final params = ApiQueryNLPTextClassification(inputs: [input]); 31 | final result = await apiInstance.queryNLPTextClassification( 32 | taskParameters: params, 33 | model: 'distilbert-base-uncased-finetuned-sst-2-english'); 34 | if (result!.isNotEmpty) { 35 | for (final row in result) { 36 | print(row); 37 | } 38 | } else { 39 | print('Inference task API Text Classification returned empty result'); 40 | } 41 | } catch (e) { 42 | print( 43 | 'Exception when calling Inference task API Text Classification: $e - exiting'); 44 | return; 45 | } 46 | 47 | return; 48 | } 49 | -------------------------------------------------------------------------------- /example/nlp/inference_chat_completion_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Conversational task 24 | // 25 | print(''); 26 | print('*** Conversational Task ***'); 27 | print(''); 28 | try { 29 | final params = ApiQueryChatCompletion( 30 | model: "HuggingFaceH4/starchat2-15b-v0.1", 31 | stream: false, 32 | message: [ 33 | {"role": "user", "content": "What is the capital of France?"} 34 | ], 35 | ); 36 | print("Simple response"); 37 | final result = await apiInstance.chatCompletion(query: params); 38 | print(result); 39 | 40 | print("Stream / result"); 41 | final streamresult = apiInstance.chatStreamCompletion(query: params); 42 | streamresult.listen((pri) => print(pri.delta.content)); 43 | } catch (e) { 44 | print( 45 | 'Exception when calling Inference task API Conversational: $e - exiting'); 46 | return; 47 | } 48 | 49 | return; 50 | } 51 | -------------------------------------------------------------------------------- /test/endpoint_with_status_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointWithStatus 14 | void main() { 15 | // final instance = EndpointWithStatus(); 16 | 17 | group('test EndpointWithStatus', () { 18 | // Account ID used to link a VPC to a private endpoint 19 | // String accountId 20 | test('to test the property `accountId`', () async { 21 | // TODO 22 | }); 23 | 24 | // EndpointCompute compute 25 | test('to test the property `compute`', () async { 26 | // TODO 27 | }); 28 | 29 | // EndpointModel model 30 | test('to test the property `model`', () async { 31 | // TODO 32 | }); 33 | 34 | // Endpoint name. Must only contains lowercase alphanumeric characters or '-' and have a length of 32 characters maximum 35 | // String name 36 | test('to test the property `name`', () async { 37 | // TODO 38 | }); 39 | 40 | // EndpointProvider provider 41 | test('to test the property `provider`', () async { 42 | // TODO 43 | }); 44 | 45 | // EndpointStatus status 46 | test('to test the property `status`', () async { 47 | // TODO 48 | }); 49 | 50 | // EndpointType type 51 | test('to test the property `type`', () async { 52 | // TODO 53 | }); 54 | }); 55 | } 56 | -------------------------------------------------------------------------------- /example/nlp/inference_token_classification_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Token classification task 24 | // 25 | print(''); 26 | print('*** Token Classification Task ***'); 27 | print(''); 28 | try { 29 | final input = 'My name is Sarah Jessica Parker but you can call me Jessica'; 30 | final params = ApiQueryNLPTokenClassification(inputs: [input]); 31 | final result = await apiInstance.queryNLPTokenClassification( 32 | taskParameters: params, 33 | model: 'dbmdz/bert-large-cased-finetuned-conll03-english'); 34 | if (result!.isNotEmpty) { 35 | for (final row in result) { 36 | print(row); 37 | } 38 | } else { 39 | print('Inference task API Token Classification returned empty result'); 40 | } 41 | } catch (e) { 42 | print( 43 | 'Exception when calling Inference task API Token Classification: $e - exiting'); 44 | return; 45 | } 46 | 47 | return; 48 | } 49 | -------------------------------------------------------------------------------- /example/nlp/inference_text_to_image_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform NLP 14 | /// task based model queries. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Conversational task 26 | // 27 | print(''); 28 | print('*** Conversational Task ***'); 29 | print(''); 30 | try { 31 | final imageFilePath = 32 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 33 | 'audio${Platform.pathSeparator}test${Platform.pathSeparator}textToImage.jpeg'; 34 | final file = File(imageFilePath); 35 | final input = 'Astronaut riding a horse'; 36 | final params = ApiResponseTextToImage(inputs: input); 37 | final result = await apiInstance.textToImage( 38 | textToImageParam: params, model: "black-forest-labs/FLUX.1-dev"); 39 | 40 | print(result); 41 | await file.writeAsBytes(result); 42 | } catch (e) { 43 | print( 44 | 'Exception when calling Inference task API Conversational: $e - exiting'); 45 | return; 46 | } 47 | 48 | return; 49 | } 50 | -------------------------------------------------------------------------------- /example/nlp/inference_text_generation_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Text Generation task 24 | // 25 | print(''); 26 | print('*** Text Generation Task ***'); 27 | print(''); 28 | try { 29 | final input = 'How are you?'; 30 | final params = ApiQueryNLPTextGeneration(inputs: input); 31 | final result = await apiInstance.queryNLPTextGeneration( 32 | taskParameters: params, model: 'gpt2'); 33 | if (result!.isNotEmpty) { 34 | for (final row in result) { 35 | print(row); 36 | } 37 | } else { 38 | print('Inference task API Text Generation returned empty result'); 39 | } 40 | print('stream response start......'); 41 | final streamResult = 42 | apiInstance.textStreamGeneration(query: params, model: "gpt2"); 43 | streamResult.listen(print); 44 | print('stream response end......'); 45 | } catch (e) { 46 | print( 47 | 'Exception when calling Inference task API Text Generation: $e - exiting'); 48 | return; 49 | } 50 | 51 | return; 52 | } 53 | -------------------------------------------------------------------------------- /example/nlp/inference_conversational_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Conversational task 24 | // 25 | print(''); 26 | print('*** Conversational Task ***'); 27 | print(''); 28 | try { 29 | final pastUserInputs = 'Which movie is the best ?'; 30 | final generatedResponses = 'It is Die Hard for sure.'; 31 | final text = 'Can you explain why ?'; 32 | final params = ApiQueryNLPConversational( 33 | text: text, 34 | pastUserInputs: [pastUserInputs], 35 | generatedResponses: [generatedResponses]); 36 | 37 | final result = await apiInstance.queryNLPConversational( 38 | taskParameters: params, model: 'google/gemma-2-2b-it'); 39 | if (result!.isNotEmpty) { 40 | for (final row in result) { 41 | print(row); 42 | } 43 | } else { 44 | print('Inference task API Conversational returned empty result'); 45 | } 46 | } catch (e) { 47 | print( 48 | 'Exception when calling Inference task API Conversational: $e - exiting'); 49 | return; 50 | } 51 | 52 | return; 53 | } 54 | -------------------------------------------------------------------------------- /lib/src/http/src/base_response.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'base_client.dart'; 6 | import 'base_request.dart'; 7 | 8 | /// The base class for HTTP responses. 9 | /// 10 | /// Subclasses of [BaseResponse] are usually not constructed manually; instead, 11 | /// they're returned by [BaseClient.send] or other HTTP client methods. 12 | abstract class BaseResponse { 13 | /// The (frozen) request that triggered this response. 14 | final BaseRequest? request; 15 | 16 | /// The HTTP status code for this response. 17 | final int statusCode; 18 | 19 | /// The reason phrase associated with the status code. 20 | final String? reasonPhrase; 21 | 22 | /// The size of the response body, in bytes. 23 | /// 24 | /// If the size of the request is not known in advance, this is `null`. 25 | final int? contentLength; 26 | 27 | // TODO(nweiz): automatically parse cookies from headers 28 | 29 | // TODO(nweiz): make this a HttpHeaders object. 30 | final Map headers; 31 | 32 | final bool isRedirect; 33 | 34 | /// Whether the server requested that a persistent connection be maintained. 35 | final bool persistentConnection; 36 | 37 | BaseResponse(this.statusCode, 38 | {this.contentLength, 39 | this.request, 40 | this.headers = const {}, 41 | this.isRedirect = false, 42 | this.persistentConnection = true, 43 | this.reasonPhrase}) { 44 | if (statusCode < 100) { 45 | throw ArgumentError('Invalid status code $statusCode.'); 46 | } else if (contentLength != null && contentLength! < 0) { 47 | throw ArgumentError('Invalid content length $contentLength.'); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example/inference_api_using_endpoint_translation.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import 'api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform basic 12 | /// model queries against an existing inference endpoint. 13 | 14 | void main() async { 15 | // Create an inference endpoint with the 'Helsinki-NLP/opus-mt-ru-en' model and 16 | // the text translation task. 17 | 18 | // Get an inference client with your Hugging Face API key as authentication and 19 | // your created inference endpoint 20 | final client = HuggingFaceClient.getInferenceClient(inferenceApiKey, 21 | 'https://xxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud'); 22 | 23 | // Get an instance of the inference API using our client 24 | final apiInstance = InferenceApi(client); 25 | 26 | // 27 | // Text translation task 28 | // 29 | print(''); 30 | print('*** Text Translation Task ***'); 31 | print(''); 32 | try { 33 | final input = 'Меня зовут Вольфганг и я живу в Берлине'; 34 | final params = ApiQueryNLPTranslation(inputs: [input]); 35 | // Leave the model empty, the inference endpoint already has the model. 36 | final result = await apiInstance.queryNLPTranslation( 37 | taskParameters: params, model: ''); 38 | if (result!.isNotEmpty) { 39 | for (final row in result) { 40 | print(row?.translationText); 41 | } 42 | } else { 43 | print('Inference task API Text Translation returned empty result'); 44 | } 45 | } catch (e) { 46 | print( 47 | 'Exception when calling Inference task API Text Translation: $e - exiting'); 48 | return; 49 | } 50 | 51 | return; 52 | } 53 | -------------------------------------------------------------------------------- /example/nlp/inference_table_qa_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Table question and answer task 24 | // 25 | print(''); 26 | print('*** Table Question and Answer Task ***'); 27 | print(''); 28 | try { 29 | final table = >{ 30 | 'Repository': ['Transformers', 'Datasets', 'Tokenizers'], 31 | 'Stars': ['36542', '4512', '3934'], 32 | 'Contributors': ['651', '77', '34'], 33 | 'Programming language': ['Python', 'Python', 'Rust, Python and NodeJS'] 34 | }; 35 | final input = ApiTableQuery( 36 | query: 'How many stars does the transformers repository have?', 37 | table: table); 38 | final params = ApiQueryNLPTableQA(inputs: [input]); 39 | final result = await apiInstance.queryNLPTableQA( 40 | taskParameters: params, model: 'google/tapas-base-finetuned-wtq'); 41 | if (result!.isNotEmpty) { 42 | for (final row in result) { 43 | print(row); 44 | } 45 | } 46 | } catch (e) { 47 | print( 48 | 'Exception when calling Inference task API Table Question and Answer: $e - exiting'); 49 | return; 50 | } 51 | 52 | return; 53 | } 54 | -------------------------------------------------------------------------------- /example/nlp/inference_feature_extraction_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Feature Extraction task 24 | // 25 | // Note : this task currently fails, 26 | // see https://discuss.huggingface.co/t/sentencesimilarityinputscheck-expected-dict-not-list-root-in-parameters/39715 27 | print(''); 28 | print('*** Feature Extraction Task ***'); 29 | print(''); 30 | try { 31 | final input = 'A string of text from which to extract the features.'; 32 | final params = ApiQueryNLPFeatureExtraction( 33 | input: input, options: InferenceOptions(waitForModel: true)); 34 | 35 | final result = await apiInstance.queryNLPFeatureExtraction( 36 | taskParameters: params, model: 'facebook/bart-base'); 37 | if (result!.isNotEmpty) { 38 | for (final row in result) { 39 | print(row?.representationFeatures); 40 | } 41 | print('Complete'); 42 | print('Complete'); 43 | } else { 44 | print('Inference task API Feature Extraction returned empty result'); 45 | } 46 | } catch (e) { 47 | print( 48 | 'Exception when calling Inference task API Feature Extraction: $e - exiting'); 49 | return; 50 | } 51 | 52 | return; 53 | } 54 | -------------------------------------------------------------------------------- /example/nlp/inference_zero_shot_classification_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Zero shot classification task 24 | // 25 | // Note : may not work, see https://huggingface.co/facebook/bart-large-mnli/discussions/20 26 | print(''); 27 | print('*** Zero Shot Classification Task ***'); 28 | print(''); 29 | try { 30 | final input = 31 | 'Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!'; 32 | final candidateLabels = ['refund', 'legal', 'faq']; 33 | final params = ApiQueryNLPZeroShotClassification( 34 | inputs: [input], candidateLabels: candidateLabels); 35 | final result = await apiInstance.queryNLPZeroShotClassification( 36 | taskParameters: params, model: 'facebook/bart-large-mnli'); 37 | if (result!.isNotEmpty) { 38 | for (final row in result) { 39 | print(row); 40 | } 41 | } else { 42 | print( 43 | 'Inference task API Zero Shot Classification returned empty result'); 44 | } 45 | } catch (e) { 46 | print( 47 | 'Exception when calling Inference task API Zero Shot Classification: $e - exiting'); 48 | return; 49 | } 50 | 51 | return; 52 | } 53 | -------------------------------------------------------------------------------- /example/audio/inference_asr_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform basic 14 | /// model tasks. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Inference Audio ASR task 26 | // 27 | 28 | // Assumes you are running the example from the project root i.e 29 | // 'dart example/audio/inference_asr_api.dart' 30 | final audioFilePath = 31 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 32 | 'audio${Platform.pathSeparator}test${Platform.pathSeparator}asr.mp3'; 33 | final audioFile = File(audioFilePath); 34 | final audioFileContents = audioFile.readAsBytesSync(); 35 | audioFileContents.buffer.asByteData(); 36 | print(''); 37 | print('*** Inference API Audio ASR task ***'); 38 | print(''); 39 | try { 40 | final result = await apiInstance.queryAudioASR( 41 | audioFile: audioFileContents, model: 'facebook/wav2vec2-base-960h'); 42 | print('Inference Result'); 43 | print(result?.text); 44 | print(''); 45 | print('Actual audio text'); 46 | print( 47 | 'My dear Fanny, you feel these things a great deal too much. I am most happy that you like the chain'); 48 | } catch (e) { 49 | print('Exception when calling Audio Inference ASR API : $e - exiting'); 50 | return; 51 | } 52 | 53 | return; 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # huggingface_client 2 | [![Build Status](https://github.com/shamblett/huggingface_client/actions/workflows/ci.yml/badge.svg)](https://github.com/shamblett/huggingface_client/actions/workflows/ci.yml) 3 | 4 | A server and browser based [Hugging Face](https://huggingface.co/) REST API client for the inference and inference endpoint APIs. 5 | 6 | The client supports standard query based inference and inference tasks for Natural Language Processing(NLP), 7 | Audio and Vision. It also supports the inference endpoint API for creation and control of inference endpoints 8 | and the provider endpoint. 9 | 10 | The bindings for the inference endpoint API are generated from the [Hugging Face Inference Endpoint OpenApi specification](lib/src/openapi/spec/openapi.json) 11 | using the [OpenAPI Generator](https://openapi-generator.tech) project. 12 | 13 | API documentation generated by the OpenAPI Generator can be found [here](lib/src/openapi/doc). 14 | 15 | There is no such Open API specification for the inference API. 16 | 17 | See the [examples.md](example/example.md) document in the examples folder for usage examples. 18 | 19 | A Hugging Face API key is needed for authentication, see [here](https://huggingface.co/docs/api-inference/quicktour) for 20 | instructions on how to obtain this. 21 | 22 | Using the inference API with your own inference endpoint is a simple matter of substituting 23 | the hugging face base path with your inference endpoint URL and setting the model parameter to '' as 24 | the inference endpoints are created on a per model(repository) basis, see [here](https://huggingface.co/docs/inference-endpoints/guides/create_endpoint) 25 | for more details. Two examples of this are included in the example directory. 26 | 27 | Note that the inference endpoint and provider APIs use the V2 version of the Hugging Face API. The V1 version is 28 | deprecated by Hugging Face and should not be used, see [here](https://huggingface.co/docs/inference-endpoints/api_reference). -------------------------------------------------------------------------------- /example/audio/inference_classification_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform basic 14 | /// model tasks. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Inference Audio Classification task 26 | // 27 | 28 | // Assumes you are running the example from the project root i.e 29 | // 'dart example/audio/inference_classification_api.dart' 30 | final audioFilePath = 31 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 32 | 'audio${Platform.pathSeparator}test${Platform.pathSeparator}ac.wav'; 33 | final audioFile = File(audioFilePath); 34 | final audioFileContents = audioFile.readAsBytesSync(); 35 | audioFileContents.buffer.asByteData(); 36 | print(''); 37 | print('*** Inference API Audio Classification task ***'); 38 | print(''); 39 | try { 40 | final result = await apiInstance.queryAudioClassification( 41 | audioFile: audioFileContents, model: 'superb/hubert-large-superb-er'); 42 | if (result!.isNotEmpty) { 43 | for (final row in result) { 44 | print(row); 45 | } 46 | } else { 47 | print('Inference Audio Classification result is empty'); 48 | } 49 | } catch (e) { 50 | print( 51 | 'Exception when calling Audio Inference Classification API : $e - exiting'); 52 | return; 53 | } 54 | 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /example/vision/inference_object_detection_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform basic 14 | /// model tasks. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Inference Vision Object Detection task 26 | // 27 | 28 | // Assumes you are running the example from the project root i.e 29 | // 'dart example/vision/inference_object_detection_api.dart' 30 | final imageFilePath = 31 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 32 | 'vision${Platform.pathSeparator}test${Platform.pathSeparator}predict-dog.png'; 33 | final imageFile = File(imageFilePath); 34 | final imageFileContents = imageFile.readAsBytesSync(); 35 | imageFileContents.buffer.asByteData(); 36 | print(''); 37 | print('*** Inference API Vision Object Detection task ***'); 38 | print(''); 39 | try { 40 | final result = await apiInstance.queryVisionObjectDetection( 41 | imageFile: imageFileContents, model: 'facebook/detr-resnet-50'); 42 | if (result!.isNotEmpty) { 43 | for (final row in result) { 44 | print(row); 45 | } 46 | } else { 47 | print('Inference Vision Object Detection result is empty'); 48 | } 49 | } catch (e) { 50 | print( 51 | 'Exception when calling Vision Inference Object Detection API : $e - exiting'); 52 | return; 53 | } 54 | 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /example/vision/inference_image_classification_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform basic 14 | /// model tasks. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Inference Vision Image Classification task 26 | // 27 | 28 | // Assumes you are running the example from the project root i.e 29 | // 'dart example/vision/inference_image_classification_api.dart' 30 | final imageFilePath = 31 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 32 | 'vision${Platform.pathSeparator}test${Platform.pathSeparator}flower.jpg'; 33 | final imageFile = File(imageFilePath); 34 | final imageFileContents = imageFile.readAsBytesSync(); 35 | imageFileContents.buffer.asByteData(); 36 | print(''); 37 | print('*** Inference API Vision Image Classification task ***'); 38 | print(''); 39 | try { 40 | final result = await apiInstance.queryVisionImageClassification( 41 | imageFile: imageFileContents, model: 'google/vit-base-patch16-224'); 42 | if (result!.isNotEmpty) { 43 | for (final row in result) { 44 | print(row); 45 | } 46 | } else { 47 | print('Inference Vision Image Classification result is empty'); 48 | } 49 | } catch (e) { 50 | print( 51 | 'Exception when calling Vision Inference Image Classification API : $e - exiting'); 52 | return; 53 | } 54 | 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /example/inference_api_using_endpoint_conversational.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import 'api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform basic 12 | /// model queries against an existing inference endpoint. 13 | 14 | void main() async { 15 | // Create an inference endpoint with the 'gpt2' model and the 16 | // conversational task. 17 | 18 | // Get an inference client with your Hugging Face API key as authentication and 19 | // your created inference endpoint 20 | final client = HuggingFaceClient.getInferenceClient(inferenceApiKey, 21 | 'https://xxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud'); 22 | 23 | // Get an instance of the inference API using our client 24 | final apiInstance = InferenceApi(client); 25 | 26 | // 27 | // Conversational task. 28 | // 29 | print(''); 30 | print('*** Conversational Task ***'); 31 | print(''); 32 | try { 33 | final pastUserInputs = 'Which movie is the best ?'; 34 | final generatedResponses = 'It is Die Hard for sure.'; 35 | final text = 'Can you explain why ?'; 36 | final params = ApiQueryNLPConversational( 37 | text: text, 38 | pastUserInputs: [pastUserInputs], 39 | generatedResponses: [generatedResponses]); 40 | // Leave the model empty, the inference endpoint already has the model. 41 | final result = await apiInstance.queryNLPConversational( 42 | taskParameters: params, model: ''); 43 | if (result!.isNotEmpty) { 44 | for (final row in result) { 45 | print(row); 46 | } 47 | } else { 48 | print('Inference task API Conversational returned empty result'); 49 | } 50 | } catch (e) { 51 | print( 52 | 'Exception when calling Inference task API Conversational: $e - exiting'); 53 | return; 54 | } 55 | return; 56 | } 57 | -------------------------------------------------------------------------------- /example/vision/inference_image_segmentation_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'dart:io'; 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import '../api_key.dart'; 12 | 13 | /// Examples of how to use the Hugging Face Inference API to perform basic 14 | /// model tasks. 15 | 16 | void main() async { 17 | // Get an inference client with your Hugging Face API key as authentication. 18 | final client = HuggingFaceClient.getInferenceClient( 19 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 20 | 21 | // Get an instance of the inference API using our client 22 | final apiInstance = InferenceApi(client); 23 | 24 | // 25 | // Inference Vision Image Segmentation task 26 | // 27 | 28 | // Assumes you are running the example from the project root i.e 29 | // 'dart example/vision/inference_image_segmentation_api.dart' 30 | final imageFilePath = 31 | '${Directory.current.path}${Platform.pathSeparator}example${Platform.pathSeparator}' 32 | 'vision${Platform.pathSeparator}test${Platform.pathSeparator}predict-dog.png'; 33 | final imageFile = File(imageFilePath); 34 | final imageFileContents = imageFile.readAsBytesSync(); 35 | imageFileContents.buffer.asByteData(); 36 | print(''); 37 | print('*** Inference API Vision Image Segmentation task ***'); 38 | print(''); 39 | try { 40 | final result = await apiInstance.queryVisionImageSegmentation( 41 | imageFile: imageFileContents, 42 | model: 'facebook/detr-resnet-50-panoptic'); 43 | if (result!.isNotEmpty) { 44 | for (final row in result) { 45 | print(row); 46 | } 47 | } else { 48 | print('Inference Vision Image Segmentation result is empty'); 49 | } 50 | } catch (e) { 51 | print( 52 | 'Exception when calling Vision Inference Image Segmentation API : $e - exiting'); 53 | return; 54 | } 55 | 56 | return; 57 | } 58 | -------------------------------------------------------------------------------- /test/endpoint_status_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for EndpointStatus 14 | void main() { 15 | // final instance = EndpointStatus(); 16 | 17 | group('test EndpointStatus', () { 18 | // Date of creation 19 | // DateTime createdAt 20 | test('to test the property `createdAt`', () async { 21 | // TODO 22 | }); 23 | 24 | // EndpointAccount createdBy 25 | test('to test the property `createdBy`', () async { 26 | // TODO 27 | }); 28 | 29 | // Information about the state of the endpoint 30 | // String message 31 | test('to test the property `message`', () async { 32 | // TODO 33 | }); 34 | 35 | // EndpointStatusPrivate private 36 | test('to test the property `private`', () async { 37 | // TODO 38 | }); 39 | 40 | // Number of replica ready to handle requests 41 | // int readyReplica 42 | test('to test the property `readyReplica`', () async { 43 | // TODO 44 | }); 45 | 46 | // EndpointState state 47 | test('to test the property `state`', () async { 48 | // TODO 49 | }); 50 | 51 | // Target number of replica to handle requests 52 | // int targetReplica 53 | test('to test the property `targetReplica`', () async { 54 | // TODO 55 | }); 56 | 57 | // Date of last update 58 | // DateTime updatedAt 59 | test('to test the property `updatedAt`', () async { 60 | // TODO 61 | }); 62 | 63 | // EndpointAccount updatedBy 64 | test('to test the property `updatedBy`', () async { 65 | // TODO 66 | }); 67 | 68 | // URL the endpoint is reachable at 69 | // String url 70 | test('to test the property `url`', () async { 71 | // TODO 72 | }); 73 | }); 74 | } 75 | -------------------------------------------------------------------------------- /lib/src/api/model/api_response_nlp_feature_extraction.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | class ApiResponseNLPFeatureExtraction { 11 | /// Returns a new [ApiResponseNLPFeatureExtraction] instance. 12 | ApiResponseNLPFeatureExtraction({ 13 | required this.representationFeatures, 14 | }); 15 | 16 | /// The numbers that are the representation features of the input. 17 | List representationFeatures; 18 | 19 | @override 20 | bool operator ==(Object other) => 21 | identical(this, other) || 22 | other is ApiResponseNLPFeatureExtraction && 23 | other.representationFeatures == representationFeatures; 24 | 25 | @override 26 | int get hashCode => 27 | // ignore: unnecessary_parenthesis 28 | (representationFeatures.hashCode); 29 | 30 | @override 31 | String toString() => 32 | 'ApiResponseNLPFeatureExtraction - [Representation Features=$representationFeatures]'; 33 | 34 | List toJson() => representationFeatures; 35 | 36 | /// Returns a new [ApiResponseNLPFeatureExtraction] instance and imports its values from 37 | /// [value] if it's a [Map], null otherwise. 38 | // ignore: prefer_constructors_over_static_methods 39 | static ApiResponseNLPFeatureExtraction? fromJson(dynamic value) { 40 | if (value is List) { 41 | return ApiResponseNLPFeatureExtraction( 42 | representationFeatures: value.cast()); 43 | } 44 | return null; 45 | } 46 | 47 | static List listFromJson( 48 | dynamic json, { 49 | bool growable = false, 50 | }) { 51 | final result = []; 52 | if (json is List && json.isNotEmpty) { 53 | for (final row in json) { 54 | final value = ApiResponseNLPFeatureExtraction.fromJson(row); 55 | if (value != null) { 56 | result.add(value); 57 | } 58 | } 59 | } 60 | return result.toList(growable: growable); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /test/v1endpoint_api_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | /// tests for V1endpointApi 14 | void main() { 15 | // final instance = V1endpointApi(); 16 | 17 | group('tests for V1endpointApi', () { 18 | // Create a new endpoint 19 | // 20 | // Create a new endpoint 21 | // 22 | //Future createEndpoint(Endpoint endpoint) async 23 | test('test createEndpoint', () async { 24 | // TODO 25 | }); 26 | 27 | // Delete an endpoint 28 | // 29 | // Delete an endpoint 30 | // 31 | //Future deleteEndpoint(String name) async 32 | test('test deleteEndpoint', () async { 33 | // TODO 34 | }); 35 | 36 | // Get endpoint information 37 | // 38 | // Get endpoint information 39 | // 40 | //Future getEndpoint(String name) async 41 | test('test getEndpoint', () async { 42 | // TODO 43 | }); 44 | 45 | // Endpoint replicas logs 46 | // 47 | // Endpoint replicas logs 48 | // 49 | //Future getEndpointLogs(String name) async 50 | test('test getEndpointLogs', () async { 51 | // TODO 52 | }); 53 | 54 | // Get endpoint metric 55 | // 56 | // Get endpoint metric 57 | // 58 | //Future getEndpointMetric(String name, MetricName metric) async 59 | test('test getEndpointMetric', () async { 60 | // TODO 61 | }); 62 | 63 | // List endpoints 64 | // 65 | // List endpoints 66 | // 67 | //Future listEndpoint() async 68 | test('test listEndpoint', () async { 69 | // TODO 70 | }); 71 | 72 | // Update an endpoint 73 | // 74 | // Update an endpoint 75 | // 76 | //Future updateEndpoint(String name, EndpointUpdate endpointUpdate) async 77 | test('test updateEndpoint', () async { 78 | // TODO 79 | }); 80 | }); 81 | } 82 | -------------------------------------------------------------------------------- /test/compute_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | // tests for Compute 14 | void main() { 15 | // final instance = Compute(); 16 | 17 | group('test Compute', () { 18 | // Accelerator accelerator 19 | test('to test the property `accelerator`', () async { 20 | // TODO 21 | }); 22 | 23 | // Compute accelerator architecture 24 | // String architecture 25 | test('to test the property `architecture`', () async { 26 | // TODO 27 | }); 28 | 29 | // Amount of memory per GPU in GB 30 | // int gpuMemoryGb 31 | test('to test the property `gpuMemoryGb`', () async { 32 | // TODO 33 | }); 34 | 35 | // Compute accelerator instance size 36 | // String instanceSize 37 | test('to test the property `instanceSize`', () async { 38 | // TODO 39 | }); 40 | 41 | // Compute accelerator instance type 42 | // String instanceType 43 | test('to test the property `instanceType`', () async { 44 | // TODO 45 | }); 46 | 47 | // Amount of RAM which can be requested per endpoint replica 48 | // int memoryGb 49 | test('to test the property `memoryGb`', () async { 50 | // TODO 51 | }); 52 | 53 | // Number of accelerator units which can be requested per endpoint replica 54 | // int numAccelerators 55 | test('to test the property `numAccelerators`', () async { 56 | // TODO 57 | }); 58 | 59 | // Number of CPUs which can be requested per endpoint replica 60 | // int numCpus 61 | test('to test the property `numCpus`', () async { 62 | // TODO 63 | }); 64 | 65 | // Price per hour in dollar of an endpoint replica 66 | // double pricePerHour 67 | test('to test the property `pricePerHour`', () async { 68 | // TODO 69 | }); 70 | 71 | // Status status 72 | test('to test the property `status`', () async { 73 | // TODO 74 | }); 75 | }); 76 | } 77 | -------------------------------------------------------------------------------- /lib/src/http/src/streamed_request.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:async'; 6 | 7 | import 'base_client.dart'; 8 | import 'base_request.dart'; 9 | import 'byte_stream.dart'; 10 | 11 | /// An HTTP request where the request body is sent asynchronously after the 12 | /// connection has been established and the headers have been sent. 13 | /// 14 | /// When the request is sent via [BaseClient.send], only the headers and 15 | /// whatever data has already been written to [StreamedRequest.sink] will be 16 | /// sent immediately. More data will be sent as soon as it's written to 17 | /// [StreamedRequest.sink], and when the sink is closed the request will end. 18 | /// 19 | /// For example: 20 | /// ```dart 21 | /// final request = http.StreamedRequest('POST', Uri.http('example.com', '')) 22 | /// ..contentLength = 10 23 | /// ..sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 24 | /// 25 | /// // The sink must be closed to end the request. 26 | /// // The Future returned from `close()` may not complete until after the 27 | /// // request is sent, and it should not be awaited. 28 | /// unawaited(request.sink.close()); 29 | /// final response = await request.send(); 30 | /// ``` 31 | class StreamedRequest extends BaseRequest { 32 | /// The sink to which to write data that will be sent as the request body. 33 | /// 34 | /// This may be safely written to before the request is sent; the data will be 35 | /// buffered. 36 | /// 37 | /// Closing this signals the end of the request. 38 | StreamSink> get sink => _controller.sink; 39 | 40 | /// The controller for [sink], from which [BaseRequest] will read data for 41 | /// [finalize]. 42 | final StreamController> _controller; 43 | 44 | /// Creates a new streaming request. 45 | StreamedRequest(super.method, super.url) 46 | : _controller = StreamController>(sync: true); 47 | 48 | /// Freezes all mutable fields and returns a single-subscription [ByteStream] 49 | /// that emits the data being written to [sink]. 50 | @override 51 | ByteStream finalize() { 52 | super.finalize(); 53 | return ByteStream(_controller.stream); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/src/openapi/api/v2provider_api.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class V2providerApi { 13 | V2providerApi([ApiClient? apiClient]) 14 | : apiClient = apiClient ?? defaultApiClient; 15 | 16 | final ApiClient apiClient; 17 | 18 | /// List vendors, regions and compute resources available 19 | /// 20 | /// List vendors, regions and compute resources available 21 | /// 22 | /// Note: This method returns the HTTP [Response]. 23 | Future _listVendorsWithHttpInfo() async { 24 | // ignore: prefer_const_declarations 25 | final path = r'/v2/provider'; 26 | 27 | // ignore: prefer_final_locals 28 | Object? postBody; 29 | 30 | final queryParams = []; 31 | final headerParams = {}; 32 | final formParams = {}; 33 | 34 | const contentTypes = ['application/json']; 35 | 36 | return apiClient.invokeAPI( 37 | path, 38 | 'GET', 39 | queryParams, 40 | postBody, 41 | headerParams, 42 | formParams, 43 | contentTypes.isEmpty ? null : contentTypes.first, 44 | ); 45 | } 46 | 47 | /// List vendors, regions and compute resources available 48 | /// 49 | /// List vendors, regions and compute resources available 50 | Future listVendors() async { 51 | final response = await _listVendorsWithHttpInfo(); 52 | if (response.statusCode >= HttpStatus.badRequest) { 53 | throw ApiException(response.statusCode, await _decodeBodyBytes(response)); 54 | } 55 | // When a remote server returns no body with a status of 204, we shall not decode it. 56 | // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" 57 | // FormatException when trying to decode an empty string. 58 | if (response.body.isNotEmpty && 59 | response.statusCode != HttpStatus.noContent) { 60 | return await apiClient.deserializeAsync( 61 | await _decodeBodyBytes(response), 62 | 'VendorList', 63 | ) as VendorList; 64 | } 65 | return null; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /example/nlp/inference_summarisation_task_api.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | import 'package:huggingface_client/huggingface_client.dart'; 9 | import '../api_key.dart'; 10 | 11 | /// Examples of how to use the Hugging Face Inference API to perform NLP 12 | /// task based model queries. 13 | 14 | void main() async { 15 | // Get an inference client with your Hugging Face API key as authentication. 16 | final client = HuggingFaceClient.getInferenceClient( 17 | inferenceApiKey, HuggingFaceClient.inferenceBasePath); 18 | 19 | // Get an instance of the inference API using our client 20 | final apiInstance = InferenceApi(client); 21 | 22 | // 23 | // Text summarisation task 24 | // 25 | print(''); 26 | print('*** Text Summarisation Task ***'); 27 | print(''); 28 | try { 29 | final input = 30 | 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest ' 31 | 'structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, ' 32 | 'the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, ' 33 | 'a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the ' 34 | 'first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of ' 35 | 'the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, ' 36 | 'the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.'; 37 | final params = ApiQueryNLPSummarisation(inputs: [input]); 38 | final result = await apiInstance.queryNLPSummarisation( 39 | taskParameters: params, model: 'facebook/bart-large-cnn'); 40 | if (result!.isNotEmpty) { 41 | for (final row in result) { 42 | print(row?.summaryText); 43 | } 44 | } else { 45 | print('Inference task API Text Summarisation returned empty result'); 46 | } 47 | } catch (e) { 48 | print( 49 | 'Exception when calling Inference task API Text Summarisation: $e - exiting'); 50 | return; 51 | } 52 | 53 | return; 54 | } 55 | -------------------------------------------------------------------------------- /lib/src/huggingface_client.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | class Unsafe { 11 | final String name; 12 | const Unsafe(this.name); 13 | } 14 | 15 | /// 16 | /// Hugging Face client class. 17 | /// Provides a thin wrapper around the Open API implementation. 18 | /// 19 | class HuggingFaceClient { 20 | /// Get an Inference Endpoint API client with API Key authentication. 21 | /// [endpointScope] is either your user name or one of your organization name. 22 | /// [basePath] the API base path i.e. [endpointBasePath] 23 | static EndpointApiClient getEndpointClient( 24 | String apiKey, String endpointScope, String basePath) => 25 | EndpointApiClient( 26 | authentication: ApiKeyAuth('header', 'Authorization') 27 | ..apiKey = apiKey 28 | ..apiKeyPrefix = 'Bearer', 29 | endpointScope: endpointScope, 30 | basePath: basePath); 31 | 32 | /// Get an Inference Endpoint Provider API client with API Key authentication. 33 | /// [endpointScope] is either your user name or one of your organization name. 34 | /// [basePath] the API base path i.e. [endpointBasePath] 35 | /// 36 | /// Note: according to the API spec for this call endpoint scope and authorization 37 | /// are not needed, however it does no harm to include them and it keeps the interface 38 | /// consistent across clients. 39 | static EndpointProviderApiClient getEndpointProviderClient( 40 | String apiKey, String endpointScope, String basePath) => 41 | EndpointProviderApiClient( 42 | authentication: ApiKeyAuth('header', 'Authorization') 43 | ..apiKey = apiKey 44 | ..apiKeyPrefix = 'Bearer', 45 | endpointScope: endpointScope, 46 | basePath: basePath); 47 | 48 | /// Get an Inference API client with API Key authentication. 49 | /// [basePath] the API base path i.e. [inferenceBasePath] 50 | static InferenceApiClient getInferenceClient( 51 | String apiKey, String basePath) => 52 | InferenceApiClient( 53 | authentication: ApiKeyAuth('header', 'Authorization') 54 | ..apiKey = apiKey 55 | ..apiKeyPrefix = 'Bearer', 56 | basePath: basePath); 57 | 58 | static String inferenceBasePath = 59 | 'https://api-inference.huggingface.co/models'; 60 | static String endpointBasePath = 'https://api.endpoints.huggingface.cloud'; 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/openapi/model/status.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | /// Resource status 13 | class Status { 14 | /// Instantiate a new enum with the provided [value]. 15 | const Status._(this.value); 16 | 17 | /// The underlying value of this enum member. 18 | final String value; 19 | 20 | @override 21 | String toString() => value; 22 | 23 | String toJson() => value; 24 | 25 | static const available = Status._(r'available'); 26 | static const notAvailable = Status._(r'notAvailable'); 27 | 28 | /// List of all possible values in this [enum][Status]. 29 | static const values = [ 30 | available, 31 | notAvailable, 32 | ]; 33 | 34 | static Status? fromJson(dynamic value) => 35 | StatusTypeTransformer().decode(value); 36 | 37 | static List listFromJson( 38 | dynamic json, { 39 | bool growable = false, 40 | }) { 41 | final result = []; 42 | if (json is List && json.isNotEmpty) { 43 | for (final row in json) { 44 | final value = Status.fromJson(row); 45 | if (value != null) { 46 | result.add(value); 47 | } 48 | } 49 | } 50 | return result.toList(growable: growable); 51 | } 52 | } 53 | 54 | /// Transformation class that can [encode] an instance of [Status] to String, 55 | /// and [decode] dynamic data back to [Status]. 56 | class StatusTypeTransformer { 57 | factory StatusTypeTransformer() => 58 | _instance ??= const StatusTypeTransformer._(); 59 | 60 | const StatusTypeTransformer._(); 61 | 62 | String encode(Status data) => data.value; 63 | 64 | /// Decodes a [dynamic value][data] to a Status. 65 | /// 66 | /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, 67 | /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] 68 | /// cannot be decoded successfully, then an [UnimplementedError] is thrown. 69 | /// 70 | /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, 71 | /// and users are still using an old app with the old code. 72 | Status? decode(dynamic data, {bool allowNull = true}) { 73 | if (data != null) { 74 | switch (data) { 75 | case r'available': 76 | return Status.available; 77 | case r'notAvailable': 78 | return Status.notAvailable; 79 | default: 80 | if (!allowNull) { 81 | throw ArgumentError('Unknown enum value to decode: $data'); 82 | } 83 | } 84 | } 85 | return null; 86 | } 87 | 88 | /// Singleton [StatusTypeTransformer] instance. 89 | static StatusTypeTransformer? _instance; 90 | } 91 | -------------------------------------------------------------------------------- /lib/src/openapi/model/accelerator.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | /// Compute accelerator 13 | class Accelerator { 14 | /// Instantiate a new enum with the provided [value]. 15 | const Accelerator._(this.value); 16 | 17 | /// The underlying value of this enum member. 18 | final String value; 19 | 20 | @override 21 | String toString() => value; 22 | 23 | String toJson() => value; 24 | 25 | static const cpu = Accelerator._(r'cpu'); 26 | static const gpu = Accelerator._(r'gpu'); 27 | 28 | /// List of all possible values in this [enum][Accelerator]. 29 | static const values = [ 30 | cpu, 31 | gpu, 32 | ]; 33 | 34 | static Accelerator? fromJson(dynamic value) => 35 | AcceleratorTypeTransformer().decode(value); 36 | 37 | static List listFromJson( 38 | dynamic json, { 39 | bool growable = false, 40 | }) { 41 | final result = []; 42 | if (json is List && json.isNotEmpty) { 43 | for (final row in json) { 44 | final value = Accelerator.fromJson(row); 45 | if (value != null) { 46 | result.add(value); 47 | } 48 | } 49 | } 50 | return result.toList(growable: growable); 51 | } 52 | } 53 | 54 | /// Transformation class that can [encode] an instance of [Accelerator] to String, 55 | /// and [decode] dynamic data back to [Accelerator]. 56 | class AcceleratorTypeTransformer { 57 | factory AcceleratorTypeTransformer() => 58 | _instance ??= const AcceleratorTypeTransformer._(); 59 | 60 | const AcceleratorTypeTransformer._(); 61 | 62 | String encode(Accelerator data) => data.value; 63 | 64 | /// Decodes a [dynamic value][data] to a Accelerator. 65 | /// 66 | /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, 67 | /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] 68 | /// cannot be decoded successfully, then an [UnimplementedError] is thrown. 69 | /// 70 | /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, 71 | /// and users are still using an old app with the old code. 72 | Accelerator? decode(dynamic data, {bool allowNull = true}) { 73 | if (data != null) { 74 | switch (data) { 75 | case r'cpu': 76 | return Accelerator.cpu; 77 | case r'gpu': 78 | return Accelerator.gpu; 79 | default: 80 | if (!allowNull) { 81 | throw ArgumentError('Unknown enum value to decode: $data'); 82 | } 83 | } 84 | } 85 | return null; 86 | } 87 | 88 | /// Singleton [AcceleratorTypeTransformer] instance. 89 | static AcceleratorTypeTransformer? _instance; 90 | } 91 | -------------------------------------------------------------------------------- /lib/src/http/src/utils.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:convert'; 7 | import 'dart:typed_data'; 8 | 9 | import 'byte_stream.dart'; 10 | 11 | /// Converts a [Map] from parameter names to values to a URL query string. 12 | /// 13 | /// mapToQuery({"foo": "bar", "baz": "bang"}); 14 | /// //=> "foo=bar&baz=bang" 15 | String mapToQuery(Map map, {Encoding? encoding}) { 16 | var pairs = >[]; 17 | map.forEach((key, value) => pairs.add([ 18 | Uri.encodeQueryComponent(key, encoding: encoding ?? utf8), 19 | Uri.encodeQueryComponent(value, encoding: encoding ?? utf8) 20 | ])); 21 | return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&'); 22 | } 23 | 24 | /// Returns the [Encoding] that corresponds to [charset]. 25 | /// 26 | /// Returns [fallback] if [charset] is null or if no [Encoding] was found that 27 | /// corresponds to [charset]. 28 | Encoding encodingForCharset(String? charset, [Encoding fallback = latin1]) { 29 | if (charset == null) return fallback; 30 | return Encoding.getByName(charset) ?? fallback; 31 | } 32 | 33 | /// Returns the [Encoding] that corresponds to [charset]. 34 | /// 35 | /// Throws a [FormatException] if no [Encoding] was found that corresponds to 36 | /// [charset]. 37 | /// 38 | /// [charset] may not be null. 39 | Encoding requiredEncodingForCharset(String charset) => 40 | Encoding.getByName(charset) ?? 41 | (throw FormatException('Unsupported encoding "$charset".')); 42 | 43 | /// A regular expression that matches strings that are composed entirely of 44 | /// ASCII-compatible characters. 45 | final _asciiOnly = RegExp(r'^[\x00-\x7F]+$'); 46 | 47 | /// Returns whether [string] is composed entirely of ASCII-compatible 48 | /// characters. 49 | bool isPlainAscii(String string) => _asciiOnly.hasMatch(string); 50 | 51 | /// Converts [input] into a [Uint8List]. 52 | /// 53 | /// If [input] is a [TypedData], this just returns a view on [input]. 54 | Uint8List toUint8List(List input) { 55 | if (input is Uint8List) return input; 56 | if (input is TypedData) { 57 | // TODO(nweiz): remove "as" when issue 11080 is fixed. 58 | return Uint8List.view((input as TypedData).buffer); 59 | } 60 | return Uint8List.fromList(input); 61 | } 62 | 63 | ByteStream toByteStream(Stream> stream) { 64 | if (stream is ByteStream) return stream; 65 | return ByteStream(stream); 66 | } 67 | 68 | /// Calls [onDone] once [stream] (a single-subscription [Stream]) is finished. 69 | /// 70 | /// The return value, also a single-subscription [Stream] should be used in 71 | /// place of [stream] after calling this method. 72 | Stream onDone(Stream stream, void Function() onDone) => 73 | stream.transform(StreamTransformer.fromHandlers(handleDone: (sink) { 74 | sink.close(); 75 | onDone(); 76 | })); 77 | -------------------------------------------------------------------------------- /test/v2endpoint_api_test.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | import 'package:huggingface_client/huggingface_client.dart'; 11 | import 'package:test/test.dart'; 12 | 13 | /// tests for V2endpointApi 14 | void main() { 15 | // final instance = V2endpointApi(); 16 | 17 | group('tests for V2endpointApi', () { 18 | // Create a new endpoint 19 | // 20 | // Create a new endpoint 21 | // 22 | //Future createEndpoint( UNKNOWN_PARAMETER_NAME, Endpoint endpoint) async 23 | test('test createEndpoint', () async { 24 | // TODO 25 | }); 26 | 27 | // Delete an endpoint 28 | // 29 | // Delete an endpoint 30 | // 31 | //Future deleteEndpoint( UNKNOWN_PARAMETER_NAME, String name) async 32 | test('test deleteEndpoint', () async { 33 | // TODO 34 | }); 35 | 36 | // Get endpoint information 37 | // 38 | // Get endpoint information 39 | // 40 | //Future getEndpoint( UNKNOWN_PARAMETER_NAME, String name) async 41 | test('test getEndpoint', () async { 42 | // TODO 43 | }); 44 | 45 | // Endpoint replicas logs 46 | // 47 | // Endpoint replicas logs 48 | // 49 | //Future getEndpointLogs( UNKNOWN_PARAMETER_NAME, String name, { int from, int to, int tail }) async 50 | test('test getEndpointLogs', () async { 51 | // TODO 52 | }); 53 | 54 | // Get endpoint metric 55 | // 56 | // Get endpoint metric 57 | // 58 | //Future getEndpointMetric( UNKNOWN_PARAMETER_NAME, String name, String metric) async 59 | test('test getEndpointMetric', () async { 60 | // TODO 61 | }); 62 | 63 | // List endpoints 64 | // 65 | // List endpoints 66 | // 67 | //Future listEndpoint( UNKNOWN_PARAMETER_NAME) async 68 | test('test listEndpoint', () async { 69 | // TODO 70 | }); 71 | 72 | // Pause endpoint 73 | // 74 | // Pause endpoint 75 | // 76 | //Future pauseEndpoint( UNKNOWN_PARAMETER_NAME, String name) async 77 | test('test pauseEndpoint', () async { 78 | // TODO 79 | }); 80 | 81 | // Resume endpoint 82 | // 83 | // Resume endpoint 84 | // 85 | //Future resumeEndpoint( UNKNOWN_PARAMETER_NAME, String name) async 86 | test('test resumeEndpoint', () async { 87 | // TODO 88 | }); 89 | 90 | // Update an endpoint 91 | // 92 | // Update an endpoint 93 | // 94 | //Future updateEndpoint( UNKNOWN_PARAMETER_NAME, String name, EndpointUpdate endpointUpdate) async 95 | test('test updateEndpoint', () async { 96 | // TODO 97 | }); 98 | }); 99 | } 100 | -------------------------------------------------------------------------------- /lib/src/openapi/api.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | 10 | // ignore: unnecessary_library_name 11 | library openapi.api; 12 | 13 | import 'dart:async'; 14 | import 'dart:convert'; 15 | import '../../api_dart_io_import.dart' 16 | if (dart.library.js_interop) '../../api_web_import.dart'; 17 | 18 | import '../http/http.dart'; 19 | import 'package:intl/intl.dart'; 20 | import 'package:meta/meta.dart'; 21 | 22 | part 'api_client.dart'; 23 | part 'api_helper.dart'; 24 | part 'api_exception.dart'; 25 | part 'auth/authentication.dart'; 26 | part 'auth/api_key_auth.dart'; 27 | part 'auth/oauth.dart'; 28 | part 'auth/http_basic_auth.dart'; 29 | part 'auth/http_bearer_auth.dart'; 30 | 31 | part 'api/v1endpoint_api.dart'; 32 | part 'api/v1provider_api.dart'; 33 | part 'api/v2endpoint_api.dart'; 34 | part 'api/v2provider_api.dart'; 35 | 36 | part 'model/accelerator.dart'; 37 | part 'model/api_response_error.dart'; 38 | part 'model/compute.dart'; 39 | part 'model/compute_list.dart'; 40 | part 'model/endpoint.dart'; 41 | part 'model/endpoint_accelerator.dart'; 42 | part 'model/endpoint_account.dart'; 43 | part 'model/endpoint_compute.dart'; 44 | part 'model/endpoint_compute_update.dart'; 45 | part 'model/endpoint_framework.dart'; 46 | part 'model/endpoint_image_credentials.dart'; 47 | part 'model/endpoint_model.dart'; 48 | part 'model/endpoint_model_image.dart'; 49 | part 'model/endpoint_model_image_one_of.dart'; 50 | part 'model/endpoint_model_image_one_of1.dart'; 51 | part 'model/endpoint_model_image_one_of1_custom.dart'; 52 | part 'model/endpoint_model_image_update.dart'; 53 | part 'model/endpoint_model_image_update_one_of.dart'; 54 | part 'model/endpoint_model_image_update_one_of_custom.dart'; 55 | part 'model/endpoint_model_update.dart'; 56 | part 'model/endpoint_provider.dart'; 57 | part 'model/endpoint_scaling.dart'; 58 | part 'model/endpoint_scaling_update.dart'; 59 | part 'model/endpoint_state.dart'; 60 | part 'model/endpoint_status.dart'; 61 | part 'model/endpoint_status_private.dart'; 62 | part 'model/endpoint_task.dart'; 63 | part 'model/endpoint_type.dart'; 64 | part 'model/endpoint_update.dart'; 65 | part 'model/endpoint_with_status.dart'; 66 | part 'model/endpoint_with_status_list.dart'; 67 | part 'model/metric_name.dart'; 68 | part 'model/metrics_params.dart'; 69 | part 'model/region.dart'; 70 | part 'model/region_list.dart'; 71 | part 'model/status.dart'; 72 | part 'model/vendor.dart'; 73 | part 'model/vendor_list.dart'; 74 | part 'model/vendors.dart'; 75 | 76 | const _delimiters = {'csv': ',', 'ssv': ' ', 'tsv': '\t', 'pipes': '|'}; 77 | const _dateEpochMarker = 'epoch'; 78 | final _dateFormatter = DateFormat('yyyy-MM-dd'); 79 | final _regList = RegExp(r'^List<(.*)>$'); 80 | final _regSet = RegExp(r'^Set<(.*)>$'); 81 | final _regMap = RegExp(r'^Map$'); 82 | 83 | ApiClient defaultApiClient = ApiClient(endpointScope: ''); 84 | -------------------------------------------------------------------------------- /lib/src/api/model/inference_options.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | // ignore_for_file: type=lint 8 | part of huggingface_client; 9 | 10 | /// 11 | /// Common inference options 12 | /// 13 | class InferenceOptions { 14 | InferenceOptions({this.useCache = true, this.waitForModel = false}); 15 | 16 | /// (Default: true). Boolean. There is a cache layer on the inference API to speedup requests we have already seen. 17 | /// Most models can use those results as is as models are deterministic (meaning the results will be the same anyway). 18 | /// However if you use a non deterministic model, you can set this parameter to prevent the caching mechanism from being 19 | /// used resulting in a real new query. 20 | bool useCache = true; 21 | 22 | /// (Default: false) Boolean. If the model is not ready, wait for it instead of receiving 503. It limits the number of requests 23 | /// required to get your inference done. It is advised to only set this flag to true after receiving a 503 24 | /// error as it will limit hanging in your application to known places. 25 | bool waitForModel = false; 26 | 27 | Map toJson() { 28 | final json = {}; 29 | json[r'options'] = {'use_cache': useCache, 'wait_for_model': waitForModel}; 30 | return json; 31 | } 32 | 33 | /// Returns a new [InferenceOptions] instance and imports its values from 34 | /// [value] if it's a [Map], null otherwise. 35 | // ignore: prefer_constructors_over_static_methods 36 | static InferenceOptions? fromJson(dynamic value) { 37 | if (value is Map) { 38 | final json = value.cast(); 39 | 40 | // Ensure that the map contains the required keys. 41 | // Note 1: the values aren't checked for validity beyond being non-null. 42 | // Note 2: this code is stripped in release mode! 43 | assert(() { 44 | for (var key in requiredKeys) { 45 | assert(json.containsKey(key), 46 | 'Required key "ApiResponseError[$key]" is missing from JSON.'); 47 | assert(json[key] != null, 48 | 'Required key "ApiResponseError[$key]" has a null value in JSON.'); 49 | } 50 | return true; 51 | }()); 52 | 53 | return InferenceOptions( 54 | useCache: mapValueOfType(json, r'use_cache')!, 55 | waitForModel: mapValueOfType(json, r'wait_for_model')!); 56 | } 57 | return null; 58 | } 59 | 60 | @override 61 | bool operator ==(Object other) => 62 | identical(this, other) || 63 | other is InferenceOptions && 64 | (other.useCache == useCache) && 65 | (other.waitForModel == waitForModel); 66 | 67 | @override 68 | int get hashCode => useCache.hashCode + waitForModel.hashCode; 69 | 70 | @override 71 | String toString() => 72 | 'InferenceOptions - [Use Cache=${useCache ? 'true' : 'false'}, Wait for model=${waitForModel ? 'true' : 'false'}]'; 73 | 74 | /// The list of required keys that must be present in a JSON. 75 | static const requiredKeys = {'use_cache', 'wait_for_model'}; 76 | } 77 | -------------------------------------------------------------------------------- /lib/src/openapi/model/endpoint_accelerator.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | /// Endpoint accelerator 13 | class EndpointAccelerator { 14 | /// Instantiate a new enum with the provided [value]. 15 | const EndpointAccelerator._(this.value); 16 | 17 | /// The underlying value of this enum member. 18 | final String value; 19 | 20 | @override 21 | String toString() => value; 22 | 23 | String toJson() => value; 24 | 25 | static const cpu = EndpointAccelerator._(r'cpu'); 26 | static const gpu = EndpointAccelerator._(r'gpu'); 27 | 28 | /// List of all possible values in this [enum][EndpointAccelerator]. 29 | static const values = [ 30 | cpu, 31 | gpu, 32 | ]; 33 | 34 | static EndpointAccelerator? fromJson(dynamic value) => 35 | EndpointAcceleratorTypeTransformer().decode(value); 36 | 37 | static List listFromJson( 38 | dynamic json, { 39 | bool growable = false, 40 | }) { 41 | final result = []; 42 | if (json is List && json.isNotEmpty) { 43 | for (final row in json) { 44 | final value = EndpointAccelerator.fromJson(row); 45 | if (value != null) { 46 | result.add(value); 47 | } 48 | } 49 | } 50 | return result.toList(growable: growable); 51 | } 52 | } 53 | 54 | /// Transformation class that can [encode] an instance of [EndpointAccelerator] to String, 55 | /// and [decode] dynamic data back to [EndpointAccelerator]. 56 | class EndpointAcceleratorTypeTransformer { 57 | factory EndpointAcceleratorTypeTransformer() => 58 | _instance ??= const EndpointAcceleratorTypeTransformer._(); 59 | 60 | const EndpointAcceleratorTypeTransformer._(); 61 | 62 | String encode(EndpointAccelerator data) => data.value; 63 | 64 | /// Decodes a [dynamic value][data] to a EndpointAccelerator. 65 | /// 66 | /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, 67 | /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] 68 | /// cannot be decoded successfully, then an [UnimplementedError] is thrown. 69 | /// 70 | /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, 71 | /// and users are still using an old app with the old code. 72 | EndpointAccelerator? decode(dynamic data, {bool allowNull = true}) { 73 | if (data != null) { 74 | switch (data) { 75 | case r'cpu': 76 | return EndpointAccelerator.cpu; 77 | case r'gpu': 78 | return EndpointAccelerator.gpu; 79 | default: 80 | if (!allowNull) { 81 | throw ArgumentError('Unknown enum value to decode: $data'); 82 | } 83 | } 84 | } 85 | return null; 86 | } 87 | 88 | /// Singleton [EndpointAcceleratorTypeTransformer] instance. 89 | static EndpointAcceleratorTypeTransformer? _instance; 90 | } 91 | -------------------------------------------------------------------------------- /lib/src/openapi/model/endpoint_type.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | /// Endpoint type. Public mean , private mean accessible only via a VPC 13 | class EndpointType { 14 | /// Instantiate a new enum with the provided [value]. 15 | const EndpointType._(this.value); 16 | 17 | /// The underlying value of this enum member. 18 | final String value; 19 | 20 | @override 21 | String toString() => value; 22 | 23 | String toJson() => value; 24 | 25 | static const public = EndpointType._(r'public'); 26 | static const protected = EndpointType._(r'protected'); 27 | static const private = EndpointType._(r'private'); 28 | 29 | /// List of all possible values in this [enum][EndpointType]. 30 | static const values = [ 31 | public, 32 | protected, 33 | private, 34 | ]; 35 | 36 | static EndpointType? fromJson(dynamic value) => 37 | EndpointTypeTypeTransformer().decode(value); 38 | 39 | static List listFromJson( 40 | dynamic json, { 41 | bool growable = false, 42 | }) { 43 | final result = []; 44 | if (json is List && json.isNotEmpty) { 45 | for (final row in json) { 46 | final value = EndpointType.fromJson(row); 47 | if (value != null) { 48 | result.add(value); 49 | } 50 | } 51 | } 52 | return result.toList(growable: growable); 53 | } 54 | } 55 | 56 | /// Transformation class that can [encode] an instance of [EndpointType] to String, 57 | /// and [decode] dynamic data back to [EndpointType]. 58 | class EndpointTypeTypeTransformer { 59 | factory EndpointTypeTypeTransformer() => 60 | _instance ??= const EndpointTypeTypeTransformer._(); 61 | 62 | const EndpointTypeTypeTransformer._(); 63 | 64 | String encode(EndpointType data) => data.value; 65 | 66 | /// Decodes a [dynamic value][data] to a EndpointType. 67 | /// 68 | /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, 69 | /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] 70 | /// cannot be decoded successfully, then an [UnimplementedError] is thrown. 71 | /// 72 | /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, 73 | /// and users are still using an old app with the old code. 74 | EndpointType? decode(dynamic data, {bool allowNull = true}) { 75 | if (data != null) { 76 | switch (data) { 77 | case r'public': 78 | return EndpointType.public; 79 | case r'protected': 80 | return EndpointType.protected; 81 | case r'private': 82 | return EndpointType.private; 83 | default: 84 | if (!allowNull) { 85 | throw ArgumentError('Unknown enum value to decode: $data'); 86 | } 87 | } 88 | } 89 | return null; 90 | } 91 | 92 | /// Singleton [EndpointTypeTypeTransformer] instance. 93 | static EndpointTypeTypeTransformer? _instance; 94 | } 95 | -------------------------------------------------------------------------------- /lib/src/openapi/model/endpoint_framework.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class EndpointFramework { 13 | /// Instantiate a new enum with the provided [value]. 14 | const EndpointFramework._(this.value); 15 | 16 | /// The underlying value of this enum member. 17 | final String value; 18 | 19 | @override 20 | String toString() => value; 21 | 22 | String toJson() => value; 23 | 24 | static const custom = EndpointFramework._(r'custom'); 25 | static const pytorch = EndpointFramework._(r'pytorch'); 26 | static const tensorflow = EndpointFramework._(r'tensorflow'); 27 | 28 | /// List of all possible values in this [enum][EndpointFramework]. 29 | static const values = [ 30 | custom, 31 | pytorch, 32 | tensorflow, 33 | ]; 34 | 35 | static EndpointFramework? fromJson(dynamic value) => 36 | EndpointFrameworkTypeTransformer().decode(value); 37 | 38 | static List listFromJson( 39 | dynamic json, { 40 | bool growable = false, 41 | }) { 42 | final result = []; 43 | if (json is List && json.isNotEmpty) { 44 | for (final row in json) { 45 | final value = EndpointFramework.fromJson(row); 46 | if (value != null) { 47 | result.add(value); 48 | } 49 | } 50 | } 51 | return result.toList(growable: growable); 52 | } 53 | } 54 | 55 | /// Transformation class that can [encode] an instance of [EndpointFramework] to String, 56 | /// and [decode] dynamic data back to [EndpointFramework]. 57 | class EndpointFrameworkTypeTransformer { 58 | factory EndpointFrameworkTypeTransformer() => 59 | _instance ??= const EndpointFrameworkTypeTransformer._(); 60 | 61 | const EndpointFrameworkTypeTransformer._(); 62 | 63 | String encode(EndpointFramework data) => data.value; 64 | 65 | /// Decodes a [dynamic value][data] to a EndpointFramework. 66 | /// 67 | /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully, 68 | /// then null is returned. However, if [allowNull] is false and the [dynamic value][data] 69 | /// cannot be decoded successfully, then an [UnimplementedError] is thrown. 70 | /// 71 | /// The [allowNull] is very handy when an API changes and a new enum value is added or removed, 72 | /// and users are still using an old app with the old code. 73 | EndpointFramework? decode(dynamic data, {bool allowNull = true}) { 74 | if (data != null) { 75 | switch (data) { 76 | case r'custom': 77 | return EndpointFramework.custom; 78 | case r'pytorch': 79 | return EndpointFramework.pytorch; 80 | case r'tensorflow': 81 | return EndpointFramework.tensorflow; 82 | default: 83 | if (!allowNull) { 84 | throw ArgumentError('Unknown enum value to decode: $data'); 85 | } 86 | } 87 | } 88 | return null; 89 | } 90 | 91 | /// Singleton [EndpointFrameworkTypeTransformer] instance. 92 | static EndpointFrameworkTypeTransformer? _instance; 93 | } 94 | -------------------------------------------------------------------------------- /lib/huggingface_client.dart: -------------------------------------------------------------------------------- 1 | /* 2 | * Package : huggingface_client 3 | * Author : S. Hamblett 4 | * Date : 02/08/2023 5 | * Copyright : S.Hamblett 6 | */ 7 | 8 | // ignore: unnecessary_library_name 9 | library huggingface_client; 10 | 11 | import 'package:huggingface_client/src/api/api/response_transformers.dart'; 12 | import 'package:meta/meta.dart'; 13 | 14 | import 'api_dart_io_import.dart' 15 | if (dart.library.js_interop) 'api_web_import.dart'; 16 | import 'dart:convert'; 17 | import 'dart:typed_data'; 18 | 19 | import 'package:huggingface_client/src/openapi/api.dart'; 20 | export 'package:huggingface_client/src/openapi/api.dart'; 21 | import 'package:huggingface_client/src/http/http.dart'; 22 | export 'package:huggingface_client/src/http/http.dart'; 23 | 24 | part 'src/huggingface_client.dart'; 25 | part 'src/api/endpoint_api_client.dart'; 26 | part 'src/api/inference_api_client.dart'; 27 | part 'src/api/endpoint_provider_api_client.dart'; 28 | part 'src/api/api/inference_api.dart'; 29 | part 'src/api/model/inference_options.dart'; 30 | part 'src/api/model/api_response_query_standard.dart'; 31 | part 'src/api/model/api_query_nlp_fill_mask.dart'; 32 | part 'src/api/model/api_response_nlp_fill_mask.dart'; 33 | part 'src/api/model/api_query_nlp_summarisation.dart'; 34 | part 'src/api/model/api_response_nlp_summarisation.dart'; 35 | part 'src/api/model/api_query_nlp_qa.dart'; 36 | part 'src/api/model/api_response_nlp_qa.dart'; 37 | part 'src/api/model/api_query_nlp_table_qa.dart'; 38 | part 'src/api/model/api_response_nlp_table_qa.dart'; 39 | part 'src/api/model/api_query_nlp_sentence_similarity.dart'; 40 | part 'src/api/model/api_response_nlp_sentence_similarity.dart'; 41 | part 'src/api/model/api_query_nlp_text_classification.dart'; 42 | part 'src/api/model/api_response_nlp_text_classification.dart'; 43 | part 'src/api/model/api_query_nlp_text_generation.dart'; 44 | part 'src/api/model/api_response_nlp_text_generation.dart'; 45 | part 'src/api/model/api_response_text_to_image.dart'; 46 | part 'src/api/model/api_query_nlp_token_classification.dart'; 47 | part 'src/api/model/api_response_nlp_token_classification.dart'; 48 | part 'src/api/model/api_query_nlp_translation.dart'; 49 | part 'src/api/model/api_response_nlp_translation.dart'; 50 | part 'src/api/model/api_query_nlp_zero_shot_classification.dart'; 51 | part 'src/api/model/api_response_nlp_zero_shot_classification.dart'; 52 | part 'src/api/model/api_query_nlp_conversational.dart'; 53 | part 'src/api/model/api_query_nlp_chat_completion.dart'; 54 | part 'src/api/model/api_response_chat_completion.dart'; 55 | part 'src/api/model/api_response_nlp_conversational.dart'; 56 | part 'src/api/model/api_query_nlp_feature_extraction.dart'; 57 | part 'src/api/model/api_response_nlp_feature_extraction.dart'; 58 | part 'src/api/model/api_response_audio_asr.dart'; 59 | part 'src/api/model/api_response_audio_classification.dart'; 60 | part 'src/api/model/api_response_vision_image_classification.dart'; 61 | part 'src/api/model/api_response_vision_object_detection.dart'; 62 | part 'src/api/model/api_response_vision_image_segmentation.dart'; 63 | part 'src/openapi/api/endpoint_api.dart'; 64 | part 'src/openapi/api/endpoint_provider_api.dart'; 65 | 66 | final _regList = RegExp(r'^List<(.*)>$'); 67 | final _regSet = RegExp(r'^Set<(.*)>$'); 68 | final _regMap = RegExp(r'^Map$'); 69 | 70 | InferenceApiClient defaultInferenceApiClient = InferenceApiClient(); 71 | -------------------------------------------------------------------------------- /lib/src/http/src/response.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:convert'; 6 | import 'dart:typed_data'; 7 | 8 | import 'package:http_parser/http_parser.dart'; 9 | 10 | import 'base_request.dart'; 11 | import 'base_response.dart'; 12 | import 'streamed_response.dart'; 13 | import 'utils.dart'; 14 | 15 | /// An HTTP response where the entire response body is known in advance. 16 | class Response extends BaseResponse { 17 | /// The bytes comprising the body of this response. 18 | final Uint8List bodyBytes; 19 | 20 | /// The body of the response as a string. 21 | /// 22 | /// This is converted from [bodyBytes] using the `charset` parameter of the 23 | /// `Content-Type` header field, if available. If it's unavailable or if the 24 | /// encoding name is unknown, [latin1] is used by default, as per 25 | /// [RFC 2616][]. 26 | /// 27 | /// [RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html 28 | String get body => _encodingForHeaders(headers).decode(bodyBytes); 29 | 30 | /// Creates a new HTTP response with a string body. 31 | Response(String body, int statusCode, 32 | {BaseRequest? request, 33 | Map headers = const {}, 34 | bool isRedirect = false, 35 | bool persistentConnection = true, 36 | String? reasonPhrase}) 37 | : this.bytes(_encodingForHeaders(headers).encode(body), statusCode, 38 | request: request, 39 | headers: headers, 40 | isRedirect: isRedirect, 41 | persistentConnection: persistentConnection, 42 | reasonPhrase: reasonPhrase); 43 | 44 | /// Create a new HTTP response with a byte array body. 45 | Response.bytes(List bodyBytes, super.statusCode, 46 | {super.request, 47 | super.headers, 48 | super.isRedirect, 49 | super.persistentConnection, 50 | super.reasonPhrase}) 51 | : bodyBytes = toUint8List(bodyBytes), 52 | super(contentLength: bodyBytes.length); 53 | 54 | /// Creates a new HTTP response by waiting for the full body to become 55 | /// available from a [StreamedResponse]. 56 | static Future fromStream(StreamedResponse response) async { 57 | final body = await response.stream.toBytes(); 58 | return Response.bytes(body, response.statusCode, 59 | request: response.request, 60 | headers: response.headers, 61 | isRedirect: response.isRedirect, 62 | persistentConnection: response.persistentConnection, 63 | reasonPhrase: response.reasonPhrase); 64 | } 65 | } 66 | 67 | /// Returns the encoding to use for a response with the given headers. 68 | /// 69 | /// Defaults to [latin1] if the headers don't specify a charset or if that 70 | /// charset is unknown. 71 | Encoding _encodingForHeaders(Map headers) => 72 | encodingForCharset(_contentTypeForHeaders(headers).parameters['charset']); 73 | 74 | /// Returns the [MediaType] object for the given headers's content-type. 75 | /// 76 | /// Defaults to `application/octet-stream`. 77 | MediaType _contentTypeForHeaders(Map headers) { 78 | var contentType = headers['content-type']; 79 | if (contentType != null) return MediaType.parse(contentType); 80 | return MediaType('application', 'octet-stream'); 81 | } 82 | -------------------------------------------------------------------------------- /lib/src/http/src/mock_client.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'base_client.dart'; 6 | import 'base_request.dart'; 7 | import 'byte_stream.dart'; 8 | import 'request.dart'; 9 | import 'response.dart'; 10 | import 'streamed_request.dart'; 11 | import 'streamed_response.dart'; 12 | 13 | // TODO(nweiz): once Dart has some sort of Rack- or WSGI-like standard for 14 | // server APIs, MockClient should conform to it. 15 | 16 | /// A mock HTTP client designed for use when testing code that uses 17 | /// [BaseClient]. 18 | /// 19 | /// This client allows you to define a handler callback for all requests that 20 | /// are made through it so that you can mock a server without having to send 21 | /// real HTTP requests. 22 | class MockClient extends BaseClient { 23 | /// The handler for receiving [StreamedRequest]s and sending 24 | /// [StreamedResponse]s. 25 | final MockClientStreamHandler _handler; 26 | 27 | MockClient._(this._handler); 28 | 29 | /// Creates a [MockClient] with a handler that receives [Request]s and sends 30 | /// [Response]s. 31 | MockClient(MockClientHandler fn) 32 | : this._((baseRequest, bodyStream) async { 33 | final bodyBytes = await bodyStream.toBytes(); 34 | var request = Request(baseRequest.method, baseRequest.url) 35 | ..persistentConnection = baseRequest.persistentConnection 36 | ..followRedirects = baseRequest.followRedirects 37 | ..maxRedirects = baseRequest.maxRedirects 38 | ..headers.addAll(baseRequest.headers) 39 | ..bodyBytes = bodyBytes 40 | ..finalize(); 41 | 42 | final response = await fn(request); 43 | return StreamedResponse( 44 | ByteStream.fromBytes(response.bodyBytes), response.statusCode, 45 | contentLength: response.contentLength, 46 | request: response.request, 47 | headers: response.headers, 48 | isRedirect: response.isRedirect, 49 | persistentConnection: response.persistentConnection, 50 | reasonPhrase: response.reasonPhrase); 51 | }); 52 | 53 | /// Creates a [MockClient] with a handler that receives [StreamedRequest]s and 54 | /// sends [StreamedResponse]s. 55 | MockClient.streaming(MockClientStreamHandler fn) 56 | : this._((request, bodyStream) async { 57 | final response = await fn(request, bodyStream); 58 | return StreamedResponse(response.stream, response.statusCode, 59 | contentLength: response.contentLength, 60 | request: response.request, 61 | headers: response.headers, 62 | isRedirect: response.isRedirect, 63 | persistentConnection: response.persistentConnection, 64 | reasonPhrase: response.reasonPhrase); 65 | }); 66 | 67 | @override 68 | Future send(BaseRequest request) async { 69 | var bodyStream = request.finalize(); 70 | return await _handler(request, bodyStream); 71 | } 72 | } 73 | 74 | /// A handler function that receives [StreamedRequest]s and sends 75 | /// [StreamedResponse]s. 76 | /// 77 | /// Note that [request] will be finalized. 78 | typedef MockClientStreamHandler = Future Function( 79 | BaseRequest request, ByteStream bodyStream); 80 | 81 | /// A handler function that receives [Request]s and sends [Response]s. 82 | /// 83 | /// Note that [request] will be finalized. 84 | typedef MockClientHandler = Future Function(Request request); 85 | -------------------------------------------------------------------------------- /lib/src/openapi/model/vendors.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class Vendors { 13 | /// Returns a new [Vendors] instance. 14 | Vendors({ 15 | this.vendors = const [], 16 | }); 17 | 18 | /// Vendors list 19 | List vendors; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || other is Vendors && other.vendors == vendors; 24 | 25 | @override 26 | int get hashCode => 27 | // ignore: unnecessary_parenthesis 28 | (vendors.hashCode); 29 | 30 | @override 31 | String toString() => 'Vendors[vendors=$vendors]'; 32 | 33 | Map toJson() { 34 | final json = {}; 35 | json[r'vendors'] = vendors; 36 | return json; 37 | } 38 | 39 | /// Returns a new [Vendors] instance and imports its values from 40 | /// [value] if it's a [Map], null otherwise. 41 | // ignore: prefer_constructors_over_static_methods 42 | static Vendors? fromJson(dynamic value) { 43 | if (value is Map) { 44 | final json = value.cast(); 45 | 46 | // Ensure that the map contains the required keys. 47 | // Note 1: the values aren't checked for validity beyond being non-null. 48 | // Note 2: this code is stripped in release mode! 49 | assert(() { 50 | for (var key in requiredKeys) { 51 | assert(json.containsKey(key), 52 | 'Required key "Vendors[$key]" is missing from JSON.'); 53 | assert(json[key] != null, 54 | 'Required key "Vendors[$key]" has a null value in JSON.'); 55 | } 56 | return true; 57 | }()); 58 | 59 | return Vendors( 60 | vendors: Vendor.listFromJson(json[r'vendors']), 61 | ); 62 | } 63 | return null; 64 | } 65 | 66 | static List listFromJson( 67 | dynamic json, { 68 | bool growable = false, 69 | }) { 70 | final result = []; 71 | if (json is List && json.isNotEmpty) { 72 | for (final row in json) { 73 | final value = Vendors.fromJson(row); 74 | if (value != null) { 75 | result.add(value); 76 | } 77 | } 78 | } 79 | return result.toList(growable: growable); 80 | } 81 | 82 | static Map mapFromJson(dynamic json) { 83 | final map = {}; 84 | if (json is Map && json.isNotEmpty) { 85 | json = json.cast(); // ignore: parameter_assignments 86 | for (final entry in json.entries) { 87 | final value = Vendors.fromJson(entry.value); 88 | if (value != null) { 89 | map[entry.key] = value; 90 | } 91 | } 92 | } 93 | return map; 94 | } 95 | 96 | // maps a json object with a list of Vendors-objects as value to a dart map 97 | static Map> mapListFromJson( 98 | dynamic json, { 99 | bool growable = false, 100 | }) { 101 | final map = >{}; 102 | if (json is Map && json.isNotEmpty) { 103 | // ignore: parameter_assignments 104 | json = json.cast(); 105 | for (final entry in json.entries) { 106 | map[entry.key] = Vendors.listFromJson( 107 | entry.value, 108 | growable: growable, 109 | ); 110 | } 111 | } 112 | return map; 113 | } 114 | 115 | /// The list of required keys that must be present in a JSON. 116 | static const requiredKeys = { 117 | 'vendors', 118 | }; 119 | } 120 | -------------------------------------------------------------------------------- /lib/src/openapi/model/vendor_list.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class VendorList { 13 | /// Returns a new [VendorList] instance. 14 | VendorList({ 15 | this.items = const [], 16 | }); 17 | 18 | /// Vendors list 19 | List items; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || other is VendorList && other.items == items; 24 | 25 | @override 26 | int get hashCode => 27 | // ignore: unnecessary_parenthesis 28 | (items.hashCode); 29 | 30 | @override 31 | String toString() => 'VendorList[items=$items]'; 32 | 33 | Map toJson() { 34 | final json = {}; 35 | json[r'items'] = items; 36 | return json; 37 | } 38 | 39 | /// Returns a new [VendorList] instance and imports its values from 40 | /// [value] if it's a [Map], null otherwise. 41 | // ignore: prefer_constructors_over_static_methods 42 | static VendorList? fromJson(dynamic value) { 43 | if (value is Map) { 44 | final json = value.cast(); 45 | 46 | // Ensure that the map contains the required keys. 47 | // Note 1: the values aren't checked for validity beyond being non-null. 48 | // Note 2: this code is stripped in release mode! 49 | assert(() { 50 | for (var key in requiredKeys) { 51 | assert(json.containsKey(key), 52 | 'Required key "VendorList[$key]" is missing from JSON.'); 53 | assert(json[key] != null, 54 | 'Required key "VendorList[$key]" has a null value in JSON.'); 55 | } 56 | return true; 57 | }()); 58 | 59 | return VendorList( 60 | items: Vendor.listFromJson(json[r'vendors']), 61 | ); 62 | } 63 | return null; 64 | } 65 | 66 | static List listFromJson( 67 | dynamic json, { 68 | bool growable = false, 69 | }) { 70 | final result = []; 71 | if (json is List && json.isNotEmpty) { 72 | for (final row in json) { 73 | final value = VendorList.fromJson(row); 74 | if (value != null) { 75 | result.add(value); 76 | } 77 | } 78 | } 79 | return result.toList(growable: growable); 80 | } 81 | 82 | static Map mapFromJson(dynamic json) { 83 | final map = {}; 84 | if (json is Map && json.isNotEmpty) { 85 | json = json.cast(); // ignore: parameter_assignments 86 | for (final entry in json.entries) { 87 | final value = VendorList.fromJson(entry.value); 88 | if (value != null) { 89 | map[entry.key] = value; 90 | } 91 | } 92 | } 93 | return map; 94 | } 95 | 96 | // maps a json object with a list of VendorList-objects as value to a dart map 97 | static Map> mapListFromJson( 98 | dynamic json, { 99 | bool growable = false, 100 | }) { 101 | final map = >{}; 102 | if (json is Map && json.isNotEmpty) { 103 | // ignore: parameter_assignments 104 | json = json.cast(); 105 | for (final entry in json.entries) { 106 | map[entry.key] = VendorList.listFromJson( 107 | entry.value, 108 | growable: growable, 109 | ); 110 | } 111 | } 112 | return map; 113 | } 114 | 115 | /// The list of required keys that must be present in a JSON. 116 | static const requiredKeys = { 117 | 'vendors', 118 | }; 119 | } 120 | -------------------------------------------------------------------------------- /lib/src/openapi/model/region_list.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class RegionList { 13 | /// Returns a new [RegionList] instance. 14 | RegionList({ 15 | this.items = const [], 16 | }); 17 | 18 | /// Vendor regions list 19 | List items; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || other is RegionList && other.items == items; 24 | 25 | @override 26 | int get hashCode => 27 | // ignore: unnecessary_parenthesis 28 | (items.hashCode); 29 | 30 | @override 31 | String toString() => 'RegionList[items=$items]'; 32 | 33 | Map toJson() { 34 | final json = {}; 35 | json[r'items'] = items; 36 | return json; 37 | } 38 | 39 | /// Returns a new [RegionList] instance and imports its values from 40 | /// [value] if it's a [Map], null otherwise. 41 | // ignore: prefer_constructors_over_static_methods 42 | static RegionList? fromJson(dynamic value) { 43 | if (value is Map) { 44 | final json = value.cast(); 45 | 46 | // Ensure that the map contains the required keys. 47 | // Note 1: the values aren't checked for validity beyond being non-null. 48 | // Note 2: this code is stripped in release mode! 49 | assert(() { 50 | for (var key in requiredKeys) { 51 | assert(json.containsKey(key), 52 | 'Required key "RegionList[$key]" is missing from JSON.'); 53 | assert(json[key] != null, 54 | 'Required key "RegionList[$key]" has a null value in JSON.'); 55 | } 56 | return true; 57 | }()); 58 | 59 | return RegionList( 60 | items: Region.listFromJson(json[r'items']), 61 | ); 62 | } 63 | return null; 64 | } 65 | 66 | static List listFromJson( 67 | dynamic json, { 68 | bool growable = false, 69 | }) { 70 | final result = []; 71 | if (json is List && json.isNotEmpty) { 72 | for (final row in json) { 73 | final value = RegionList.fromJson(row); 74 | if (value != null) { 75 | result.add(value); 76 | } 77 | } 78 | } 79 | return result.toList(growable: growable); 80 | } 81 | 82 | static Map mapFromJson(dynamic json) { 83 | final map = {}; 84 | if (json is Map && json.isNotEmpty) { 85 | json = json.cast(); // ignore: parameter_assignments 86 | for (final entry in json.entries) { 87 | final value = RegionList.fromJson(entry.value); 88 | if (value != null) { 89 | map[entry.key] = value; 90 | } 91 | } 92 | } 93 | return map; 94 | } 95 | 96 | // maps a json object with a list of RegionList-objects as value to a dart map 97 | static Map> mapListFromJson( 98 | dynamic json, { 99 | bool growable = false, 100 | }) { 101 | final map = >{}; 102 | if (json is Map && json.isNotEmpty) { 103 | // ignore: parameter_assignments 104 | json = json.cast(); 105 | for (final entry in json.entries) { 106 | map[entry.key] = RegionList.listFromJson( 107 | entry.value, 108 | growable: growable, 109 | ); 110 | } 111 | } 112 | return map; 113 | } 114 | 115 | /// The list of required keys that must be present in a JSON. 116 | static const requiredKeys = { 117 | 'items', 118 | }; 119 | } 120 | -------------------------------------------------------------------------------- /lib/src/http/src/browser_client.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file 2 | // for details. All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | import 'dart:async'; 6 | import 'dart:js_interop'; 7 | 8 | import 'package:web/web.dart'; 9 | 10 | import 'base_client.dart'; 11 | import 'base_request.dart'; 12 | import 'byte_stream.dart'; 13 | import 'exception.dart'; 14 | import 'streamed_response.dart'; 15 | 16 | /// Create a [BrowserClient]. 17 | /// 18 | /// Used from conditional imports, matches the definition in `client_stub.dart`. 19 | BaseClient createClient() { 20 | if (const bool.fromEnvironment('no_default_http_client')) { 21 | throw StateError('no_default_http_client was defined but runWithClient ' 22 | 'was not used to configure a Client implementation.'); 23 | } 24 | return BrowserClient(); 25 | } 26 | 27 | /// A `package:web`-based HTTP client that runs in the browser and is backed by 28 | /// XMLHttpRequests. 29 | /// 30 | /// This client inherits some of the limitations of XMLHttpRequest. It ignores 31 | /// the [BaseRequest.contentLength], [BaseRequest.persistentConnection], 32 | /// [BaseRequest.followRedirects], and [BaseRequest.maxRedirects] fields. It is 33 | /// also unable to stream requests or responses; a request will only be sent and 34 | /// a response will only be returned once all the data is available. 35 | class BrowserClient extends BaseClient { 36 | /// The currently active XHRs. 37 | /// 38 | /// These are aborted if the client is closed. 39 | final _xhrs = {}; 40 | 41 | /// Whether to send credentials such as cookies or authorization headers for 42 | /// cross-site requests. 43 | /// 44 | /// Defaults to `false`. 45 | bool withCredentials = false; 46 | 47 | bool _isClosed = false; 48 | 49 | /// Sends an HTTP request and asynchronously returns the response. 50 | @override 51 | Future send(BaseRequest request) async { 52 | if (_isClosed) { 53 | throw ClientException( 54 | 'HTTP request failed. Client is already closed.', request.url); 55 | } 56 | var bytes = await request.finalize().toBytes(); 57 | var xhr = XMLHttpRequest(); 58 | _xhrs.add(xhr); 59 | xhr 60 | ..open(request.method, '${request.url}', true) 61 | ..responseType = 'arraybuffer' 62 | ..withCredentials = withCredentials; 63 | 64 | for (final MapEntry entry in request.headers.entries) { 65 | xhr.setRequestHeader(entry.key, entry.value); 66 | } 67 | 68 | var completer = Completer(); 69 | 70 | unawaited(xhr.onLoad.first.then((_) { 71 | var body = (xhr.response as JSArrayBuffer).toDart.asUint8List(); 72 | completer.complete(StreamedResponse( 73 | ByteStream.fromBytes(body), xhr.status, 74 | contentLength: body.length, 75 | request: request, 76 | headers: xhr.responseHeaders, 77 | reasonPhrase: xhr.statusText)); 78 | })); 79 | 80 | unawaited(xhr.onError.first.then((_) { 81 | // Unfortunately, the underlying XMLHttpRequest API doesn't expose any 82 | // specific information about the error itself. 83 | completer.completeError( 84 | ClientException('XMLHttpRequest error.', request.url), 85 | StackTrace.current); 86 | })); 87 | 88 | xhr.send(bytes.jsify()); 89 | 90 | try { 91 | return await completer.future; 92 | } finally { 93 | _xhrs.remove(xhr); 94 | } 95 | } 96 | 97 | /// Closes the client. 98 | /// 99 | /// This terminates all active requests. 100 | @override 101 | void close() { 102 | _isClosed = true; 103 | for (var xhr in _xhrs) { 104 | xhr.abort(); 105 | } 106 | _xhrs.clear(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /lib/src/openapi/model/compute_list.dart: -------------------------------------------------------------------------------- 1 | // 2 | // AUTO-GENERATED FILE, DO NOT MODIFY! 3 | // 4 | 5 | // ignore_for_file: unused_element, unused_import 6 | // ignore_for_file: always_put_required_named_parameters_first 7 | // ignore_for_file: constant_identifier_names 8 | // ignore_for_file: lines_longer_than_80_chars 9 | // ignore_for_file: type=lint 10 | part of openapi.api; 11 | 12 | class ComputeList { 13 | /// Returns a new [ComputeList] instance. 14 | ComputeList({ 15 | this.items = const [], 16 | }); 17 | 18 | /// Vendor region compute resources list 19 | List items; 20 | 21 | @override 22 | bool operator ==(Object other) => 23 | identical(this, other) || other is ComputeList && other.items == items; 24 | 25 | @override 26 | int get hashCode => 27 | // ignore: unnecessary_parenthesis 28 | (items.hashCode); 29 | 30 | @override 31 | String toString() => 'ComputeList[items=$items]'; 32 | 33 | Map toJson() { 34 | final json = {}; 35 | json[r'items'] = items; 36 | return json; 37 | } 38 | 39 | /// Returns a new [ComputeList] instance and imports its values from 40 | /// [value] if it's a [Map], null otherwise. 41 | // ignore: prefer_constructors_over_static_methods 42 | static ComputeList? fromJson(dynamic value) { 43 | if (value is Map) { 44 | final json = value.cast(); 45 | 46 | // Ensure that the map contains the required keys. 47 | // Note 1: the values aren't checked for validity beyond being non-null. 48 | // Note 2: this code is stripped in release mode! 49 | assert(() { 50 | for (var key in requiredKeys) { 51 | assert(json.containsKey(key), 52 | 'Required key "ComputeList[$key]" is missing from JSON.'); 53 | assert(json[key] != null, 54 | 'Required key "ComputeList[$key]" has a null value in JSON.'); 55 | } 56 | return true; 57 | }()); 58 | 59 | return ComputeList( 60 | items: Compute.listFromJson(json[r'items']), 61 | ); 62 | } 63 | return null; 64 | } 65 | 66 | static List listFromJson( 67 | dynamic json, { 68 | bool growable = false, 69 | }) { 70 | final result = []; 71 | if (json is List && json.isNotEmpty) { 72 | for (final row in json) { 73 | final value = ComputeList.fromJson(row); 74 | if (value != null) { 75 | result.add(value); 76 | } 77 | } 78 | } 79 | return result.toList(growable: growable); 80 | } 81 | 82 | static Map mapFromJson(dynamic json) { 83 | final map = {}; 84 | if (json is Map && json.isNotEmpty) { 85 | json = json.cast(); // ignore: parameter_assignments 86 | for (final entry in json.entries) { 87 | final value = ComputeList.fromJson(entry.value); 88 | if (value != null) { 89 | map[entry.key] = value; 90 | } 91 | } 92 | } 93 | return map; 94 | } 95 | 96 | // maps a json object with a list of ComputeList-objects as value to a dart map 97 | static Map> mapListFromJson( 98 | dynamic json, { 99 | bool growable = false, 100 | }) { 101 | final map = >{}; 102 | if (json is Map && json.isNotEmpty) { 103 | // ignore: parameter_assignments 104 | json = json.cast(); 105 | for (final entry in json.entries) { 106 | map[entry.key] = ComputeList.listFromJson( 107 | entry.value, 108 | growable: growable, 109 | ); 110 | } 111 | } 112 | return map; 113 | } 114 | 115 | /// The list of required keys that must be present in a JSON. 116 | static const requiredKeys = { 117 | 'items', 118 | }; 119 | } 120 | --------------------------------------------------------------------------------