mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
aider: Added regex to extract tokens from name
in get_model
function.
# Context: USER: use a regex to check `name` for "-XXk" and set tokens = the number XX ASSISTANT: To use a regex to check for "-XXk" in the `name` and set `tokens` to the number XX, you can modify the `get_model` function in the `aider/models.py` file. Here's the updated code: ```python aider/models.py <<<<<<< ORIGINAL def get_model(name): models = GPT35_models + GPT4_models for model in models: if model.name == name: return model tokens = 0 model = Model(name, tokens) ======= import re def get_model(name): models = GPT35_models + GPT4_models for model in models: if model.name == name: return model match = re.search(r'-([0-9]+)k', name) tokens = int(match.group(1)) if match else 0 model = Model(name, tokens) >>>>>>> UPDATED ``` This change imports the `re` module and uses the `re.search()` function to find the "-XXk" pattern in the `name`. If the pattern is found, it sets `tokens` to the number XX.
This commit is contained in:
parent
8c91e107e0
commit
8b5dcecbe2
1 changed files with 4 additions and 1 deletions
|
@ -20,6 +20,8 @@ GPT35_16k = Model("gpt-3.5-turbo-16k", 16)
|
|||
GPT35_models = [GPT35, GPT35_16k]
|
||||
|
||||
|
||||
import re
|
||||
|
||||
def get_model(name):
|
||||
models = GPT35_models + GPT4_models
|
||||
|
||||
|
@ -27,7 +29,8 @@ def get_model(name):
|
|||
if model.name == name:
|
||||
return model
|
||||
|
||||
tokens = 0
|
||||
match = re.search(r'-([0-9]+)k', name)
|
||||
tokens = int(match.group(1)) if match else 0
|
||||
|
||||
model = Model(name, tokens)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue