ExileChat
AI 知识库 - RAG 流程基础功能实现
本项目基于 FastAPI 与tortoise-orm 等异步方式结合 openai 实现。
文档规整
当前仅支持 .docx 类型,后续补充 .pdf 等类型。
# /ExileChat/test/test_ai/test_document_chunk.py
from utils.ai.document_chunk import DocumentChunk
if __name__ == "__main__":
# 文档的路径或静态资源服务器的地址
file_path = "./test/测试文档.docx"
# 文档中图片存放的路径或图片服务器的地址,`image_base_path` 与 `image_base_url` 使用其一即可
image_base_path = "./test/test_ai"
image_base_url = "https://www.example.com"
dc = DocumentChunk(image_base_path=image_base_path, is_debug=True)
dc.process_file(file_path)
大模型调用
你需要查阅对应大模型的文档以及准备 api_key,按照例子来使用它。当前仅支持 OpenAI、AzureOpenAI、Moonshot,当然你可以自行添加其他模型,你需要根据以下代码示例实现对应的初始化工作。
# /ExileChat/utils/ai/llm_engine.py
# 代码片段
class ModelClient:
"""Models Client"""
api_key: str = None
kwargs: dict = {}
@classmethod
def open_ai(cls):
"""OpenAI Client"""
...
@classmethod
def azure_open_ai(cls):
"""AzureOpenAI Client"""
...
@classmethod
def ():
...
:
():
.model_name = model_name
.api_key = api_key
.is_debug = is_debug
.args = args
.kwargs = kwargs
ModelClient.api_key = api_key
ModelClient.kwargs = kwargs
.client_dict = {
: ModelClient.open_ai,
: ModelClient.azure_open_ai,
: ModelClient.moonshot,
}
...


