Skip to content

Commit

Permalink
intermediate
Browse files Browse the repository at this point in the history
  • Loading branch information
ARYPROGRAMMER committed Oct 26, 2024
1 parent 7ca2e1f commit 331b171
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 364 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
### ⭐ About
A tool which helps non-professional lawyers to understand and improve their legal documents


$~$

<details>
Expand All @@ -17,7 +16,6 @@ $~$
![image](screenshots/img2.png)
![image](screenshots/img3.png)


</details>

$~$
Expand Down
63 changes: 16 additions & 47 deletions app/api/analyzer/route.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
// import { model } from "@/lib/groq";
// import { DocAnalyzerSchema } from "@/lib/doc-analyzer.types";
// import { generateObject } from "ai";
// import { NextRequest, NextResponse } from "next/server";

// export async function POST(req: NextRequest) {
// try {
// const body = await req.json();
// const prompt = `You are an Legal Consulting Advisor. Analyze the document given and help users understand and improve their legal documents. The Document is title is ${body.title} and other requirements are as follows:
// - The Severities, Risks and the Description of the Document.
// - A complete breakdown of all changes in the document to make it more legally sound in markdown format.
// - Tips(atmost 5) to add in the document to make it more legally sound`;

// const result = await generateObject({
// model,
// schema: DocAnalyzerSchema,
// prompt,
// });

// return NextResponse.json(result.object);
// } catch (error) {
// console.error("Error analyzing document:", error);
// return NextResponse.json({ error: "Failed to analyze document." });
// }
// }

import { model } from "@/lib/groq";
import { DocAnalyzerSchema, DocPlan } from "@/lib/doc-analyzer.types";
import { generateObject } from "ai";
Expand All @@ -33,31 +7,26 @@ export async function POST(req: NextRequest) {
try {
const body = await req.json();

if (!body.title) {
if (!body.content) {
return NextResponse.json(
{ error: "Title is required" },
{ error: "Content is required" },
{ status: 400 }
);
}

const prompt = `As a Legal Consulting Advisor, analyze the following document titled "${body.title}". Provide:
1. A comprehensive description that outlines:
- Key legal risks and their severity levels
- Potential compliance issues
- Areas requiring immediate attention
2. A detailed markdown-formatted breakdown of required changes, including:
- Section-by-section analysis
- Specific recommendations for improvement
- Legal implications of each change
const prompt = `
As a Legal Consulting Advisor, first understand the following document:
Document Content: ${body.content}
3. A markdown-formatted list of 5 essential tips to enhance the document's legal soundness, focusing on:
- Risk mitigation
- Compliance improvement
- Legal protection enhancement
now return your own analyzed reponse in json only format, for example:
Format the response maintaining clear structure and using markdown for better readability.`;
{
"title": "Legal Analysis of Document or any other thing.. as your wish",
"content": "A detailed legal analysis of the document.. as your wish.",
"tips": "1. Tip 1\n2. Tip 2\n3. Tip 3\n4. Tip 4\n5. Tip 5... upto 20 OR 30 tips in new line in more than 500 words",
"review": "A very long very long comprehensive review of the document... as per your wish"
}`;

// Generate the analysis
const result = await generateObject({
Expand All @@ -69,10 +38,10 @@ Format the response maintaining clear structure and using markdown for better re
// Create a complete DocPlan object
const docPlan: DocPlan = {
id: Date.now(), // Generate a unique ID
title: body.title,
description: result.object.description,
studyPlan: result.object.studyPlan,
title: result.object.title,
content: result.object.content,
tips: result.object.tips,
review: result.object.review,
starred: false
};

Expand Down
18 changes: 9 additions & 9 deletions components/add-doc-analyze.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
export default function AddStudyPlan({
onAdd,
}: {
onAdd: (title: string) => void;
onAdd: (content: string) => void;
}) {
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false);
const [newPlanTitle, setNewPlanTitle] = useState<string>("");
const [newPlanContent, setNewPlanContent] = useState<string>("");
const [isError, setIsError] = useState<boolean>(false);

const generateNewPlan = () => {
if (newPlanTitle.trim().length < 10) {
if (newPlanContent.trim().length < 10) {
setIsError(true);
return;
}
setIsError(false);
onAdd(newPlanTitle);
setNewPlanTitle("");
onAdd(newPlanContent);
setNewPlanContent("");
setIsDialogOpen(false);
};

const handleClose = () => {
setNewPlanTitle("");
setNewPlanContent("");
setIsError(false);
setIsDialogOpen(false);
};
Expand Down Expand Up @@ -86,9 +86,9 @@ export default function AddStudyPlan({
<Textarea
id="documentContent"
placeholder="Paste or type your legal document content here..."
value={newPlanTitle}
value={newPlanContent}
onChange={(e) => {
setNewPlanTitle(e.target.value);
setNewPlanContent(e.target.value);
setIsError(false);
}}
className="min-h-[300px] resize-y leading-relaxed"
Expand Down Expand Up @@ -119,7 +119,7 @@ export default function AddStudyPlan({
<Button
variant="default"
onClick={generateNewPlan}
disabled={newPlanTitle.trim().length === 0}
disabled={newPlanContent.trim().length === 0}
className="px-6"
>
Start Review
Expand Down
Loading

0 comments on commit 331b171

Please sign in to comment.