Commit graph

3662 commits

Author SHA1 Message Date
Paul Gauthier
6863b47e6a Check the environment inside Model 2024-04-20 08:09:17 -07:00
Paul Gauthier
e513174da4 Warn if litellm is not giving us good validate_environment() responses 2024-04-20 08:01:50 -07:00
Paul Gauthier
0969380ce9 copy 2024-04-19 16:42:25 -07:00
paul-gauthier
08f8c8c0f5
Update llms.md 2024-04-19 16:14:34 -07:00
paul-gauthier
cf266b4bf2
Update llms.md 2024-04-19 16:11:59 -07:00
paul-gauthier
2fce674dd0
Update llms.md 2024-04-19 16:11:26 -07:00
paul-gauthier
a13abaccef
Merge pull request #564 from paul-gauthier/litellm 2024-04-19 16:09:07 -07:00
Paul Gauthier
434fa5f6a7 updated benchmark to new Coder & Model classes 2024-04-19 15:21:24 -07:00
Paul Gauthier
05cdd9f2ec rename 2024-04-19 15:20:41 -07:00
Paul Gauthier
46b4a4381c toc 2024-04-19 14:53:33 -07:00
Paul Gauthier
9d01f9cb29 copy 2024-04-19 14:50:09 -07:00
Paul Gauthier
35eb9cf40d copy 2024-04-19 14:49:26 -07:00
Paul Gauthier
4e50f0d095 Support weak_model=False 2024-04-19 14:05:58 -07:00
Paul Gauthier
f81b62dfea Added --require-model-info 2024-04-19 14:01:02 -07:00
Paul Gauthier
aac110f078 copy 2024-04-19 13:45:51 -07:00
Paul Gauthier
6cecbd02d6 Document new model support 2024-04-19 13:18:12 -07:00
Paul Gauthier
99f43b4088 GPT->LLM 2024-04-19 12:19:38 -07:00
Paul Gauthier
f0f0c330d7 cleanup 2024-04-19 12:14:58 -07:00
Paul Gauthier
547ae142ba refactor tokenizer 2024-04-19 12:08:35 -07:00
Paul Gauthier
6f1cebc4c2 fix: do not stomp main model.info 2024-04-19 11:24:11 -07:00
Paul Gauthier
922559a15a Refactored error handling to display model name in case of unknown model. 2024-04-19 11:17:33 -07:00
Paul Gauthier
fb3285ff77 aider: Added a main function to allow running the script with a model name from the command line and printing the results.
# Aider chat conversation:

USER: add a main func so i can run this script with a model name on the cmd line and print the results

ASSISTANT: Here are the changes to add a `main` function that allows running the script with a model name from the command line and printing the results:

aider/models.py
```python
<<<<<<< SEARCH
=======
import sys

def main():
    if len(sys.argv) != 2:
        print("Usage: python models.py <model_name>")
        sys.exit(1)

    model_name = sys.argv[1]
    matching_models = fuzzy_match_models(model_name)

    if matching_models:
        print(f"Matching models for '{model_name}':")
        for model in matching_models:
            print(model)
    else:
        print(f"No matching models found for '{model_name}'.")

if __name__ == "__main__":
    main()
>>>>>>> REPLACE
```

The `main` function does the following:

1. It checks if the script is called with exactly one command-line argument (the model name). If not, it prints the usage instructions and exits with an error code.

2. It retrieves the model name from the command-line argument using `sys.argv[1]`.

3. It calls the `fuzzy_match_models` function with the provided model name to get the list of matching models.

4. If matching models are found, it prints a message indicating the matching models for the given model name and then prints each matching model on a separate line.

5. If no matching models are found, it prints a message indicating that no matching models were found for the given model name.

The `if __name__ == "__main__":` block ensures that the `main` function is only executed when the script is run directly, not when it is imported as a module.

