# Aider chat conversation:
USER: implemenet the `fuzzy_match_models` function. takes the name of a LLM like "gpt-3.5" and searches the list of `models` to find models which contain the name or contain a slight misspelling of the name
ASSISTANT: Here is an implementation of the `fuzzy_match_models` function that searches for models containing the given name or a slight misspelling:
aider/models.py
```python
<<<<<<< SEARCH
def fuzzy_match_models(name):
models = litellm.most_cost.keys()
=======
import difflib
def fuzzy_match_models(name):
models = litellm.most_cost.keys()
# Check for exact match first
if name in models:
return [name]
# Check for models containing the name
matching_models = [model for model in models if name in model]
# If no matches found, check for slight misspellings
if not matching_models:
matching_models = difflib.get_close_matches(name, models, n=3, cutoff=0.8)
return matching_models
>>>>>>> REPLACE
```
This implementation does the following:
1. It first checks if the given `name` exactly matches any model in the `models` list. If an exact match is found, it returns a list containing only that model name.
2. If no exact match is found, it searches for models that contain the given `name` as a substring. It uses a list comprehension to filter the `models` list and find models that include `name`.
3. If still no matches are found, it uses the `difflib.get_close_matches()` function to find models that are close matches to the given `name`. It searches for up to 3 close matches with a similarity ratio of at least 0.8 (80%).
4. Finally, it returns the list of matching models found either by exact match, substring match, or close match.
This implementation allows for fuzzy matching of model names, considering both exact matches and slight misspellings.
# Aider chat conversation:
USER: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
ASSISTANT: To address the `DeprecationWarning` regarding `pkg_resources`, we will replace its usage with the recommended `importlib.resources` or `importlib.metadata` from the Python standard library. The specific replacement depends on the original use case of `pkg_resources`. In the provided code, `pkg_resources` is used to access package data, so we will use `importlib.resources`.
Here are the diffs for the necessary changes:
```diff
--- aider/repomap.py
+++ aider/repomap.py
@@ ... @@
import networkx as nx
-import pkg_resources
+import importlib.resources as pkg_resources
from diskcache import Cache
from grep_ast import TreeContext, filename_to_lang
from pygments.lexers import guess_lexer_for_filename
from pygments.token import Token
from pygments.util import ClassNotFound
@@ ... @@
# Load the tags queries
try:
- scm_fname = pkg_resources.resource_filename(
- __name__, os.path.join("queries", f"tree-sitter-{lang}-tags.scm")
- )
+ scm_fname = pkg_resources.files(__package__).joinpath(
+ "queries", f"tree-sitter-{lang}-tags.scm"
+ )
except KeyError:
return
- query_scm = Path(scm_fname)
+ query_scm = scm_fname
if not query_scm.exists():
return
query_scm = query_scm.read_text()
```
These changes replace the deprecated `pkg_resources.resource_filename` with `importlib.resources.files`, which is the recommended way to access package resources in Python 3.9 and later. The `files()` function returns a `Path`-like object that can be used to read the contents of the resource.