Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Fix hugging face embedding (microsoft#6673)
### Motivation and Context Fix the Bug microsoft#6635 HuggingFace Embedding: Unable to Deserialization for certain models <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description As mentioned in the issue, the HuggingFace Embedding API interface returns responses typically in the form of `List<ReadOnlyMemory<float>>` and occasionally as `List<List<List<ReadOnlyMemory<float>>>>`. Currently, only the latter format is handled correctly, leading to deserialization issues. To address this, I propose the following solution: ``` try { // Attempt to parse data as List<ReadOnlyMemory<float>> and return the parsed data } catch (KernelException ex1) { try { // If the first attempt fails, attempt to parse data as List<List<List<ReadOnlyMemory<float>>>>` and return the parsed data } catch (KernelException ex2) { // If both attempts fail, handle the exception (e.g., the model doesn't exist ,the model has still been loading, or an HTTP exception occurred) and rethrow the error } } ``` ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Dmytro Struk <[email protected]>
- Loading branch information