(defun gptel-got--model () "This function retrieves the model name from the GPTel backend. It sends a GET request to the backend's models endpoint to fetch the available models. The function returns the model name (string) from the first entry in the backend's model list, which should be sufficient when ." (let ((result (gptel--url-retrieve (concat "http://" (gptel-backend-host gptel-backend) "/v1/models") :method "GET"))) (plist-get (aref (plist-get result :models) 0) :model))) (defun gptel-got-match-model () "Finds the closest matching model name from the backend's model list. This function uses string distance (e.g., Levenshtein distance) to compare the target model name (from `gptel-got--model') against all available models. It returns the best-matching model name (string) from the backend. Intended for scenarios where the exact model name is unknown or contains typos. The function ensures the most similar model name is selected for operation by minimizing the string distance between names." (let ((got-model (gptel-got--model)) (min most-positive-fixnum) (best-match nil)) (cl-loop for model in (gptel-backend-models gptel-backend) do (let ((distance (string-distance got-model (symbol-name model))) (when (< distance min) (setq min distance) (setq best-match model)))) best-match))