Moatless Tools是一个爱好项目,我可以尝试一些关于如何使用LLM在大型现有代码库中编辑代码的想法。我认为,与其依靠代理商将其方式推定为解决方案,而是建立良好的工具以将正确的上下文插入提示并处理响应至关重要。
目前,我专注于Moatless-Tree-Search,这是一种扩展的Moatless-Tools的扩展版本,它构建了带有并行解决方案的节点的树结构,并使用树搜索来查找最佳轨迹。 Moatless-Tools中的代码已简化,现在已成为此扩展的代码库的简化版本。
我使用SWE基础基准作为验证我的想法的一种方式。
使用Claude 3.5 SONNET V20241022,使用0.0.3版,我获得了38.3%的求解率。每个实例的平均成本为$ 0.30。
在此版本中,我能够从27%求解的三个主要原因:
Claude 3.5十四行诗和计算机使用
已调整了该解决方案以使用新版本的Claude 3.5十四行诗中引入的text_editor_20241022工具。在编辑现有代码时,这提供了更稳定的结果。
无城市的测试床
我设置了一个基于Kubernetes的解决方案,以运行测试并向代理提供有关测试结果的反馈。值得注意的是,代理必须独立识别测试,并且不能依靠每个实例的PASS_TO_PASS或FAIL_TO_PASS数据。
更灵活的模型
在较早版本的无护城内工具中,代理遵循刚性流,首先检索了内容,然后编辑了代码。现在,根据情况,它可以在代码检索或编辑的操作之间动态选择。
尝试在Google Colab上设置的Claude 3.5十四行诗V20241022评估
使用Claude 3.5十四行诗,使用0.0.2版,我获得了26.7%的求解率,每个实例的成本更高。
尝试在Google Colab上设置的Claude 3.5评估
无城市工具0.0.1的求解率为24%,每个基准实例平均耗资0.13美元,用于使用GPT-4O解决。使用300个实例运行SWE Bench Lite数据集的费用约为40美元。
在Google Colab中尝试一下
我专注于测试自己的想法,该项目目前有些混乱。我的计划是在未来的时期内组织它。但是,请随意克隆回购并尝试运行此笔记本:
在进行评估之前,您需要:
您可以通过任何一个配置这些设置:
.env文件(从.env.example复制): cp .env.example .env
# Edit .env with your values # Directory for storing vector index store files
export INDEX_STORE_DIR= " /tmp/index_store "
# Directory for storing clonedrepositories
export REPO_DIR= " /tmp/repos "
# Required: At least one LLM provider API key
export OPENAI_API_KEY= " <your-key> "
export ANTHROPIC_API_KEY= " <your-key> "
# ...or Base URL for custom LLM API service (optional)
export CUSTOM_LLM_API_BASE= " <your-base-url> "
export CUSTOM_LLM_API_KEY= " <your-key> "
# Required: API Key for Voyage Embeddings
export VOYAGE_API_KEY= " <your-key> "
# Optional: Configuration for testbed environment (https://github.com/aorwall/moatless-testbeds)
export TESTBED_API_KEY= " <your-key> "
export TESTBED_BASE_URL= " <your-base-url> " 基本设置使用AgenticLoop求解SWE基础实例。
from moatless . agent import ActionAgent
from moatless . agent . code_prompts import SIMPLE_CODE_PROMPT
from moatless . benchmark . swebench import create_repository
from moatless . benchmark . utils import get_moatless_instance
from moatless . completion import CompletionModel
from moatless . file_context import FileContext
from moatless . index import CodeIndex
from moatless . loop import AgenticLoop
from moatless . actions import FindClass , FindFunction , FindCodeSnippet , SemanticSearch , RequestMoreContext , RequestCodeChange , Finish , Reject
index_store_dir = "/tmp/index_store"
repo_base_dir = "/tmp/repos"
persist_path = "trajectory.json"
instance = get_moatless_instance ( "django__django-16379" )
completion_model = CompletionModel ( model = "gpt-4o" , temperature = 0.0 )
repository = create_repository ( instance )
code_index = CodeIndex . from_index_name (
instance [ "instance_id" ], index_store_dir = index_store_dir , file_repo = repository
)
actions = [
FindClass ( code_index = code_index , repository = repository ),
FindFunction ( code_index = code_index , repository = repository ),
FindCodeSnippet ( code_index = code_index , repository = repository ),
SemanticSearch ( code_index = code_index , repository = repository ),
RequestMoreContext ( repository = repository ),
RequestCodeChange ( repository = repository , completion_model = completion_model ),
Finish (),
Reject ()
]
file_context = FileContext ( repo = repository )
agent = ActionAgent ( actions = actions , completion = completion_model , system_prompt = SIMPLE_CODE_PROMPT )
loop = AgenticLoop . create (
message = instance [ "problem_statement" ],
agent = agent ,
file_context = file_context ,
repository = repository ,
persist_path = persist_path ,
max_iterations = 50 ,
max_cost = 2.0 # Optional: Set maximum cost in dollars
)
final_node = loop . run ()
if final_node :
print ( final_node . observation . message )