|
@@ -1,2 +1,94 @@
|
|
|
# mentat
|
|
|
|
|
|
+https://github.com/AbanteAI/mentat
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## Usage
|
|
|
+
|
|
|
+python 3.10
|
|
|
+
|
|
|
+
|
|
|
+准备一个 openai gpt4 key,新建 .env文件,输入:
|
|
|
+
|
|
|
+```
|
|
|
+OPENAI_API_KEY=sk-rju8J2X
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+执行:
|
|
|
+
|
|
|
+```
|
|
|
+python3 -m venv .venv
|
|
|
+source .venv/bin/activat
|
|
|
+
|
|
|
+git clone https://github.com/AbanteAI/mentat.git
|
|
|
+cd mentat
|
|
|
+pip install -e .
|
|
|
+
|
|
|
+mentat path/to/directory --exclude exclude_me.py dir1/dir2 **/*.ts
|
|
|
+mentat /workspaces/mentat/setup.py
|
|
|
+```
|
|
|
+
|
|
|
+## 源码分析
|
|
|
+
|
|
|
+输入命令 `mentat /workspaces/mentat/setup.py` 会执行如下命令:
|
|
|
+
|
|
|
+```
|
|
|
+mentat=mentat.app:run_cli
|
|
|
+
|
|
|
+# 带参数运行
|
|
|
+ run(
|
|
|
+ expand_paths(paths),
|
|
|
+ expand_paths(exclude_paths),
|
|
|
+ no_code_map,
|
|
|
+ diff,
|
|
|
+ pr_diff,
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+第一个参数为文件路径,或者文件夹。后面参数为排除路径等。
|
|
|
+
|
|
|
+```
|
|
|
+ setup_api_key()
|
|
|
+ loop(paths, exclude_paths, cost_tracker, no_code_map, diff, pr_diff)
|
|
|
+```
|
|
|
+
|
|
|
+先设置 key,然后循环:
|
|
|
+```
|
|
|
+ while True:
|
|
|
+ if need_user_request:
|
|
|
+ user_response = user_input_manager.collect_user_input()
|
|
|
+ conv.add_user_message(user_response)
|
|
|
+
|
|
|
+ file_edits = conv.get_model_response(parser, config)
|
|
|
+ file_edits = [
|
|
|
+ file_edit
|
|
|
+ for file_edit in file_edits
|
|
|
+ if file_edit.is_valid(code_file_manager, config)
|
|
|
+ ]
|
|
|
+ if file_edits:
|
|
|
+ need_user_request = get_user_feedback_on_edits(
|
|
|
+ config,
|
|
|
+ conv,
|
|
|
+ code_context,
|
|
|
+ user_input_manager,
|
|
|
+ code_file_manager,
|
|
|
+ file_edits,
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ need_user_request = True
|
|
|
+```
|
|
|
+这里循环等待用户输入,将用户输入 `conv.add_user_message(user_response)` 加入conv对象。那么继续深入这个 Conversation 类,这个是调用 openai 接口。
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|