Skip to content

Implement hf_token support, viewApi, and unit tests#16

Merged
sergix44 merged 1 commit intosergix44:masterfrom
ikarolaborda:feature/implement-readme-todos
Mar 24, 2026
Merged

Implement hf_token support, viewApi, and unit tests#16
sergix44 merged 1 commit intosergix44:masterfrom
ikarolaborda:feature/implement-readme-todos

Conversation

@ikarolaborda
Copy link
Copy Markdown
Contributor

Summary

  • hf_token support: Wire the existing $hfToken parameter as an Authorization: Bearer header on all HTTP requests (via Guzzle default headers) and WebSocket connections (via handshake headers). The token is passed from Client through RemoteClient where all transport is centralized.
  • viewApi(): Add a new public method that calls Gradio's GET /info endpoint and returns the API information (named/unnamed endpoints, parameters, return types) as an associative array.
  • Unit tests: Add 16 deterministic Pest tests using Guzzle MockHandler + history middleware. Covers: client construction, config fetching, hf_token auth header presence/absence, viewApi endpoint call, predict with apiName/fnIndex/raw mode, client options passthrough, event callbacks, DTO behavior, and error cases. Replaces the previous live-API-dependent ExampleTest.
  • README documentation: Comprehensive update with examples for all features (basic usage, hf_token auth, viewApi, client options, function index, raw mode, event system, config access, file upload). All README TODOs marked as complete.

Changes

File Change
src/Client/RemoteClient.php Accept $hfToken, inject Authorization header into Guzzle defaults and WS options
src/Client.php Pass $hfToken to parent, add viewApi() method, add HTTP_API_INFO constant
tests/ClientTest.php 16 new unit tests with mocked HTTP responses
tests/ExampleTest.php Removed (live API tests that cannot run in CI)
README.md Full documentation rewrite with examples and updated TODO checklist

Test plan

  • All 16 unit tests pass (vendor/bin/pest — 16 passed, 0.03s)
  • Auth header present on all requests when hf_token is set
  • Auth header absent when hf_token is null
  • viewApi() hits GET /info and returns decoded array
  • predict() works with apiName, fnIndex, and raw mode
  • Custom httpClientOptions are passed through to Guzzle
  • Event callbacks fire correctly during predict
  • Constructor validates src URL format
  • No breaking changes to existing public API

@ikarolaborda ikarolaborda force-pushed the feature/implement-readme-todos branch 2 times, most recently from 93e19c7 to 4da653f Compare March 22, 2026 14:23
@sergix44 sergix44 requested review from Copilot and sergix44 March 22, 2026 14:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class Hugging Face token authentication support across HTTP + WebSocket transports, introduces a viewApi() helper to fetch Gradio’s /info metadata, and replaces live/integration-style tests with deterministic unit tests and refreshed documentation.

Changes:

  • Wire hfToken through the transport layer to send Authorization: Bearer … on HTTP requests and WS handshakes.
  • Add Client::viewApi() to call GET /info and return decoded API metadata.
  • Replace the live Example test with a mocked Pest test suite and update README examples/TODOs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Client/RemoteClient.php Adds hfToken handling and default header injection for HTTP + WS
src/Client.php Passes hfToken to transport and adds viewApi()
tests/ClientTest.php Adds mocked Pest tests covering auth, viewApi, predict modes, options, events, DTOs
tests/ExampleTest.php Removes live API tests unsuitable for CI
README.md Documents new features and provides usage examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Client/RemoteClient.php
Comment thread src/Client/RemoteClient.php
Comment thread README.md
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Client.php
Comment thread tests/ClientTest.php Outdated
- Wire hf_token as Authorization Bearer header on all HTTP and WebSocket
  requests via RemoteClient
- Add viewApi() method to Client that calls GET /info endpoint
- Add 16 unit tests using Guzzle MockHandler (client construction,
  auth headers, viewApi, predict, client options, events, DTOs)
- Replace live API tests with deterministic mocked tests
- Update README with comprehensive documentation and examples
@ikarolaborda ikarolaborda force-pushed the feature/implement-readme-todos branch from cec126e to 9ad8591 Compare March 23, 2026 17:19
@sergix44 sergix44 merged commit 39ce4fa into sergix44:master Mar 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants