mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
refactor the jsonschema check into base
This commit is contained in:
parent
ba2c5d05da
commit
cbe59b85c2
4 changed files with 10 additions and 12 deletions
|
@ -12,6 +12,7 @@ import backoff
|
||||||
import git
|
import git
|
||||||
import openai
|
import openai
|
||||||
import requests
|
import requests
|
||||||
|
from jsonschema import Draft7Validator
|
||||||
from openai.error import APIError, RateLimitError, ServiceUnavailableError, Timeout
|
from openai.error import APIError, RateLimitError, ServiceUnavailableError, Timeout
|
||||||
from rich.console import Console, Text
|
from rich.console import Console, Text
|
||||||
from rich.live import Live
|
from rich.live import Live
|
||||||
|
@ -187,6 +188,15 @@ class Coder:
|
||||||
for fname in self.get_inchat_relative_files():
|
for fname in self.get_inchat_relative_files():
|
||||||
self.io.tool_output(f"Added {fname} to the chat.")
|
self.io.tool_output(f"Added {fname} to the chat.")
|
||||||
|
|
||||||
|
# validate the functions jsonschema
|
||||||
|
if hasattr(self, "functions"):
|
||||||
|
for function in self.functions:
|
||||||
|
Draft7Validator.check_schema(function)
|
||||||
|
|
||||||
|
if self.verbose:
|
||||||
|
self.io.tool_output("JSON Schema:")
|
||||||
|
self.io.tool_output(json.dumps(self.functions, indent=4))
|
||||||
|
|
||||||
def find_common_root(self):
|
def find_common_root(self):
|
||||||
if len(self.abs_fnames) == 1:
|
if len(self.abs_fnames) == 1:
|
||||||
self.root = os.path.dirname(list(self.abs_fnames)[0])
|
self.root = os.path.dirname(list(self.abs_fnames)[0])
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from jsonschema import Draft7Validator
|
|
||||||
|
|
||||||
from ..dump import dump # noqa: F401
|
from ..dump import dump # noqa: F401
|
||||||
from .base_coder import Coder
|
from .base_coder import Coder
|
||||||
from .editblock_coder import do_replace
|
from .editblock_coder import do_replace
|
||||||
|
@ -82,8 +80,6 @@ class EditBlockFunctionCoder(Coder):
|
||||||
"updated_lines"
|
"updated_lines"
|
||||||
] = updated_lines
|
] = updated_lines
|
||||||
|
|
||||||
Draft7Validator.check_schema(self.functions[0])
|
|
||||||
|
|
||||||
self.gpt_prompts = EditBlockFunctionPrompts()
|
self.gpt_prompts = EditBlockFunctionPrompts()
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from jsonschema import Draft7Validator
|
|
||||||
|
|
||||||
from aider import diffs
|
from aider import diffs
|
||||||
|
|
||||||
from ..dump import dump # noqa: F401
|
from ..dump import dump # noqa: F401
|
||||||
|
@ -35,8 +33,6 @@ class SingleWholeFileFunctionCoder(Coder):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Draft7Validator.check_schema(self.functions[0])
|
|
||||||
|
|
||||||
self.gpt_prompts = SingleWholeFileFunctionPrompts()
|
self.gpt_prompts = SingleWholeFileFunctionPrompts()
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from jsonschema import Draft7Validator
|
|
||||||
|
|
||||||
from aider import diffs
|
from aider import diffs
|
||||||
|
|
||||||
from ..dump import dump # noqa: F401
|
from ..dump import dump # noqa: F401
|
||||||
|
@ -48,8 +46,6 @@ class WholeFileFunctionCoder(Coder):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Draft7Validator.check_schema(self.functions[0])
|
|
||||||
|
|
||||||
self.gpt_prompts = WholeFileFunctionPrompts()
|
self.gpt_prompts = WholeFileFunctionPrompts()
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue