Skip to content

Commit

Permalink
com.rest.huggingface 1.0.0-preview.15 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Jan 26, 2024
1 parent a0b0452 commit ad9d57c
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 86 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/upm-subtree-split.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,8 @@ jobs:
upm-subtree-split:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: upm subtree split
run: |
# upm subtree split
git config user.name github-actions
git config user.email [email protected]
$packageDir = Get-Item -Path "**/Packages/com.*" | Select-Object -ExpandProperty FullName
$packageDir = $packageDir.replace('${{ github.workspace }}/','')
Write-Host $packageDir
git subtree split --prefix="$packageDir" -b upm
git checkout upm
git fetch origin upm
git rebase origin/upm --reapply-cherry-picks
git push origin upm --force-with-lease --tags --set-upstream --verbose
working-directory: ${{ github.workspace }}
shell: pwsh
- uses: RageAgainstThePixel/upm-subtree-split@v1
81 changes: 43 additions & 38 deletions HuggingFace/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options
root = true
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options

# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

[*.cs]

Expand All @@ -12,6 +12,8 @@ indent_size = 4
indent_style = space
tab_width = 4

file_header_template = Licensed under the MIT License. See LICENSE in the project root for license information.

# New line preferences
end_of_line = crlf
insert_final_newline = true
Expand All @@ -37,39 +39,42 @@ csharp_style_var_when_type_is_apparent = true
#### Resharper/Rider Rules ####
# https://www.jetbrains.com/help/resharper/EditorConfig_Properties.html

resharper_csharp_force_attribute_style=separate
csharp_place_field_attribute_on_same_line=false
csharp_place_accessorholder_attribute_on_same_line=false
csharp_trailing_comma_in_multiline_lists=false
csharp_trailing_comma_in_singleline_lists=false
csharp_keep_existing_attribute_arrangement=false
csharp_blank_lines_around_region=1
csharp_blank_lines_inside_region=1
csharp_keep_blank_lines_in_code=false
csharp_remove_blank_lines_near_braces_in_code=true
csharp_blank_lines_before_control_transfer_statements=1
csharp_blank_lines_after_control_transfer_statements=1
csharp_blank_lines_before_block_statements=1
csharp_blank_lines_after_block_statements=1
csharp_blank_lines_before_multiline_statements=1
csharp_blank_lines_after_multiline_statements=1
csharp_blank_lines_around_block_case_section=0
csharp_blank_lines_around_multiline_case_section=0
csharp_blank_lines_before_case=0
csharp_blank_lines_after_case=0
resharper_unity_duplicate_event_function_highlighting=error
resharper_unity_duplicate_shortcut_highlighting=error
resharper_unity_expected_component_highlighting=error
resharper_unity_explicit_tag_comparison_highlighting=error
resharper_unity_incorrect_mono_behaviour_instantiation_highlighting=error
resharper_unity_incorrect_scriptable_object_instantiation_highlighting=error
resharper_unity_no_null_coalescing_highlighting=error
resharper_unity_performance_critical_code_camera_main_highlighting=error
resharper_unity_performance_critical_code_invocation_highlighting=warning
resharper_unity_performance_critical_code_null_comparison_highlighting=warning
resharper_unity_possible_misapplication_of_attribute_to_multiple_fields_highlighting=error
resharper_unity_redundant_attribute_on_target_highlighting=error
resharper_unity_redundant_formerly_serialized_as_attribute_highlighting=error
resharper_unity_unresolved_component_or_scriptable_object_highlighting=error
resharper_use_name_of_instead_of_type_of_highlighting=error
resharper_wrong_public_modifier_specification_highlighting=error
resharper_csharp_force_attribute_style = separate
csharp_place_field_attribute_on_same_line = false
csharp_place_accessorholder_attribute_on_same_line = false
csharp_trailing_comma_in_multiline_lists = false
csharp_trailing_comma_in_singleline_lists = false
csharp_keep_existing_attribute_arrangement = false
csharp_blank_lines_around_region = 1
csharp_blank_lines_inside_region = 1
csharp_keep_blank_lines_in_code = false
csharp_remove_blank_lines_near_braces_in_code = true
csharp_blank_lines_before_control_transfer_statements = 1
csharp_blank_lines_after_control_transfer_statements = 1
csharp_blank_lines_before_block_statements = 1
csharp_blank_lines_after_block_statements = 1
csharp_blank_lines_before_multiline_statements = 1
csharp_blank_lines_after_multiline_statements = 1
csharp_blank_lines_around_block_case_section = 0
csharp_blank_lines_around_multiline_case_section = 0
csharp_blank_lines_before_case = 0
csharp_blank_lines_after_case = 0
resharper_unity_duplicate_event_function_highlighting = error
resharper_unity_duplicate_shortcut_highlighting = error
resharper_unity_expected_component_highlighting = error
resharper_unity_explicit_tag_comparison_highlighting = error
resharper_unity_incorrect_mono_behaviour_instantiation_highlighting = error
resharper_unity_incorrect_scriptable_object_instantiation_highlighting = error
resharper_unity_no_null_coalescing_highlighting = error
resharper_unity_performance_critical_code_camera_main_highlighting = error
resharper_unity_performance_critical_code_invocation_highlighting = warning
resharper_unity_performance_critical_code_null_comparison_highlighting = warning
resharper_unity_possible_misapplication_of_attribute_to_multiple_fields_highlighting = error
resharper_unity_redundant_attribute_on_target_highlighting = error
resharper_unity_redundant_formerly_serialized_as_attribute_highlighting = error
resharper_unity_unresolved_component_or_scriptable_object_highlighting = error
resharper_use_name_of_instead_of_type_of_highlighting = error
resharper_wrong_public_modifier_specification_highlighting = error

