Fetch available Docker models using a provided API URL. Used by the preferences refresh button to load models before saving.
()
| 734 | ) |
| 735 | @pga_login_required |
| 736 | def refresh_docker_models(): |
| 737 | """ |
| 738 | Fetch available Docker models using a provided API URL. |
| 739 | Used by the preferences refresh button to load models before saving. |
| 740 | """ |
| 741 | from pgadmin.llm.utils import validate_api_url |
| 742 | |
| 743 | data = request.get_json(force=True, silent=True) or {} |
| 744 | api_url = data.get('api_url', '') |
| 745 | |
| 746 | if not api_url: |
| 747 | return make_json_response( |
| 748 | data={'models': [], 'error': 'No API URL provided'}, |
| 749 | status=200 |
| 750 | ) |
| 751 | |
| 752 | if not validate_api_url(api_url): |
| 753 | return make_json_response( |
| 754 | data={'models': [], |
| 755 | 'error': 'API URL is not in the allowed list. ' |
| 756 | 'Contact your administrator to update ' |
| 757 | 'ALLOWED_LLM_API_URLS in the server ' |
| 758 | 'configuration.'}, |
| 759 | status=200 |
| 760 | ) |
| 761 | |
| 762 | try: |
| 763 | models = _fetch_docker_models(api_url) |
| 764 | return make_json_response(data={'models': models}, status=200) |
| 765 | except LLMApiError as e: |
| 766 | return make_json_response( |
| 767 | data={'models': [], 'error': str(e)}, |
| 768 | status=200 |
| 769 | ) |
| 770 | except Exception: |
| 771 | return make_json_response( |
| 772 | data={'models': [], |
| 773 | 'error': 'Failed to fetch Docker models. ' |
| 774 | 'Check the API URL configuration.'}, |
| 775 | status=200 |
| 776 | ) |
| 777 | |
| 778 | |
| 779 | def _fetch_anthropic_models(api_key, api_url=''): |
nothing calls this directly
no test coverage detected