Skip to content

Commit 0fbf179

Browse files
authored
Merge pull request #61 from OpenBMB/refactor_chatEngine
refactor: streamline configuration variable access
2 parents d04cc54 + 2f9b561 commit 0fbf179

30 files changed

+1793
-1441
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 忽略私人配置文件,包含有api_key等信息
2-
config private.yml
3-
private.yml
2+
config private.toml
3+
private.toml
44

55
# Byte-compiled / optimized / DLL files
66
__pycache__/
@@ -181,4 +181,5 @@ prompt_output/
181181
log.txt
182182
.chroma_db
183183
config.yml
184+
config.toml
184185
.pre-commit-config.yaml

README.md

Lines changed: 94 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
[中文](README_CN.md) | [Background](#-background) | [Features](#-features) | [Getting Started](#-getting-started) | [Future Work](#-future-work) | [Supported Language](#-supported-language) | [Citation](#-citation)
2-
3-
# 🤗 Introduction
4-
5-
RepoAgent is an Open-Source project driven by Large Language Models(LLMs) that aims to provide an intelligent way to document projects.
6-
It is designed to be a handy tool for developers who need to organize their code and cooperate with teammates.
7-
8-
**Paper:** http://arxiv.org/abs/2402.16667
9-
10-
![RepoAgent](assets/images/RepoAgent.png)
1+
<h1 align="center"><em> RepoAgent: An LLM-Powered Framework for Repository-level Code Documentation Generation.</em></h1>
2+
3+
<p align="center">
4+
<img src="https://img.shields.io/pypi/dm/repoagent" alt="PyPI - Downloads"/>
5+
<a href="https://pypi.org/project/repoagent/">
6+
<img src="https://img.shields.io/pypi/v/repoagent" alt="PyPI - Version"/>
7+
</a>
8+
<a href="Pypi">
9+
<img src="https://img.shields.io/pypi/pyversions/repoagent" alt="PyPI - Python Version"/>
10+
</a>
11+
<img alt="GitHub License" src="https://img.shields.io/github/license/LOGIC-10/RepoAgent">
12+
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/LOGIC-10/RepoAgent?style=social">
13+
<img alt="GitHub issues" src="https://img.shields.io/github/issues/LOGIC-10/RepoAgent">
14+
<a href="https://arxiv.org/abs/2402.16667v1">
15+
<img src="https://img.shields.io/badge/cs.CL-2402.16667-b31b1b?logo=arxiv&logoColor=red" alt="arXiv"/>
16+
</a>
17+
</p>
18+
19+
<p align="center">
20+
<img src="assets/images/RepoAgent.png" alt="RepoAgent"/>
21+
</p>
22+
23+
<p align="center">
24+
<a href="https://github.com/LOGIC-10/RepoAgent/blob/main/README.md">English readme</a>
25+
26+
<a href="https://github.com/LOGIC-10/RepoAgent/blob/main/README_CN.md">简体中文 readme</a>
27+
</p>
1128

1229
## 👾 Background
30+
1331
In the realm of computer programming, the significance of comprehensive project documentation, including detailed explanations for each Python file, cannot be overstated. Such documentation serves as the cornerstone for understanding, maintaining, and enhancing the codebase. It provides essential context and rationale for the code, making it easier for current and future developers to comprehend the purpose, functionality, and structure of the software. It not only facilitates current and future developers in grasping the project's purpose and structure but also ensures that the project remains accessible and modifiable over time, significantly easing the learning curve for new team members.
1432

1533
Traditionally, creating and maintaining software documentation demanded significant human effort and expertise, a challenge for small teams without dedicated personnel. The introduction of Large Language Models (LLMs) like GPT has transformed this, enabling AI to handle much of the documentation process. This shift allows human developers to focus on verification and fine-tuning, greatly reducing the manual burden of documentation.
@@ -31,13 +49,13 @@ Traditionally, creating and maintaining software documentation demanded signific
3149

3250
### Installation Method
3351

34-
<!-- #### Using pip (Recommended for Users)
52+
#### Using pip (Recommended for Users)
3553

3654
Install the `repoagent` package directly using pip:
3755

3856
```bash
3957
pip install repoagent
40-
``` -->
58+
```
4159

4260
#### Development Setup Using PDM
4361

@@ -56,7 +74,7 @@ If you're looking to contribute or set up a development environment:
5674
```bash
5775
git clone https://github.com/LOGIC-10/RepoAgent.git
5876
cd RepoAgent
59-
```
77+
```
6078

6179
- **Setup with PDM**
6280

@@ -76,91 +94,100 @@ If you're looking to contribute or set up a development environment:
7694

7795
### Configuring RepoAgent
7896

79-
First, configure the OpenAI API parameters in the config.yml file.
80-
For details on obtaining these, please refer to [OpenAI API](https://beta.openai.com/docs/developer-quickstart/your-api-keys).
81-
82-
In the `config.yml` file, configure other parameters like OpenAI API, the destination repository path, document language, and so on:
83-
84-
```yaml
85-
api_keys:
86-
gpt-3.5-turbo-16k:
87-
- api_key: sk-XXXX
88-
base_url: https://example.com/v1/
89-
api_type: azure
90-
api_version: XXX
91-
engine: GPT-35-Turbo-16k
92-
# you can use any kwargs supported by openai.ChatCompletion here
93-
- api_key: sk-xxxxx
94-
organization: org-xxxxxx
95-
model: gpt-3.5-turbo-16k
96-
...
97-
98-
default_completion_kwargs:
99-
model: gpt-4-1106
100-
temperature: 0.2
101-
request_timeout: 60
102-
103-
repo_path: /path/to/your/repo
104-
project_hierarchy: .project_hierarchy # This is a folder, where we store the project hierarchy and metainfo. This can be shared with your team members.
105-
Markdown_Docs_folder: Markdown_Docs # The folder in the root directory of your target repository to store the documentation.
106-
ignore_list: ["ignore_file1.py", "ignore_file2.py", "ignore_directory"] # Ignore some py files or folders that you don't want to generate documentation for by giving relative paths in ignore_list.
107-
whitelist_path: /path/of/whitelist_path_json #if you provide the whitelist json with the same structure in Metainfo, RepoAgent will only process the given part. This is useful in a very big project, like "higgingface Transformers"
108-
109-
language: en # Two-letter language codes (ISO 639-1 codes), e.g. `language: en` for English. Refer to Supported Language for more languages.
110-
max_thread_count: 10 # We support multiprocessing to speedup the process
111-
max_document_tokens: 1024 # the maximum number of tokens in a document generated
112-
log_level: info
97+
Before configuring specific parameters for RepoAgent, please ensure that the OpenAI API is configured as an environment variable in the command line:
98+
99+
```sh
100+
export OPENAI_API_KEY=YOUR_API_KEY # on Linux/Mac
101+
set OPENAI_API_KEY=YOUR_API_KEY # on Windows
102+
$Env:OPENAI_API_KEY = "YOUR_API_KEY" # on Windows (PowerShell)
103+
```
104+
105+
Use `repoagent configure` if you need to modify the running parameters.
106+
107+
```sh
108+
Enter the path to target repository:
109+
Enter the project hierarchy file name [.project_doc_record]:
110+
Enter the Markdown documents folder name [markdown_docs]:
111+
Enter files or directories to ignore, separated by commas []:
112+
Enter the language (ISO 639 code or language name, e.g., 'en', 'eng', 'English') [Chinese]:
113+
Enter the maximum number of threads [4]:
114+
Enter the maximum number of document tokens [1024]:
115+
Enter the log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) [INFO]:
116+
Enter the model [gpt-3.5-turbo]:
117+
Enter the temperature [0.2]:
118+
Enter the request timeout (seconds) [60.0]:
119+
Enter the base URL [https://api.openai.com/v1]:
113120
```
114121

115-
### Run RepoAgent
122+
## Run RepoAgent
116123

117124
Enter the root directory of RepoAgent and try the following command in the terminal:
118125
```sh
119-
python -m repo_agent #this command will generate doc, or update docs(pre-commit-hook will automatically call this)
126+
repoagent run #this command will generate doc, or update docs(pre-commit-hook will automatically call this)
127+
```
128+
129+
The run command supports the following optional flags (if set, will override config defaults):
130+
131+
- `-m`, `--model` TEXT: Specifies the model to use for completion. Default: `gpt-3.5-turbo`
132+
- `-t`, `--temperature` FLOAT: Sets the generation temperature for the model. Lower values make the model more deterministic. Default: `0.2`
133+
- `-r`, `--request-timeout` INTEGER: Defines the timeout in seconds for the API request. Default: `60`
134+
- `-b`, `--base-url` TEXT: The base URL for the API calls. Default: `https://api.openai.com/v1`
135+
- `-tp`, `--target-repo-path` PATH: The file system path to the target repository. Used as the root for documentation generation. Default: `path/to/your/target/repository`
136+
- `-hp`, `--hierarchy-path` TEXT: The name or path for the project hierarchy file, used to organize documentation structure. Default: `.project_doc_record`
137+
- `-mdp`, `--markdown-docs-path` TEXT: The folder path where Markdown documentation will be stored or generated. Default: `markdown_docs`
138+
- `-i`, `--ignore-list` TEXT: A list of files or directories to ignore during documentation generation, separated by commas.
139+
- `-l`, `--language` TEXT: The ISO 639 code or language name for the documentation. Default: `Chinese`
140+
- `-ll`, `--log-level` [DEBUG|INFO|WARNING|ERROR|CRITICAL]: Sets the logging level for the application. Default: `INFO`
141+
142+
143+
You can also try the following feature
120144

121-
# you can also try the follow feature
122-
python -m repo_agent clean #this command will remove repoagent-related cache
123-
python -m repo_agent print #this command will print how repo-agent parse the target repo
124-
python -m repo_agent diff #this command will check what docs will be updated/generated based on current code change
145+
```sh
146+
repoagent clean # Remove repoagent-related cache
147+
repoagent print-hierarchy # Print how repo-agent parse the target repo
148+
repoagent diff # Check what docs will be updated/generated based on current code change
125149
```
126150

127151
If it's your first time generating documentation for the target repository, RepoAgent will automatically create a JSON file maintaining the global structure information and a folder named Markdown_Docs in the root directory of the target repository for storing documents.
128152
129-
The paths of the global structure information json file and the documentation folder can be configured in `config.yml`.
130-
131-
Once you have initially generated the global documentation for the target repository, or if the project you cloned already contains global documentation information, you can then seamlessly and automatically maintain internal project documentation with your team by configuring the **pre-commit hook** in the target repository!
153+
Once you have initially generated the global documentation for the target repository, or if the project you cloned already contains global documentation information, you can then seamlessly and automatically maintain internal project documentation with your team by configuring the **pre-commit hook** in the target repository!
132154
133-
### Configuring the Target Repository
155+
### Use `pre-commit`
134156
135157
RepoAgent currently supports generating documentation for projects, which requires some configuration in the target repository.
136158
137159
First, ensure that the target repository is a git repository and has been initialized.
138-
```
160+
161+
```sh
139162
git init
140163
```
141164
Install pre-commit in the target repository to detect changes in the git repository.
142165
143-
```
166+
```sh
144167
pip install pre-commit
145168
```
146169
Create a file named `.pre-commit-config.yaml` in the root directory of the target repository. An example is as follows:
147170
148-
```
171+
```yml
149172
repos:
150173
- repo: local
151174
hooks:
152175
- id: repo-agent
153176
name: RepoAgent
154-
entry: python path/to/your/repo_agent/runner.py
177+
entry: repoagent
155178
language: system
179+
pass_filenames: false # prevent from passing filenames to the hook
156180
# You can specify the file types that trigger the hook, but currently only python is supported.
157181
types: [python]
158182
```
183+
159184
For specific configuration methods of hooks, please refer to [pre-commit](https://pre-commit.com/#plugins).
160185
After configuring the yaml file, execute the following command to install the hook.
161-
```
186+
187+
```sh
162188
pre-commit install
163189
```
190+
164191
In this way, each git commit will trigger the RepoAgent's hook, automatically detecting changes in the target repository and generating corresponding documents.
165192
Next, you can make some modifications to the target repository, such as adding a new file to the target repository, or modifying an existing file.
166193
You just need to follow the normal git workflow: git add, git commit -m "your commit message", git push
@@ -178,25 +205,21 @@ We utilized the default model **gpt-3.5-turbo** to generate documentation for th
178205
**In the end, you can flexibly adjust the output format, template, and other aspects of the document by customizing the prompt. We are excited about your exploration of a more scientific approach to Automated Technical Writing and your contributions to the community.**
179206

180207
### Exploring chat with repo
208+
181209
We conceptualize **Chat With Repo** as a unified gateway for these downstream applications, acting as a connector that links RepoAgent to human users and other AI agents. Our future research will focus on adapting the interface to various downstream applications and customizing it to meet their unique characteristics and implementation requirements.
182210

183211
Here we demonstrate a preliminary prototype of one of our downstream tasks: Automatic Q&A for Issues and Code Explanation. You can start the server by running the following code.
184-
```bash
185-
python -m repo_agent.chat_with_repo
212+
213+
```sh
214+
repoagent chat-with-repo
186215
```
187216

188217
## ✅ Future Work
189218

190-
- [x] Identification and maintenance of parent-child relationship hierarchy structure between objects
191-
- [x] Implement Black commit
192-
- [x] **Bi-direct reference** Construct Bi-directional reference topology
193-
- [x] **chat with repo** Chat with the repository by giving code and document at the same time
194-
- [x] Automatically generate better visualizations such as Gitbook
219+
- [x] Support install and configure via `pip install repoagent`
195220
- [ ] Generate README.md automatically combining with the global documentation
196221
- [ ] **Multi-programming-language support** Support more programming languages like Java, C or C++, etc.
197222
- [ ] Local model support like Llama, chatGLM, Qwen, GLM4, etc.
198-
- [ ] Support install and configure via `pip install repoagent`
199-
- [X] Automatically generate Gitbook for better visualization effects
200223

201224
## 🥰 Featured Cases
202225

@@ -206,45 +229,6 @@ Here are featured cases that have adopted RepoAgent.
206229
- [ChatDev](https://github.com/OpenBMB/ChatDev): Collaborative AI agents for software development.
207230
- [XAgent](https://github.com/OpenBMB/XAgent): An Autonomous LLM Agent for Complex Task Solving.
208231

209-
## 🇺🇳 Supported Language
210-
211-
Set the target language with the two-letter language codes (ISO 639-1 codes), Click on the 'Languages List' section below to expand the list of supported languages.
212-
213-
<details>
214-
<summary>Languages List</summary>
215-
216-
| Flag | Code | Language |
217-
|------|------|------------|
218-
| 🇬🇧 | en | English |
219-
| 🇪🇸 | es | Spanish |
220-
| 🇫🇷 | fr | French |
221-
| 🇩🇪 | de | German |
222-
| 🇨🇳 | zh | Chinese |
223-
| 🇯🇵 | ja | Japanese |
224-
| 🇷🇺 | ru | Russian |
225-
| 🇮🇹 | it | Italian |
226-
| 🇰🇷 | ko | Korean |
227-
| 🇳🇱 | nl | Dutch |
228-
| 🇵🇹 | pt | Portuguese |
229-
| 🇸🇦 | ar | Arabic |
230-
| 🇹🇷 | tr | Turkish |
231-
| 🇸🇪 | sv | Swedish |
232-
| 🇩🇰 | da | Danish |
233-
| 🇫🇮 | fi | Finnish |
234-
| 🇳🇴 | no | Norwegian |
235-
| 🇵🇱 | pl | Polish |
236-
| 🇨🇿 | cs | Czech |
237-
| 🇭🇺 | hu | Hungarian |
238-
| 🇬🇷 | el | Greek |
239-
| 🇮🇱 | he | Hebrew |
240-
| 🇹🇭 | th | Thai |
241-
| 🇮🇳 | hi | Hindi |
242-
| 🇧🇩 | bn | Bengali |
243-
244-
</details>
245-
246-
> e.g., `language: en` for English.
247-
248232
## 📊 Citation
249233

250234
```bibtex

0 commit comments

Comments
 (0)