With these changes, you can run the script from the command line by providing a model name as an argument, and it will print the matching models or a message if no matches are found.
2024-04-19 11:08:28 -07:00
Paul Gauthier
70b2f5d054 aider: Implemented the fuzzy_match_models function to search for models containing the given name or a slight misspelling.
# 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.
2024-04-19 11:07:32 -07:00
Paul Gauthier
7ef10c56a2 Added a fuzzy model matching function to find models by name. 2024-04-19 11:07:31 -07:00
Paul Gauthier
7ec4de865d Added --weak-model 2024-04-19 10:57:21 -07:00
Paul Gauthier
93bd187bf3 Added --opus 2024-04-18 17:09:43 -07:00
Paul Gauthier
3e153cc7fa upgrade actions 2024-04-18 16:41:45 -07:00
Paul Gauthier
3449f7da42 quiet tree-sitter warnings 2024-04-18 16:36:56 -07:00
Paul Gauthier
65400981c5 aider: Replace deprecated pkg_resources.resource_filename with importlib.resources.files for accessing package resources in Python 3.9+.
# 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.
2024-04-18 16:30:10 -07:00
Paul Gauthier
7a047dc98e networkx 3.3 no longer works on python 3.9 2024-04-18 16:25:21 -07:00
Paul Gauthier
fbcbe137ab cleanup 2024-04-18 16:21:15 -07:00
Paul Gauthier
d750511c7c added litellm dep; upgraded all deps 2024-04-18 16:18:36 -07:00
Paul Gauthier
957026d3cc fixed test_sendchat 2024-04-18 16:13:08 -07:00
Paul Gauthier
363b3202ab fixed test_repomap 2024-04-18 16:06:35 -07:00
Paul Gauthier
2a3eb8ac35 fixed test_editblock and _wholefile 2024-04-18 16:02:50 -07:00
Paul Gauthier
512b991a51 fixed test_coder 2024-04-18 15:55:59 -07:00
Paul Gauthier
f960774b51 fixed test_commands 2024-04-18 15:01:02 -07:00
Paul Gauthier
67cc974454 fixed test_main 2024-04-18 14:57:51 -07:00
Paul Gauthier
733c09d30f fixed test_repo 2024-04-18 14:55:56 -07:00
Paul Gauthier
cb547da90c Fixed test_models 2024-04-18 14:53:20 -07:00
Paul Gauthier
f291c8f777 dropped aliases 2024-04-18 14:44:50 -07:00
Paul Gauthier
0da1b59901 Fixed up images in chat 2024-04-18 14:39:32 -07:00
Paul Gauthier
f1c09ececf Switched voice to litellm 2024-04-18 14:13:26 -07:00
Paul Gauthier
cf2a48b21f get_weak_model 2024-04-18 13:55:43 -07:00
Paul Gauthier
93f4a46996 reorg 2024-04-18 09:29:26 -07:00
Paul Gauthier
15c1ad1f96 aider: Create the NoModelInfo class to handle exceptions when model information cannot be retrieved.
# Aider chat conversation:

USER: create the `NoModelInfo` class

ASSISTANT: ```diff
--- aider/models/model.py
+++ aider/models/model.py
@@ ... @@
 from dataclasses import dataclass, fields

 import litellm
+from typing import Optional
 from PIL import Image

 from aider.dump import dump

+class NoModelInfo(Exception):
+    """
+    Exception raised when model information cannot be retrieved.
+    """
+    def __init__(self, message: Optional[str] = None):
+        super().__init__(message or "No model information available.")
+
 @dataclass
 class ModelSettings:
     name: str
```
2024-04-18 09:26:07 -07:00
Paul Gauthier
dd000c6147 Add exception handling when retrieving model info in the Model class constructor. 2024-04-18 09:26:05 -07:00
Paul Gauthier
79170839ee noop 2024-04-18 09:24:18 -07:00
Paul Gauthier
68888faa6f Configure model settings, adopt litellm bugfix 2024-04-18 09:22:32 -07:00
Paul Gauthier
f12bbf1e5b todo 2024-04-17 15:55:55 -07:00