From bf03f43b44ada20cbd28c5587e4e080ef58eb003 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 5 Dec 2023 11:21:11 -0800 Subject: [PATCH] fixed benchmark --- aider/coders/base_coder.py | 2 -- aider/main.py | 17 +++++++++-------- benchmark/benchmark.py | 4 ++++ docs/faq.md | 6 +++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 9db3318bc..4c9f8eca9 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -480,7 +480,6 @@ class Coder: except ExhaustedContextWindow: exhausted = True except openai.BadRequestError as err: - dump(err) if "maximum context length" in str(err): exhausted = True else: @@ -955,7 +954,6 @@ class Coder: def check_model_availability(io, client, main_model): available_models = client.models.list() - dump(available_models) model_ids = sorted(model.id for model in available_models) if main_model.name in model_ids: return True diff --git a/aider/main.py b/aider/main.py index 36cf7574e..d4c8cb5c7 100644 --- a/aider/main.py +++ b/aider/main.py @@ -177,7 +177,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): model_group.add_argument( "--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( "--openai-api-type", @@ -497,14 +497,15 @@ def main(argv=None, input=None, output=None, force_git_root=None): ) else: kwargs = dict() - if args.openai_api_base and "openrouter.ai" in args.openai_api_base: - kwargs["default_headers"] = {"HTTP-Referer": "http://aider.chat", "X-Title": "Aider"} + if args.openai_api_base: + 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( - api_key=args.openai_api_key, - base_url=args.openai_api_base, - **kwargs, - ) + client = openai.OpenAI(api_key=args.openai_api_key, **kwargs) main_model = models.Model.create(args.model, client) diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 433c82f98..6c8e5135d 100755 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -18,6 +18,7 @@ import git import lox import matplotlib.pyplot as plt import numpy as np +import openai import pandas as pd import prompts import typer @@ -630,10 +631,13 @@ def run_test( show_fnames = ",".join(map(str, fnames)) print("fnames:", show_fnames) + client = openai.OpenAI(api_key=os.environ["OPENAI_API_KEY"]) + coder = Coder.create( main_model, edit_format, io, + client=client, fnames=fnames, use_git=False, stream=False, diff --git a/docs/faq.md b/docs/faq.md index 74b2d4759..a99a13dfe 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -274,13 +274,17 @@ done You can also script aider from python: ```python +import openai 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 fnames = ["foo.py"] # 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 coder.run("make a script that prints hello world")