fixed benchmark

This commit is contained in:
Paul Gauthier 2023-12-05 11:21:11 -08:00
parent d92a93221c
commit bf03f43b44
4 changed files with 18 additions and 11 deletions

View file

@ -480,7 +480,6 @@ class Coder:
except ExhaustedContextWindow: except ExhaustedContextWindow:
exhausted = True exhausted = True
except openai.BadRequestError as err: except openai.BadRequestError as err:
dump(err)
if "maximum context length" in str(err): if "maximum context length" in str(err):
exhausted = True exhausted = True
else: else:
@ -955,7 +954,6 @@ class Coder:
def check_model_availability(io, client, main_model): def check_model_availability(io, client, main_model):
available_models = client.models.list() available_models = client.models.list()
dump(available_models)
model_ids = sorted(model.id for model in available_models) model_ids = sorted(model.id for model in available_models)
if main_model.name in model_ids: if main_model.name in model_ids:
return True return True

View file

@ -177,7 +177,7 @@ def main(argv=None, input=None, output=None, force_git_root=None):
model_group.add_argument( model_group.add_argument(
"--openai-api-base", "--openai-api-base",
metavar="OPENAI_API_BASE", metavar="OPENAI_API_BASE",
help="Specify the api_base (default: https://api.openai.com/v1)", help="Specify the api base url",
) )
model_group.add_argument( model_group.add_argument(
"--openai-api-type", "--openai-api-type",
@ -497,14 +497,15 @@ def main(argv=None, input=None, output=None, force_git_root=None):
) )
else: else:
kwargs = dict() kwargs = dict()
if args.openai_api_base and "openrouter.ai" in args.openai_api_base: if args.openai_api_base:
kwargs["default_headers"] = {"HTTP-Referer": "http://aider.chat", "X-Title": "Aider"} kwargs["base_url"] = args.openai_api_base
if "openrouter.ai" in args.openai_api_base:
kwargs["default_headers"] = {
"HTTP-Referer": "http://aider.chat",
"X-Title": "Aider",
}
client = openai.OpenAI( client = openai.OpenAI(api_key=args.openai_api_key, **kwargs)
api_key=args.openai_api_key,
base_url=args.openai_api_base,
**kwargs,
)
main_model = models.Model.create(args.model, client) main_model = models.Model.create(args.model, client)

View file

@ -18,6 +18,7 @@ import git
import lox import lox
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import openai
import pandas as pd import pandas as pd
import prompts import prompts
import typer import typer
@ -630,10 +631,13 @@ def run_test(
show_fnames = ",".join(map(str, fnames)) show_fnames = ",".join(map(str, fnames))
print("fnames:", show_fnames) print("fnames:", show_fnames)
client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])
coder = Coder.create( coder = Coder.create(
main_model, main_model,
edit_format, edit_format,
io, io,
client=client,
fnames=fnames, fnames=fnames,
use_git=False, use_git=False,
stream=False, stream=False,

View file

@ -274,13 +274,17 @@ done
You can also script aider from python: You can also script aider from python:
```python ```python
import openai
from aider.coders import Coder from aider.coders import Coder
# Make an openai client
client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# This is a list of files to add to the chat # This is a list of files to add to the chat
fnames = ["foo.py"] fnames = ["foo.py"]
# Create a coder object # Create a coder object
coder = Coder.create(fnames=fnames) coder = Coder.create(client=client, fnames=fnames)
# This will execute one instruction on those files and then return # This will execute one instruction on those files and then return
coder.run("make a script that prints hello world") coder.run("make a script that prints hello world")