”随着人工智能技术的发展,如何让 AI 落地服务于特定的专业领域成为一个重要课题。“
今天,我们来看一个有趣的开源项目 LawGlance。这是一个印度团队开发的法律 AI 助手。
为什么想要分享呢?
首先,这是一个基于 Crew.AI 的多智能体工作流案例,而且结合智能体框架LangChain 和 向量数据库Chroma ,又有多文档知识库配置,使用聊天的模式,实现法律问题的精准检索和回答。
接下来,我们逐一拆解。
一、项目核心技术架构
这个项目主要使用了四个核心技术:
- Crew.AI:负责管理多个 AI "专家"的协作
- LangChain:处理 AI 应用的整体流程
- ChromaDB:存储和检索法律文档
- OpenAI API:提供语言理解能力
如下,是整个项目类的设计:
二、Crew.AI "专家团队"的设计
LawGlance 的特别之处在于采用了多个 AI "专家"协同工作的方式,就像一个虚拟的法律顾问团队。项目中,设计了四位 AI “专家”,每位都有自己的专长:
而且这些"专家"的工作流程非常清晰:
首先由检索专家找到相关法律文档,然后法律顾问根据这些文档回答问题,评估专家验证答案的准确性,最后由编辑专家优化表达。这种分工协作的方式大大提高了回答的质量。
检索专家(Retriever Agent):负责快速找到相关的法律文档。使用到了向量数据库工具。chroma_tool。
retriever_agent = Agent(
role='Retriever Agent',
goal='Retrieve relevant content about "{query}" from the vector store.',
backstory=("You are skilled at searching the vector store for user queries and fetching relevant documents."
"Your ability to find and retrieve relevant content ensures accurate reports."),
verbose=True,
memory = True,
tools=[chroma_tool],
llm=llm
)
法律顾问(Legal Assistant Agent):负责解答法律问题。特别要注意的是,如果在知识库里没有对应的法律条款,法律顾问会启动联网检索。使用到了工具 Tools 为 web_search_tool。
legal_assistant_agent = Agent(
role="Legal Assistant Agent",
goal="Generate responses for the {query} based on retrieved documents only",
backstory=
"You are a lawyer assistant LawGlance and you answer for legal related queries"
"You create informative responses using the data provided by the retriever task only"
"If an informative response can't be provided from the documents you should use websearch tool and respond based on it.",
verbose=True,
memory = True,
allow_delegation=False,
tools = [web_search_tool],
llm=llm
)
评估专家(Evaluation Agent):确保答案的准确性。
evaluation_agent = Agent(
role=“Evaluation Expert Agent”,
goal=“Verify and evaluate the accuracy and authenticity of responses created by retriever and generator agents.”,
backstory=
"You are an evaluation expert in the LawGlance ecosystem. "
"Your primary task is to validate the responses generated by the retriever and generator agents. "
“You check for accuracy, relevance, and authenticity of the content before it reaches the customer.”,
verbose=True,
memory=False,
allow_delegation=False,
tools = [web_search_tool],
llm=llm
)
编辑专家(Editor Agent):让回答更容易理解。
editor_agent = Agent(
role="Editor Agent",
goal="Create a concise and edited output for '{query}' based on the generated response.",
backstory=(
"You are an Editor tasked with refining the generated responses."
"You ensure that the final output is concise,to the point, relevant, and properly formatted without any hallucinations."
"For responses generated using web search, you must include the source of the information."
),
verbose=True,
memory=False,
llm=llm
)
三、技术亮点分析
项目有几个特别值得关注的技术亮点:
精准检索技术
项目使用了向量数据库技术Chroma,可以理解问题的含义而不是简单的关键词匹配。比如当你问"我可以在什么情况下解除劳动合同",系统会理解这是一个关于劳动法的问题,并找到相关法律条款。
智能协作机制
各个 AI "专家"之间的配合就像真实的团队协作。每个专家都会把自己的工作结果传递给下一位,同时共享必要的上下文信息,确保整个过程的连贯性。
对话记忆功能
系统能够记住对话的上下文,这意味着你可以进行连续的对话。比如在问完"什么是知识产权"后,直接问"如何保护它",系统也能理解你指的是知识产权。
四、实际应用案例
让我们看一个具体的使用例子:
用户: “What is relevant articles dealing with freedom of speech”? 系统:[检索相关法律文档] → [生成初步回答] → [验证准确性] → [优化表达] 最终回答:Articles related to freedom of speech in the Indian Constitution are encapsulated mainly in Article 19…。
1-Agent: Retriever Agent 检索专家
从向量数据库中检索出 5 篇与言论自由相关的文章。并且提供了对应的原文 Content。
1. Document Source: [Indian Constitution](https://cdnbbsr.s3waas.gov.in/s380537a945c7aaa788ccfcdf1b99b5d8f/uploads/2024/07/20240716890312078.pdf)
- Content: "Prohibited and any contravention of this provision shall be an offence punishable in accordance with law. (2) Nothing in this article shall prevent the State from imposing compulsory service for public purposes, and in imposing such service the State shall not make any discrimination on grounds only of religion, race, caste, or class or any of them. Article 24. Prohibition of employment of children in factories, etc.—No child below the age of fourteen years shall be employed to work in any factory or mine or engaged in any other hazardous employment. Right to Freedom of Religion Article 25. Freedom of conscience and free profession, practice and propagation of religion.—(1) Subject to public order, morality and health and to the other provisions of this Part, all persons are equally entitled to freedom of conscience and the right freely to profess, practice, and propagate religion. (2) Nothing in this article shall affect the operation of any existing law or…"
2. Document Source: [Indian Constitution](https://cdnbbsr.s3waas.gov.in/s380537a945c7aaa788ccfcdf1b99b5d8f/uploads/2024/07/20240716890312078.pdf)
- Content: "No citizen of India shall accept any title from any foreign State. (3) No person who is not a citizen of India shall, while he holds any office of profit or trust under the State, accept without the consent of the President any title from any foreign State. (4) No person holding any office of profit or trust under the State shall, without the consent of the President, accept any present, emolument, or office of any kind from or under any foreign State. Right to Freedom Article 19. Protection of certain rights regarding freedom of speech, etc.—(1) All citizens shall have the right—(a) to freedom of speech and expression; (b) to assemble peaceably and without arms; (c) to form associations or unions or co-operative societies; (d) to move freely throughout the territory of India; (e) to reside and settle in any part of the territory of India…"
3. Document Source: [Indian Constitution](https://cdnbbsr.s3waas.gov.in/s380537a945c7aaa788ccfcdf1b99b5d8f/uploads/2024/07/20240716890312078.pdf)
- Content: "No person shall be deprived of his life or personal liberty except according to procedure established by law. Article 21A. Right to education.—The State shall provide free and compulsory education to all children of the age of six to fourteen years in such manner as the State may, by law, determine. Article 22. Protection against arrest and detention in certain cases.—(1) No person who is arrested shall be detained in custody without being informed, as soon as may be, of the grounds for such arrest nor shall he be denied the right to consult, and to be defended by, a legal practitioner of his choice…"
4. Document Source: [Indian Constitution](https://cdnbbsr.s3waas.gov.in/s380537a945c7aaa788ccfcdf1b99b5d8f/uploads/2024/07/20240716890312078.pdf)
- Content: "No person shall be compelled to pay any taxes, the proceeds of which are specifically appropriated in payment of expenses for the promotion or maintenance of any particular religion or religious denomination. Article 28. Freedom as to attendance at religious instruction or religious worship in certain educational institutions.—(1) No religious instruction shall be provided in any educational institution wholly maintained out of State funds…"
5. Document Source: [Indian Constitution](https://cdnbbsr.s3waas.gov.in/s380537a945c7aaa788ccfcdf1b99b5d8f/uploads/2024/07/20240716890312078.pdf)
- Content: "The right to move the Supreme Court by appropriate proceedings for the enforcement of the rights conferred by this Part is guaranteed..."
These documents highlight various articles related to freedom of speech and its context within the Indian Constitution.
2-Agent: Legal Assistant Agent 法律顾问
根据检索专家提供的原文资料,识别出与印度的言论自由相关性最高的文章是Article 19,并且提供了对应的理由。
# Agent: Legal Assistant Agent## Final Answer:
Articles related to freedom of speech in the Indian Constitution are primarily encapsulated in Article 19. Specifically:
1. **Article 19(1)(a)**: This article guarantees all citizens the right to freedom of speech and expression. It serves as the foundational legal provision that upholds the principle of free speech in India.
2. **Article 19(2)**: While Article 19(1)(a) ensures freedom of speech, Article 19(2) stipulates that this freedom is not absolute and can be subject to "reasonable restrictions." These restrictions can be imposed in the interest of:
- Sovereignty and integrity of India
- Security of the State
- Friendly relations with foreign States
- Public order
- Decency or morality
- Contempt of court
- Defamation
- Incitement to an offence
The balance between freedom of speech and the need for regulation is a critical aspect of legal discourse in India, with various court rulings interpreting these articles in different contexts. For instance, the Supreme Court has affirmed the constitutionality of pre-censorship in films, indicating that some limitations on free expression can be legally upheld.
Thus, the right to free speech in India, as enshrined in Article 19, is a complex interplay of rights and restrictions, reflecting the challenges in ensuring both individual liberties and societal interests.
3-Agent: Evaluation Expert Agent评估专家
评估和肯定法律顾问提出的,Article 19 是关联性最高的文章。并且给了对应的评估理由。
# Agent: Evaluation Expert Agent## Final Answer:
Articles related to freedom of speech in the Indian Constitution are primarily encapsulated in Article 19. Specifically:
1. **Article 19(1)(a)**: This article guarantees all citizens the right to freedom of speech and expression. It serves as the foundational legal provision that upholds the principle of free speech in India.
2. **Article 19(2)**: While Article 19(1)(a) ensures freedom of speech, Article 19(2) stipulates that this freedom is not absolute and can be subject to "reasonable restrictions." These restrictions can be imposed in the interest of:
- Sovereignty and integrity of India
- Security of the State
- Friendly relations with foreign States
- Public order
- Decency or morality
- Contempt of court
- Defamation
- Incitement to an offence
The balance between freedom of speech and the need for regulation is a critical aspect of legal discourse in India, with various court rulings interpreting these articles in different contexts. For instance, the Supreme Court has affirmed the constitutionality of pre-censorship in films, indicating that some limitations on free expression can be legally upheld.
Thus, the right to free speech in India, as enshrined in Article 19, is a complex interplay of rights and restrictions, reflecting the challenges in ensuring both individual liberties and societal interests.
Accuracy: 100%
4-Agent: Editor Agent 编辑专家
负责将最终的答案编辑完善,形成用户阅读有好的结论。
# Agent: Editor Agent## Final Answer:
Articles related to freedom of speech in the Indian Constitution are encapsulated mainly in **Article 19**. **Article 19(1)(a)** guarantees the right to freedom of speech and expression, while **Article 19(2)** outlines reasonable restrictions on this freedom to protect interests such as public order and morality. This dynamic between rights and restrictions is frequently interpreted by the courts, highlighting the balance between individual liberties and societal interests.
最后,说一点感悟。大模型应用上的各种幻觉和专业度不足的问题,在行业里,基本都是通过 RAG 技术解决。但是,只用 RAG 也只能解决知识关联和参考的问题。没办法能够保证答案输出的精准度。
而,LawGlance 项目展示了如何将先进的 AI 技术应用到专业领域。通过多个 AI "专家"的协作,实现了准确、可靠的法律问答服务。这个开源项目不仅为法律服务提供了新的可能,也为其他专业领域的 AI 应用提供了有价值的参考。
github 项目地址:https://github.com/lawglance/lawglance
如何学习大模型
现在社会上大模型越来越普及了,已经有很多人都想往这里面扎,但是却找不到适合的方法去学习。
作为一名资深码农,初入大模型时也吃了很多亏,踩了无数坑。现在我想把我的经验和知识分享给你们,帮助你们学习AI大模型,能够解决你们学习中的困难。
下面这些都是我当初辛苦整理和花钱购买的资料,现在我已将重要的AI大模型资料包括市面上AI大模型各大白皮书、AGI大模型系统学习路线、AI大模型视频教程、实战学习,等录播视频免费分享出来
,需要的小伙伴可以扫取。
一、AGI大模型系统学习路线
很多人学习大模型的时候没有方向,东学一点西学一点,像只无头苍蝇乱撞,我下面分享的这个学习路线希望能够帮助到你们学习AI大模型。
二、AI大模型视频教程
三、AI大模型各大学习书籍!
四、AI大模型各大场景实战案例
五、AI大模型面试题库
👉学会后的收获:👈
• 基于大模型全栈工程实现(前端、后端、产品经理、设计、数据分析等),通过这门课可获得不同能力;
• 能够利用大模型解决相关实际项目需求: 大数据时代,越来越多的企业和机构需要处理海量数据,利用大模型技术可以更好地处理这些数据,提高数据分析和决策的准确性。因此,掌握大模型应用开发技能,可以让程序员更好地应对实际项目需求;
• 基于大模型和企业数据AI应用开发,实现大模型理论、掌握GPU算力、硬件、LangChain开发框架和项目实战技能, 学会Fine-tuning垂直训练大模型(数据准备、数据蒸馏、大模型部署)一站式掌握;
• 能够完成时下热门大模型垂直领域模型训练能力,提高程序员的编码能力: 大模型应用开发需要掌握机器学习算法、深度学习框架等技术,这些技术的掌握可以提高程序员的编码能力和分析能力,让程序员更加熟练地编写高质量的代码。
👉 福利来袭
CSDN大礼包:《2025最全AI大模型学习资源包》免费分享,安全可点 👈
五、结束语
学习AI大模型是当前科技发展的趋势,它不仅能够为我们提供更多的机会和挑战,还能够让我们更好地理解和应用人工智能技术。通过学习AI大模型,我们可以深入了解深度学习、神经网络等核心概念,并将其应用于自然语言处理、计算机视觉、语音识别等领域。同时,掌握AI大模型还能够为我们的职业发展增添竞争力,成为未来技术领域的领导者。
再者,学习AI大模型也能为我们自己创造更多的价值,提供更多的岗位以及副业创收,让自己的生活更上一层楼。
因此,学习AI大模型是一项有前景且值得投入的时间和精力的重要选择。