Fix view_api bug where unnamed rotes where showing api_name instead of fn_index (#3972)

* Fix view_api bug

* Add to changelog

* Rework test
This commit is contained in:
Freddy Boulton 2023-04-26 18:38:46 -04:00 committed by GitHub
parent 37d52a753c
commit 2a59ec04fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -2,11 +2,11 @@
## New Features:
- Progress Updates from `gr.Progress()` can be accessed via `job.status().progress_data` by @freddyaboulton](https://github.com/freddyaboulton) in [PR 3924](https://github.com/gradio-app/gradio/pull/3924)
- Progress Updates from `gr.Progress()` can be accessed via `job.status().progress_data` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3924](https://github.com/gradio-app/gradio/pull/3924)
## Bug Fixes:
No changes to highlight.
- Fixed bug where unnamed routes where displayed with `api_name` instead of `fn_index` in `view_api` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3972](https://github.com/gradio-app/gradio/pull/3972)
## Documentation Changes:

View File

@ -415,7 +415,6 @@ class Client:
info = fetch.json()["api"]
else:
raise ValueError(f"Could not fetch api info for {self.src}")
num_named_endpoints = len(info["named_endpoints"])
num_unnamed_endpoints = len(info["unnamed_endpoints"])
if num_named_endpoints == 0 and all_endpoints is None:
@ -430,7 +429,9 @@ class Client:
if all_endpoints:
human_info += f"\nUnnamed API endpoints: {num_unnamed_endpoints}\n"
for fn_index, endpoint_info in info["unnamed_endpoints"].items():
human_info += self._render_endpoints_info(fn_index, endpoint_info)
# When loading from json, the fn_indices are read as strings
# because json keys can only be strings
human_info += self._render_endpoints_info(int(fn_index), endpoint_info)
else:
if num_unnamed_endpoints > 0:
human_info += f"\nUnnamed API endpoints: {num_unnamed_endpoints}, to view, run Client.view_api(`all_endpoints=True`)\n"

View File

@ -667,6 +667,13 @@ class TestAPIInfo:
"unnamed_endpoints": {},
}
def test_unnamed_endpoints_use_fn_index(self, count_generator_demo):
# This demo has no api_name
with connect(count_generator_demo) as client:
info = client.view_api(return_format="str")
assert "fn_index=0" in info
assert "api_name" not in info
class TestEndpoints:
def test_upload(self):