Skip to content

Commit

Permalink
准备好v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NewToolAI committed Dec 5, 2024
1 parent 6b27a7e commit de38014
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 43 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

\[ 中文 | [English](README_en.md) \]

DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,支持 Flask 和 Django。
DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,目前支持 Flask 和 Django。

## 注意

Expand All @@ -18,7 +18,7 @@ DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,支持 Flask

## 特性

- 支持自动扫描API服务的路由结构
- 支持Flask和Django,自动扫描API服务的路由结构

- 支持多种国内外主流商业和开源模型;

Expand All @@ -40,6 +40,8 @@ DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,支持 Flask

- [2024-12-02] windows操作系统测试通过 (需要使用power shell 或 windows terminal);新的模型名称提供方式,防止环境变量冲突 (参照下面使用方法)。

- [2024-12-05] 支持Django,4.2.x版本测试通过。

## 安装

```bash
Expand All @@ -66,17 +68,23 @@ export DOCAPI_MODEL=openai:gpt-4o-mini

export OPENAI_API_KEY=api_key

# Generate documentation
# Flask框架生成文档
docapi generate server.py

# Update documentation
# Django框架生成文档
# docapi generate manage.py

# Flask框架更新文档
docapi update server.py

# Start the web service
# Django框架更新文档
# docapi update manage.py

# 启动文档web服务
docapi serve
```

**[更多使用方法](USAGE.md)**
*[更多使用方法](USAGE.md)*


## 支持模型
Expand Down Expand Up @@ -118,5 +126,3 @@ docapi serve
- ~~支持Windows操作系统.~~

- ~~支持django框架。~~

- 导入到postman。
38 changes: 22 additions & 16 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

\[ [中文](README.md) | English \]

DocAPI is a Python package that leverages LLMs to automatically generate API documentation, supporting both Flask and Django frameworks.
DocAPI is a Python package that automatically generates API documentation using LLMs. It currently supports Flask and Django frameworks.

## Notice

Expand All @@ -18,15 +18,15 @@ DocAPI is a Python package that leverages LLMs to automatically generate API doc

## Features

- Supports automatic scanning of API service routing structure.
- Supports various mainstream commercial and open-source models, both domestic and international.
- Supports automatic generation and partial updates of documentation.
- Supports API documentation in multiple languages (requires large model support).
- Supports web-based deployment for displaying API documentation.
- Supports both Flask and Django, automatically scanning the routing structure of API services.

- Supports a variety of popular commercial and open-source models, both domestic and international.

- Supports automatic generation of documentation and partial updates to existing documentation.

- Supports API documentation in multiple languages (requires support from large models).

- Supports deployment of web pages for displaying API documentation.

## Changelog

Expand All @@ -40,6 +40,8 @@ DocAPI is a Python package that leverages LLMs to automatically generate API doc

- **[2024-12-02]** Successfully tested on Windows OS (requires PowerShell or Windows Terminal); introduced a new way of specifying model names to prevent environment variable conflicts (see usage instructions below).

- **[2024-12-05]** Supported Django, tested successfully with version 4.2.x.

## Installation

```bash
Expand All @@ -66,17 +68,23 @@ export DOCAPI_MODEL=openai:gpt-4o-mini

export OPENAI_API_KEY=api_key

# Generate documentation
# Generate documentation for Flask framework
docapi generate server.py

# Update documentation
# Generate documentation for Django framework
# docapi generate manage.py

# Update documentation for Flask framework
docapi update server.py

# Start the web service
# Update documentation for Django framework
# docapi update manage.py

# Start the documentation web service
docapi serve
```

**[More usage methods](USAGE.md)**
*[More usage methods](USAGE.md)*

## Supported Models

Expand Down Expand Up @@ -117,5 +125,3 @@ docapi serve
- ~~Support Windows OS.~~

- ~~Add support for Django framework.~~

- Enable export to Postman.
20 changes: 13 additions & 7 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export DOCAPI_MODEL=openai:gpt-4o-mini

export OPENAI_API_KEY=api_key

# Generate documentation
# Generate documentation for Flask framework
docapi generate server.py

# Update documentation
# Generate documentation for Django framework
# docapi generate manage.py

# Update documentation for Flask framework
docapi update server.py

# Start the web service
# Update documentation for Django framework
# docapi update manage.py

# Start the documentation web service
docapi serve
```

Expand Down Expand Up @@ -49,10 +55,10 @@ export DOCAPI_MODEL=xai:grok-beta
export XAI_API_KEY=api_key

# Generate documentation
docapi generate server.py
docapi generate manage.py

# Update documentation
docapi update server.py
docapi update manage.py

# Start the web service
docapi serve
Expand Down Expand Up @@ -101,10 +107,10 @@ export DOCAPI_MODEL=aliyun:qwen-turbo
export DASHSCOPE_API_KEY=api_key

# Generate documentation
docapi generate server.py --workers 6
docapi generate manage.py --workers 6

# Update documentation
docapi update server.py --workers 6
docapi update manage.py --workers 6

# Start the web service
docapi serve
Expand Down
4 changes: 2 additions & 2 deletions docapi/docapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
*Path: `{path}`*
'''

INDEX_STR = '''## DocAPI is a Python package that automatically generates API documentation using LLM.
INDEX_STR = '''### DocAPI is a Python package that automatically generates API documentation using LLMs. It currently supports Flask and Django frameworks.
## DocAPI是一个Python包,它使用LLM自动生成API文档
### DocAPI 是一个使用 LLM 自动生成 API 文档的 Python 包,目前支持 Flask 和 Django。
[Github: https://github.com/Shulin-Zhang/docapi](https://github.com/Shulin-Zhang/docapi)
'''
Expand Down
1 change: 1 addition & 0 deletions docapi/scanner/django_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import hashlib
import inspect

import django
from django.urls import get_resolver
from django.urls import URLPattern, URLResolver
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "docapi"
version = "0.1.7"
description = "DocAPI is a Python package that automatically generates API documentation using LLM, with support for both Flask and Django frameworks."
version = "1.0.0"
description = "DocAPI is a Python package that automatically generates API documentation using LLMs. It currently supports Flask and Django frameworks."
authors = ["zhangshulin <[email protected]>"]
license = "Apache License Version 2.0"
readme = "README.md"
Expand All @@ -16,7 +16,7 @@ qianfan = "^0.4.12.1"
zhipuai = "^2.1.5.20230904"
python-dotenv = "^1.0.1"
flask = "^3.0.0"
django = "4.2.0"
django = "^4.2.0"

[tool.poetry.scripts]
docapi = "docapi.main:run"
Expand Down
2 changes: 2 additions & 0 deletions test/django_project/students/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@


def student_list(request):
'''学生列表'''
students = Student.objects.all().values('id', 'name', 'age', 'grade', 'email')
return JsonResponse(list(students), safe=False)


# 增加学生
def student_add(request):
if request.method == 'POST':
name = request.POST.get('name')
Expand Down
12 changes: 5 additions & 7 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ def test_code(env_path, model):
load_dotenv(dotenv_path=env_path)

docapi = DocAPI.build(lang="zh", model=model)
docapi.generate("django_project/manage.py", "django_project/docs", )
docapi.update("django_project/manage.py", "django_project/docs")

docapi.generate("flask_project/server.py", "docs", )

docapi.update("flask_project/server.py", "docs")


def test(env_path):
def test(env):
for model in MODELS:
test_flask(env_path, model)
test_flask(env, model)

test_code(env_path, MODELS[-1])
test_code(env, MODELS[-1])

os.system(f'docapi serve flask_project/docs')

Expand Down

0 comments on commit de38014

Please sign in to comment.