mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
lint
This commit is contained in:
parent
30a3cc0847
commit
1334392418
8 changed files with 49 additions and 41 deletions
|
@ -636,7 +636,10 @@ class Coder:
|
|||
if len(chunk.choices) == 0:
|
||||
continue
|
||||
|
||||
if hasattr(chunk.choices[0], "finish_reason") and chunk.choices[0].finish_reason == "length":
|
||||
if (
|
||||
hasattr(chunk.choices[0], "finish_reason")
|
||||
and chunk.choices[0].finish_reason == "length"
|
||||
):
|
||||
raise ExhaustedContextWindow()
|
||||
|
||||
try:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from .model import Model
|
||||
from .openai import OpenAIModel
|
||||
from .openrouter import OpenRouterModel
|
||||
from .model import Model
|
||||
|
||||
GPT4 = Model.create('gpt-4')
|
||||
GPT35 = Model.create('gpt-3.5-turbo')
|
||||
GPT35_16k = Model.create('gpt-3.5-turbo-16k')
|
||||
GPT4 = Model.create("gpt-4")
|
||||
GPT35 = Model.create("gpt-3.5-turbo")
|
||||
GPT35_16k = Model.create("gpt-3.5-turbo-16k")
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import openai
|
||||
|
||||
|
||||
class Model:
|
||||
name = None
|
||||
edit_format = None
|
||||
|
@ -16,7 +18,8 @@ class Model:
|
|||
def create(cls, name):
|
||||
from .openai import OpenAIModel
|
||||
from .openrouter import OpenRouterModel
|
||||
if ("openrouter.ai" in openai.api_base):
|
||||
|
||||
if "openrouter.ai" in openai.api_base:
|
||||
return OpenRouterModel(name)
|
||||
return OpenAIModel(name)
|
||||
|
||||
|
@ -25,12 +28,12 @@ class Model:
|
|||
|
||||
@staticmethod
|
||||
def strong_model():
|
||||
return Model.create('gpt-4')
|
||||
return Model.create("gpt-4")
|
||||
|
||||
@staticmethod
|
||||
def weak_model():
|
||||
return Model.create('gpt-3.5-turbo')
|
||||
return Model.create("gpt-3.5-turbo")
|
||||
|
||||
@staticmethod
|
||||
def commit_message_models():
|
||||
return [Model.create('gpt-3.5-turbo'), Model.create('gpt-3.5-turbo-16k')]
|
||||
return [Model.create("gpt-3.5-turbo"), Model.create("gpt-3.5-turbo-16k")]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import tiktoken
|
||||
import re
|
||||
|
||||
import tiktoken
|
||||
|
||||
from .model import Model
|
||||
|
||||
known_tokens = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import openai
|
||||
import tiktoken
|
||||
|
||||
from .model import Model
|
||||
|
||||
cached_model_details = None
|
||||
|
@ -7,12 +8,12 @@ cached_model_details = None
|
|||
|
||||
class OpenRouterModel(Model):
|
||||
def __init__(self, name):
|
||||
if name == 'gpt-4':
|
||||
name = 'openai/gpt-4'
|
||||
elif name == 'gpt-3.5-turbo':
|
||||
name = 'openai/gpt-3.5-turbo'
|
||||
elif name == 'gpt-3.5-turbo-16k':
|
||||
name = 'openai/gpt-3.5-turbo-16k'
|
||||
if name == "gpt-4":
|
||||
name = "openai/gpt-4"
|
||||
elif name == "gpt-3.5-turbo":
|
||||
name = "openai/gpt-3.5-turbo"
|
||||
elif name == "gpt-3.5-turbo-16k":
|
||||
name = "openai/gpt-3.5-turbo-16k"
|
||||
|
||||
self.name = name
|
||||
self.edit_format = edit_format_for_model(name)
|
||||
|
@ -24,20 +25,22 @@ class OpenRouterModel(Model):
|
|||
global cached_model_details
|
||||
if cached_model_details == None:
|
||||
cached_model_details = openai.Model.list().data
|
||||
found = next((details for details in cached_model_details if details.get('id') == name), None)
|
||||
found = next(
|
||||
(details for details in cached_model_details if details.get("id") == name), None
|
||||
)
|
||||
|
||||
if found:
|
||||
self.max_context_tokens = int(found.get('context_length'))
|
||||
self.prompt_price = round(float(found.get('pricing').get('prompt')) * 1000,6)
|
||||
self.completion_price = round(float(found.get('pricing').get('completion')) * 1000,6)
|
||||
self.max_context_tokens = int(found.get("context_length"))
|
||||
self.prompt_price = round(float(found.get("pricing").get("prompt")) * 1000, 6)
|
||||
self.completion_price = round(float(found.get("pricing").get("completion")) * 1000, 6)
|
||||
|
||||
else:
|
||||
raise ValueError(f'invalid openrouter model: {name}')
|
||||
raise ValueError(f"invalid openrouter model: {name}")
|
||||
|
||||
|
||||
# TODO run benchmarks and figure out which models support which edit-formats
|
||||
def edit_format_for_model(name):
|
||||
if any(str in name for str in ['gpt-4', 'claude-2']):
|
||||
if any(str in name for str in ["gpt-4", "claude-2"]):
|
||||
return "diff"
|
||||
|
||||
return "whole"
|
||||
|
|
|
@ -51,10 +51,7 @@ def send_with_retries(model_name, messages, functions, stream):
|
|||
kwargs["engine"] = openai.api_engine
|
||||
|
||||
if "openrouter.ai" in openai.api_base:
|
||||
kwargs["headers"] = {
|
||||
"HTTP-Referer": "http://aider.chat",
|
||||
"X-Title": "Aider"
|
||||
}
|
||||
kwargs["headers"] = {"HTTP-Referer": "http://aider.chat", "X-Title": "Aider"}
|
||||
|
||||
key = json.dumps(kwargs, sort_keys=True).encode()
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -18,7 +18,7 @@ setup(
|
|||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
install_requires=requirements,
|
||||
python_requires='>=3.9',
|
||||
python_requires=">=3.9",
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"aider = aider.main:main",
|
||||
|
|
|
@ -24,33 +24,33 @@ class TestModels(unittest.TestCase):
|
|||
model = Model.create("gpt-4-32k-2123")
|
||||
self.assertEqual(model.max_context_tokens, 32 * 1024)
|
||||
|
||||
|
||||
@patch('openai.Model.list')
|
||||
@patch("openai.Model.list")
|
||||
def test_openrouter_model_properties(self, mock_model_list):
|
||||
import openai
|
||||
|
||||
old_base = openai.api_base
|
||||
openai.api_base = 'https://openrouter.ai/api/v1'
|
||||
openai.api_base = "https://openrouter.ai/api/v1"
|
||||
mock_model_list.return_value = {
|
||||
'data': [
|
||||
"data": [
|
||||
{
|
||||
'id': 'openai/gpt-4',
|
||||
'object': 'model',
|
||||
'context_length': '8192',
|
||||
'pricing': {
|
||||
'prompt': '0.00006',
|
||||
'completion': '0.00012'
|
||||
}
|
||||
"id": "openai/gpt-4",
|
||||
"object": "model",
|
||||
"context_length": "8192",
|
||||
"pricing": {"prompt": "0.00006", "completion": "0.00012"},
|
||||
}
|
||||
]
|
||||
}
|
||||
mock_model_list.return_value = type('', (), {'data': mock_model_list.return_value['data']})()
|
||||
mock_model_list.return_value = type(
|
||||
"", (), {"data": mock_model_list.return_value["data"]}
|
||||
)()
|
||||
|
||||
model = OpenRouterModel("gpt-4")
|
||||
self.assertEqual(model.name, 'openai/gpt-4')
|
||||
self.assertEqual(model.name, "openai/gpt-4")
|
||||
self.assertEqual(model.max_context_tokens, 8192)
|
||||
self.assertEqual(model.prompt_price, 0.06)
|
||||
self.assertEqual(model.completion_price, 0.12)
|
||||
openai.api_base = old_base
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue