{"id":14459329,"url":"https://github.com/billvsme/law_ai","last_synced_at":"2025-08-28T17:31:28.008Z","repository":{"id":201233223,"uuid":"707270542","full_name":"billvsme/law_ai","owner":"billvsme","description":"💼法律AI助手，法律RAG，通过全部200+本法律手册📖、网页搜索内容💻结合LLM回答你的问题，并且给出相应的法规和网站，基于⚡️ langchain，Gradio，openai，chroma，duckduckgo-search","archived":false,"fork":false,"pushed_at":"2024-01-22T06:29:48.000Z","size":2104,"stargazers_count":82,"open_issues_count":1,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-01T20:04:07.452Z","etag":null,"topics":["ai","chroma","gradio","langchain","openai","python"],"latest_commit_sha":null,"homepage":"https://law.vmaig.com/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/billvsme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-10-19T14:55:57.000Z","updated_at":"2024-08-29T09:59:04.000Z","dependencies_parsed_at":"2024-01-02T15:44:28.018Z","dependency_job_id":null,"html_url":"https://github.com/billvsme/law_ai","commit_stats":null,"previous_names":["billvsme/law_ai"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billvsme%2Flaw_ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billvsme%2Flaw_ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billvsme%2Flaw_ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billvsme%2Flaw_ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/billvsme","download_url":"https://codeload.github.com/billvsme/law_ai/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231291056,"owners_count":18353714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chroma","gradio","langchain","openai","python"],"created_at":"2024-09-01T20:01:27.728Z","updated_at":"2024-12-25T22:30:20.342Z","avatar_url":"https://github.com/billvsme.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \n![Python version](https://img.shields.io/badge/python-3.9+-blue)\n[![web ui](https://img.shields.io/badge/WebUI-Gradio-important)](https://www.gradio.app/)\n[![Twitter follow](https://img.shields.io/twitter/follow/gradio?style=social\u0026label=follow)](https://twitter.com/billvsme)\n\n\u003c/div\u003e\n\n法律AI助手\n=========\n\n法律AI助手，法律RAG，通过倒入全部200+本法律手册、网页搜索内容结合LLM回答你的问题，并且给出对应的法规和网站，基于langchain，openai，chroma，duckduckgo-search, Gradio\n\n## Demo\n[https://law.vmaig.com/](https://law.vmaig.com/)\n\n**用户名**: username  \n**密码**:  password  \n\n## 原理\n\n基于langchain链式调用，先按条切分法律条文，导入向量数据Chroma。\n问答相关问题时，先通过相似度搜索向量数据，获取相关法律条文，然后通过DuckDuckGo互联网搜索相关网页，然后合并法律条文和网页内容，对问题进行回答。\n\n**初始化init**\n```mermaid\nflowchart LR\n    A[法律文件加载LawLoader] --\u003e B[MarkdownHeaderTextSplitter]\n    subgraph 文件切分LawSplitter\n    B[MarkdownHeaderTextSplitter] --\u003e C[RecursiveCharacterTextSplitter]\n    end\n    C --\u003e E[Embedding]\n    E --\u003e F[向量数据库Chroma]\n```\n\n**提问流程**\n```mermaid\nflowchart LR\n    A[提问] --\u003e B[问题校验];\n    B -- 否 --\u003e C1[请提问法律相关问题]\n    B -- 是 --\u003e C2[法律Chain];\n    subgraph Law Chain \n    C2 --\u003e D[LLM]\n    subgraph MultiQuery Retriever\n    D --\u003e E1[相似问题 01]\n    D --\u003e E2[相似问题 02]\n    D --\u003e E3[相似问题 03]\n    E1 --\u003e F[向量数据库Chroma]\n    E2 --\u003e F\n    E3 --\u003e F\n    F --\u003e H[法律docs]\n    end\n    C2 --\u003e G[DuckDuckGo互联网搜索]\n    subgraph Web Retriever\n    G --\u003e I[网页docs]\n    end\n    H --\u003e K[合并combine]\n    I --\u003e K\n    J[提问Prompt] --\u003e K\n    K --\u003e L[LLM]\n    L --\u003e M[callback流输出]\n    end\n```\n\n\n## 初始化运行环境\n\n```\n# 创建.env 文件\ncp .env.example .env\n\n# 修改.env 中的内容\nvim .env\n\n# 安装venv环境\npython -m venv ~/.venv/law\n. ~/.venv/law\npip install -r requirements.txt\n```\n\n## 初始化向量数据库\n\n```\n# 加载和切分法律手册，初始化向量数据库\npython manager.py --init\n```\n\n## 运行web ui\n\n```\npython manager.py --web\n```\n\n默认用户名/密码: username / password\n\n\u003ca href=\"https://sm.ms/image/DbP3TiHZConUFe7\" target=\"_blank\"\u003e\u003cimg src=\"https://s2.loli.net/2023/10/20/DbP3TiHZConUFe7.png\" \u003e\u003c/a\u003e\n\n## 运行对话\n\n```\npython manager.py --shell\n```\n\n\u003ca href=\"https://sm.ms/image/7E4zMpbafCPvNxX\" target=\"_blank\"\u003e\u003cimg src=\"https://s2.loli.net/2023/10/19/7E4zMpbafCPvNxX.png\"\u003e\u003c/a\u003e\n\n## 配置修改\n\n如果你想修改回答中的法律条数和网页条数，可以修改config.py\n- 法律条数: LAW_VS_SEARCH_K\n- 网页条数: WEB_VS_SEARCH_K\n- web ui地址: WEB_HOST\n- web ui端口: WEB_PORT\n- web ui登录用户: WEB_USERNAME\n- web ui登录密码: WEB_PASSWORD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillvsme%2Flaw_ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbillvsme%2Flaw_ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillvsme%2Flaw_ai/lists"}