Fetch available OpenAI models. Returns models that support function calling.
()
| 512 | @blueprint.route("/models/openai", methods=["GET"], endpoint='models_openai') |
| 513 | @pga_login_required |
| 514 | def get_openai_models(): |
| 515 | """ |
| 516 | Fetch available OpenAI models. |
| 517 | Returns models that support function calling. |
| 518 | """ |
| 519 | from pgadmin.llm.utils import get_openai_api_key, get_openai_api_url |
| 520 | |
| 521 | api_key = get_openai_api_key() |
| 522 | api_url = get_openai_api_url() |
| 523 | if not api_key and not api_url: |
| 524 | return make_json_response( |
| 525 | data={'models': [], 'error': 'No API key configured'}, |
| 526 | status=200 |
| 527 | ) |
| 528 | |
| 529 | try: |
| 530 | models = _fetch_openai_models(api_key, api_url) |
| 531 | return make_json_response(data={'models': models}, status=200) |
| 532 | except LLMApiError as e: |
| 533 | return make_json_response( |
| 534 | data={'models': [], 'error': str(e)}, |
| 535 | status=200 |
| 536 | ) |
| 537 | except Exception: |
| 538 | return make_json_response( |
| 539 | data={'models': [], |
| 540 | 'error': 'Failed to fetch OpenAI models. ' |
| 541 | 'Check the API key and URL configuration.'}, |
| 542 | status=200 |
| 543 | ) |
| 544 | |
| 545 | |
| 546 | @blueprint.route( |
nothing calls this directly
no test coverage detected