DocAPI is a Python package that automatically generates API documentation using LLM.
Project description
[ English | 中文 ]
DocAPI is a Python package that uses LLM to automatically generate API documentation.
Features
-
The Flask framework supports automatic scanning of the routing structure of API services;
-
Supports a variety of mainstream commercial and open source models at home and abroad;
-
Supports automatic document generation and partial document update;
-
Supports Chinese and English documents;
-
Supports web page deployment to display API documentation.
Installation
pip install -U docapi
or
pip install -U docapi -i https://pypi.org/simple
GitHub source code installation
pip install git+https://github.com/Shulin-Zhang/docapi
Usage
Automatically scan the routing structure. This is only valid for flask projects and must be used in the environment of api projects.
OpenAI:
export OPENAI_API_KEY=api_key
export OPENAI_API_MODEL=gpt-4o-mini
# Generate documents
docapi generate server.py --lang en
# Update documents
docapi update server.py --lang en
# Start web service
docapi serve
Azure OpenAI:
export AZURE_OPENAI_API_KEY=api_key
export AZURE_OPENAI_ENDPOINT=endpoint
export OPENAI_API_VERSION=version
export AZURE_OPENAI_MODEL=gpt-4o-mini
# 生成文档
docapi generate server.py
# 更新文档
docapi update server.py
# 启动web服务
docapi serve
Qianwen, Open source deployment:
export OPENAI_API_KEY=api_key
export OPENAI_API_BASE=api_base_url
export OPENAI_API_MODEL=model_name
# Generate documents
docapi generate server.py --lang en
# Update documents
docapi update server.py --lang en
# Start web service
docapi serve
Baidu Qianfan:
export QIANFAN_ACCESS_KEY=access_key
export QIANFAN_SECRET_KEY=secret_key
export QIANFAN_MODEL=ERNIE-3.5-8K
# Generate documents
docapi generate server.py --lang en
# Update documents
docapi update server.py --lang en
# Start web service
docapi serve
ZhipuAI:
export ZHIPUAI_API_KEY=api_key
export ZHIPUAI_MODEL=glm-4-flash
# Generate documents
docapi generate server.py
# Update documents
docapi update server.py
# Start web service
docapi serve
Code calls
import os
from docapi import DocAPI, llm_builder, prompt
from docapi.scanner import flask_scanner
os.environ['OPENAI_API_KEY'] = "api_key"
os.environ['OPENAI_API_BASE'] = "api_base"
os.environ['OPENAI_API_MODEL'] = "model_name"
docapi = DocAPI.build(lang="en")
# docapi = DocAPI(llm=llm_builder.build_llm(), scanner=flask_scanner, prompt=prompt.doc_prompt_en)
docapi.generate("flask_project/flask_server.py", "docs")
# docapi.update("flask_project/flask_server.py", "docs")
# docapi.serve("docs", ip="127.0.0.1", port=8080)
Changelog
- [2024-11-17] Support Zhipu AI, Baidu Qianfan model, optimize document structure, and add javascript code examples; Remove the execution mode that uses the configuration file.
Supported Models
-
OpenAI
-
AzureOpenAI
-
Tongyi Qianwen
-
Zhipu AI
-
Baidu Qianfan
-
Open source model
Supported API Frameworks
- Flask
Automatic scanning is only valid for the Flask framework and is recommended for use on Flask services.
API Web Page
TODO
-
Supports large models such as Wenxin Yiyan and Zhipu AI. -
Supports automatic scanning of frameworks such as Django.
-
Supports online web page display of documents. -
Supports custom document templates.
-
Multithreading accelerates requests.
-
Import to postman.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docapi-0.1.1.tar.gz
.
File metadata
- Download URL: docapi-0.1.1.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15070afdae0a001ee0fb4eb60eb76fd9c07f44e130c38dff36fac045a8e80267 |
|
MD5 | a6706005a89dda4002682efaa55849ac |
|
BLAKE2b-256 | 7c2dce751dd7388dc158c9e37e09a1462101a5caf6ead42ec92a6c7a265e0507 |
File details
Details for the file docapi-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: docapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de413acf7c99877b6e48c2777ebec2f0b8fe795ca4d1e3e9a90661a03daa7124 |
|
MD5 | b428705fe645e09fab49d866427d908e |
|
BLAKE2b-256 | 708b66b57793b1c48bb13974335541fa73fc212b9d075296810cb65025cf57e6 |