# ReSharper inspection severities
resharper_arrange_attributes_highlighting = suggestion
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<ModelsTagsByType> GetModelTagsAsync(CancellationToken cancella
{
var response = await Rest.GetAsync(GetUrl("models-tags-by-type"), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<ModelsTagsByType>(response.Body, client.JsonSerializationOptions);
return JsonConvert.DeserializeObject<ModelsTagsByType>(response.Body, HuggingFaceClient.JsonSerializationOptions);
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public async Task<IReadOnlyList<ModelInfo>> ListModelsAsync(ModelSearchArguments

var response = await Rest.GetAsync(uriBuilder.Uri.ToString(), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<IReadOnlyList<ModelInfo>>(response.Body, client.JsonSerializationOptions);
return JsonConvert.DeserializeObject<IReadOnlyList<ModelInfo>>(response.Body, HuggingFaceClient.JsonSerializationOptions);
}

/// <summary>
Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task<ModelInfo> GetModelDetailsAsync(string repoId, string revision

var response = await Rest.GetAsync(uriBuilder.Uri.ToString(), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<ModelInfo>(response.Body, client.JsonSerializationOptions);
return JsonConvert.DeserializeObject<ModelInfo>(response.Body, HuggingFaceClient.JsonSerializationOptions);
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public async Task<IReadOnlyDictionary<string, TaskInfo>> GetAllTasksAsync(Cancel
{
var response = await Rest.GetAsync(GetUrl("tasks"), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<IReadOnlyDictionary<string, TaskInfo>>(response.Body, client.JsonSerializationOptions);
return JsonConvert.DeserializeObject<IReadOnlyDictionary<string, TaskInfo>>(response.Body, HuggingFaceClient.JsonSerializationOptions);
}

/// <summary>
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task<UserInfo> WhoAmIAsync(CancellationToken cancellationToken = de
{
var response = await Rest.GetAsync(GetUrl("whoami-v2"), parameters: new RestParameters(client.DefaultRequestHeaders), cancellationToken);
response.Validate();
return JsonConvert.DeserializeObject<UserInfo>(response.Body, client.JsonSerializationOptions);
return JsonConvert.DeserializeObject<UserInfo>(response.Body, HuggingFaceClient.JsonSerializationOptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public class HuggingFaceClient : BaseClient<HuggingFaceAuthentication, HuggingFa
public HuggingFaceClient(HuggingFaceAuthentication authentication = null, HuggingFaceSettings settings = null)
: base(authentication ?? HuggingFaceAuthentication.Default, settings ?? HuggingFaceSettings.Default)
{
JsonSerializationOptions = new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
};

HubEndpoint = new HubEndpoint(this);
InferenceEndpoint = new InferenceEndpoint(this);
}
Expand All @@ -45,14 +39,18 @@ protected override void SetupDefaultRequestHeaders()
=> DefaultRequestHeaders = new Dictionary<string, string>
{
#if !UNITY_WEBGL
{"User-Agent", "com.rest.huggingface" },
{ "User-Agent", "com.rest.huggingface" },
#endif
{"Authorization", Rest.GetBearerOAuthToken(Authentication.Info.ApiKey) }
{ "Authorization", Rest.GetBearerOAuthToken(Authentication.Info.ApiKey) }
};

public override bool HasValidAuthentication => !string.IsNullOrWhiteSpace(Authentication?.Info?.ApiKey);

internal JsonSerializerSettings JsonSerializationOptions { get; }
internal static JsonSerializerSettings JsonSerializationOptions { get; } = new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
};

public HubEndpoint HubEndpoint { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static async Task DecodeAudioAsync(AudioToAudioResult result, bool debug
await fileStream.DisposeAsync();
}

result.AudioClip = await Rest.DownloadAudioClipAsync($"file://{localFilePath}", AudioType.MPEG, debug: debug, cancellationToken: cancellationToken);
result.AudioClip = await Rest.DownloadAudioClipAsync($"file://{localFilePath}", AudioType.MPEG, parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override async Task DecodeAsync(Stream stream, bool debug = false, Cancel
await fileStream.DisposeAsync();
}

AudioClip = await Rest.DownloadAudioClipAsync($"file://{filePath}", AudioType.MPEG, debug: debug, cancellationToken: cancellationToken);
AudioClip = await Rest.DownloadAudioClipAsync($"file://{filePath}", AudioType.MPEG, parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static async Task DecodeImageAsync(ImageSegmentationResult result, bool
await fileStream.DisposeAsync();
}

result.Mask = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken);
result.Mask = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override async Task DecodeAsync(Stream stream, bool debug = false, Cancel
await fileStream.DisposeAsync();
}

Image = await Rest.DownloadTextureAsync($"file://{filePath}", debug: debug, cancellationToken: cancellationToken);
Image = await Rest.DownloadTextureAsync($"file://{filePath}", parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async Task<Response> CallEndpointAsync()
headers.Add("Accept", task.MimeType);
}

var jsonData = await task.ToJsonAsync(client.JsonSerializationOptions, cancellationToken).ConfigureAwait(true);
var jsonData = await task.ToJsonAsync(HuggingFaceClient.JsonSerializationOptions, cancellationToken).ConfigureAwait(true);

if (!string.IsNullOrWhiteSpace(jsonData))
{
Expand Down Expand Up @@ -116,7 +116,7 @@ async Task<Response> CallEndpointAsync()

if (typeof(JsonInferenceTaskResponse).IsAssignableFrom(typeof(TResponse)))
{
var jsonResponse = Activator.CreateInstance(typeof(TResponse), response.Body, client.JsonSerializationOptions) as TResponse;
var jsonResponse = Activator.CreateInstance(typeof(TResponse), response.Body, HuggingFaceClient.JsonSerializationOptions) as TResponse;

if (jsonResponse is B64JsonInferenceTaskResponse b64JsonInferenceTaskResponse)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override async Task DecodeAsync(bool debug = false, CancellationToken can
await fileStream.DisposeAsync();
}

Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken);
Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override async Task DecodeAsync(Stream stream, bool debug, CancellationTo
await fileStream.DisposeAsync();
}

Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", debug: debug, cancellationToken: cancellationToken);
Image = await Rest.DownloadTextureAsync($"file://{localFilePath}", parameters: new RestParameters(debug: debug), cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ public AbstractTestFixture()
{
var auth = new HuggingFaceAuthentication().LoadDefaultsReversed();
var settings = new HuggingFaceSettings();
HuggingFaceClient = new HuggingFaceClient(auth, settings);
//HuggingFaceClient.EnableDebug = true;
HuggingFaceClient = new HuggingFaceClient(auth, settings)
{
EnableDebug = true
};
}
}
}
8 changes: 4 additions & 4 deletions HuggingFace/Packages/com.rest.huggingface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "HuggingFace",
"description": "A Non-Official HuggingFace Rest Client for Unity (UPM)",
"keywords": [],
"version": "1.0.0-preview.14",
"version": "1.0.0-preview.15",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.huggingface#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.huggingface/releases",
Expand All @@ -20,9 +20,9 @@
"registry": "https://package.openupm.com"
},
"dependencies": {
"com.utilities.rest": "2.4.0",
"com.utilities.encoder.wav": "1.1.3",
"com.utilities.encoder.ogg": "3.1.1"
"com.utilities.rest": "2.5.0",
"com.utilities.encoder.wav": "1.1.4",
"com.utilities.encoder.ogg": "3.1.2"
},
"hideInEditor": false
}
4 changes: 2 additions & 2 deletions HuggingFace/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"com.unity.ide.rider": "3.0.26",
"com.unity.ide.rider": "3.0.27",
"com.unity.ide.visualstudio": "2.0.22",
"com.unity.test-framework": "1.1.33",
"com.utilities.buildpipeline": "1.1.9"
"com.utilities.buildpipeline": "1.2.1"
},
"scopedRegistries": [
{
Expand Down
4 changes: 2 additions & 2 deletions HuggingFace/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
m_EditorVersion: 2022.3.15f1
m_EditorVersionWithRevision: 2022.3.15f1 (b58023a2b463)
m_EditorVersion: 2022.3.16f1
m_EditorVersionWithRevision: 2022.3.16f1 (d2c21f0ef2f1)

0 comments on commit ad9d57c

Please sign in to comment.