Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus authored Nov 23, 2024
1 parent 8f0528d commit 538c0bb
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,39 +360,7 @@ async def get_image(filename) -> FileResponse:

return FileResponse(target, media_type=content_type)

@self.app.get("/providers")
async def providers():
model_list = [{
'id': provider.__name__,
'object': 'provider',
'created': 0,
'url': provider.url,
'label': getattr(provider, "label", None),
} for provider in __providers__ if provider.working]
return JSONResponse(model_list)

@self.app.get("/providers/{provider}")
async def providers_info(provider: str):
if provider not in ProviderUtils.convert:
return JSONResponse({"error": "The model does not exist."}, 404)
provider: ProviderType = ProviderUtils.convert[provider]
def safe_get_models(provider: ProviderType) -> list[str]:
try:
return provider.get_models() if hasattr(provider, "get_models") else []
except:
return []
provider_info = {
'id': provider.__name__,
'object': 'provider',
'created': 0,
'url': provider.url,
'label': getattr(provider, "label", None),
'models': safe_get_models(provider),
'image_models': getattr(provider, "image_models", []) or [],
'vision_models': [model for model in [getattr(provider, "default_vision_model", None)] if model],
'params': [*provider.get_parameters()] if hasattr(provider, "get_parameters") else []
}
return JSONResponse(provider_info)


def format_exception(e: Exception, config: Union[ChatCompletionsConfig, ImageGenerationConfig], image: bool = False) -> str:
last_provider = {} if not image else g4f.get_last_provider(True)
Expand Down

0 comments on commit 538c0bb

Please sign in to comment.