Fetch available Ollama models using a provided API URL. Used by the preferences refresh button to load models before saving.
()
| 653 | ) |
| 654 | @pga_login_required |
| 655 | def refresh_ollama_models(): |
| 656 | """ |
| 657 | Fetch available Ollama models using a provided API URL. |
| 658 | Used by the preferences refresh button to load models before saving. |
| 659 | """ |
| 660 | from pgadmin.llm.utils import validate_api_url |
| 661 | |
| 662 | data = request.get_json(force=True, silent=True) or {} |
| 663 | api_url = data.get('api_url', '') |
| 664 | |
| 665 | if not api_url: |
| 666 | return make_json_response( |
| 667 | data={'models': [], 'error': 'No API URL provided'}, |
| 668 | status=200 |
| 669 | ) |
| 670 | |
| 671 | if not validate_api_url(api_url): |
| 672 | return make_json_response( |
| 673 | data={'models': [], |
| 674 | 'error': 'API URL is not in the allowed list. ' |
| 675 | 'Contact your administrator to update ' |
| 676 | 'ALLOWED_LLM_API_URLS in the server ' |
| 677 | 'configuration.'}, |
| 678 | status=200 |
| 679 | ) |
| 680 | |
| 681 | try: |
| 682 | models = _fetch_ollama_models(api_url) |
| 683 | return make_json_response(data={'models': models}, status=200) |
| 684 | except LLMApiError as e: |
| 685 | return make_json_response( |
| 686 | data={'models': [], 'error': str(e)}, |
| 687 | status=200 |
| 688 | ) |
| 689 | except Exception: |
| 690 | return make_json_response( |
| 691 | data={'models': [], |
| 692 | 'error': 'Failed to fetch Ollama models. ' |
| 693 | 'Check the API URL configuration.'}, |
| 694 | status=200 |
| 695 | ) |
| 696 | |
| 697 | |
| 698 | @blueprint.route("/models/docker", methods=["GET"], endpoint='models_docker') |
nothing calls this directly
no test coverage detected