added new demo

This commit is contained in:
ShubhamSaboo 2024-12-10 17:54:18 -06:00
parent 091c0a505f
commit 5c7b92b65c
2 changed files with 42 additions and 25 deletions

View file

@ -1,10 +1,6 @@
# AI Legal Agent Team # 👨‍⚖️ AI Legal Agent Team
An intelligent legal document analysis Agent Team powered by GPT-4 and Qdrant vector database. The system uses a team of specialized AI agents to analyze legal documents, providing comprehensive insights, key points, and recommendations. We used phi-agent to create the agent team. A Streamlit application that simulates a full-service legal team using multiple AI agents to analyze legal documents and provide comprehensive legal insights. Each agent represents a different legal specialist role, from research and contract analysis to strategic planning, working together to provide thorough legal analysis and recommendations.
## Demo:
https://github.com/user-attachments/assets/e89f2fc9-6a66-4eac-98dd-b4cb04e50419
## Features ## Features
@ -54,7 +50,7 @@ https://github.com/user-attachments/assets/e89f2fc9-6a66-4eac-98dd-b4cb04e50419
## Notes ## Notes
- Supports PDF documents only - Supports PDF documents only
- Uses GPT-4 for analysis - Uses GPT-4o for analysis
- Uses text-embedding-3-small for embeddings - Uses text-embedding-3-small for embeddings
- Requires stable internet connection - Requires stable internet connection
- API usage costs apply - API usage costs apply

View file

@ -7,6 +7,7 @@ from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder from phi.embedder.openai import OpenAIEmbedder
import tempfile import tempfile
import os import os
#initializing the session state variables #initializing the session state variables
def init_session_state(): def init_session_state():
"""Initialize session state variables""" """Initialize session state variables"""
@ -30,7 +31,7 @@ def init_qdrant():
if not st.session_state.qdrant_url: if not st.session_state.qdrant_url:
raise ValueError("Qdrant URL not provided") raise ValueError("Qdrant URL not provided")
return Qdrant( #from the phidata Qdrant docs return Qdrant(
collection="legal_knowledge", collection="legal_knowledge",
url=st.session_state.qdrant_url, url=st.session_state.qdrant_url,
api_key=st.session_state.qdrant_api_key, api_key=st.session_state.qdrant_api_key,
@ -76,7 +77,7 @@ def main():
st.set_page_config(page_title="Legal Document Analyzer", layout="wide") st.set_page_config(page_title="Legal Document Analyzer", layout="wide")
init_session_state() init_session_state()
st.title("AI Legal Agent Team") st.title("AI Legal Agent Team 👨‍⚖️")
with st.sidebar: with st.sidebar:
st.header("🔑 API Configuration") st.header("🔑 API Configuration")
@ -131,7 +132,7 @@ def main():
legal_researcher = Agent( legal_researcher = Agent(
name="Legal Researcher", name="Legal Researcher",
role="Legal research specialist", role="Legal research specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
tools=[DuckDuckGo()], tools=[DuckDuckGo()],
knowledge=st.session_state.knowledge_base, knowledge=st.session_state.knowledge_base,
search_knowledge=True, search_knowledge=True,
@ -148,7 +149,7 @@ def main():
contract_analyst = Agent( contract_analyst = Agent(
name="Contract Analyst", name="Contract Analyst",
role="Contract analysis specialist", role="Contract analysis specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
knowledge=knowledge_base, knowledge=knowledge_base,
search_knowledge=True, search_knowledge=True,
instructions=[ instructions=[
@ -162,7 +163,7 @@ def main():
legal_strategist = Agent( legal_strategist = Agent(
name="Legal Strategist", name="Legal Strategist",
role="Legal strategy specialist", role="Legal strategy specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
knowledge=knowledge_base, knowledge=knowledge_base,
search_knowledge=True, search_knowledge=True,
instructions=[ instructions=[
@ -177,7 +178,7 @@ def main():
st.session_state.legal_team = Agent( st.session_state.legal_team = Agent(
name="Legal Team Lead", name="Legal Team Lead",
role="Legal team coordinator", role="Legal team coordinator",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
team=[legal_researcher, contract_analyst, legal_strategist], team=[legal_researcher, contract_analyst, legal_strategist],
knowledge=st.session_state.knowledge_base, knowledge=st.session_state.knowledge_base,
search_knowledge=True, search_knowledge=True,
@ -218,7 +219,17 @@ def main():
elif not uploaded_file: elif not uploaded_file:
st.info("👈 Please upload a legal document to begin analysis") st.info("👈 Please upload a legal document to begin analysis")
elif st.session_state.legal_team: elif st.session_state.legal_team:
st.header("Document Analysis") # Create a dictionary for analysis type icons
analysis_icons = {
"Contract Review": "📑",
"Legal Research": "🔍",
"Risk Assessment": "⚠️",
"Compliance Check": "✅",
"Custom Query": "💭"
}
# Dynamic header with icon
st.header(f"{analysis_icons[analysis_type]} {analysis_type} Analysis")
analysis_configs = { analysis_configs = {
"Contract Review": { "Contract Review": {
@ -249,15 +260,22 @@ def main():
} }
st.info(f"📋 {analysis_configs[analysis_type]['description']}") st.info(f"📋 {analysis_configs[analysis_type]['description']}")
st.write(f"🤖 Active Agents: {', '.join(analysis_configs[analysis_type]['agents'])}") #dictionary!! st.write(f"🤖 Active Legal AI Agents: {', '.join(analysis_configs[analysis_type]['agents'])}") #dictionary!!
# Replace the existing user_query section with this:
if analysis_type == "Custom Query":
user_query = st.text_area( user_query = st.text_area(
"Enter your specific query:", "Enter your specific query:",
help="Add any specific questions or points you want to analyze" help="Add any specific questions or points you want to analyze"
) )
else:
user_query = None # Set to None for non-custom queries
if st.button("Analyze"): if st.button("Analyze"):
if user_query or analysis_type != "Custom Query": if analysis_type == "Custom Query" and not user_query:
st.warning("Please enter a query")
else:
with st.spinner("Analyzing document..."): with st.spinner("Analyzing document..."):
try: try:
# Ensure OpenAI API key is set # Ensure OpenAI API key is set
@ -269,14 +287,19 @@ def main():
Using the uploaded document as reference: Using the uploaded document as reference:
Primary Analysis Task: {analysis_configs[analysis_type]['query']} Primary Analysis Task: {analysis_configs[analysis_type]['query']}
Additional User Query: {user_query if user_query else 'None'}
Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])} Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])}
Please search the knowledge base and provide specific references from the document. Please search the knowledge base and provide specific references from the document.
""" """
else: else:
combined_query = user_query combined_query = f"""
Using the uploaded document as reference:
{user_query}
Please search the knowledge base and provide specific references from the document.
Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])}
"""
response = st.session_state.legal_team.run(combined_query) response = st.session_state.legal_team.run(combined_query)
@ -326,8 +349,6 @@ def main():
except Exception as e: except Exception as e:
st.error(f"Error during analysis: {str(e)}") st.error(f"Error during analysis: {str(e)}")
else:
st.warning("Please enter a query or select an analysis type")
else: else:
st.info("Please upload a legal document to begin analysis") st.info("Please upload a legal document to begin analysis")