Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ yarn install

```env
GOOGLE_GENERATIVE_AI_API_KEY=your_api_key_here
FIRECRAWL_API_KEY=
```

4. Run the development server:
Expand Down
36 changes: 29 additions & 7 deletions app/api/generate-quiz/route.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
import { pdfExtractSchema } from "@/lib/schemas";
import { google } from "@ai-sdk/google";
import { streamObject } from "ai";
import FirecrawlApp from '@mendable/firecrawl-js';

export const maxDuration = 60;

export async function POST(req: Request) {
const { files } = await req.json();
const firstFile = files[0].data;
const { files, url } = await req.json();

let content = '';

if (url) {
const app = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY! });

const scrapeResponse = await app.scrapeUrl(url, {
formats: ['markdown'],
});

if (!scrapeResponse.success) {
throw new Error(`Failed to scrape: ${scrapeResponse.error}`);
}

content = scrapeResponse.markdown ?? '';
console.log(content);
} else if (files && files.length > 0) {
content = files[0]?.data ?? '';
} else {
throw new Error('No content provided');
}

const result = await streamObject({
model: google("gemini-1.5-pro-latest"),
messages: [
{
role: "system",
content:
"You are a document analyzer. Extract the most important points from the provided PDF document. Focus on key information, main ideas, and significant details.",
"You are a document analyzer. Extract the most important points from the provided document. Focus on key information, main ideas, and significant details.",
},
{
role: "user",
content: [
{
type: "text",
text: "Please read this PDF and extract the key points. Include relevant context where helpful.",
text: url
? "Please analyze this webpage content and extract the key points. Include relevant context where helpful."
: "Please read this PDF and extract the key points. Include relevant context where helpful.",
},
{
type: "file",
data: firstFile,
mimeType: "application/pdf",
type: "text",
text: content,
},
],
},
Expand Down
9 changes: 2 additions & 7 deletions components/MindMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,9 @@ export default function MindMap({ data, onNodeClick }: MindMapProps) {
<FileUp className="h-12 w-12 text-zinc-300 mx-auto mb-6" />
<h3 className="text-xl font-medium">No Mind Map Yet</h3>
<p className="text-sm text-zinc-400 pb-4">
Upload a PDF to generate an interactive mind map of its key concepts.
Upload a PDF or Enter a URL to generate an interactive mind map of its key concepts.
</p>
<Button
onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
className="font-mono bg-zinc-100 text-zinc-800 shadow-none hover:bg-zinc-200 duration-200"
>
Upload File
</Button>

</div>
</div>
)
Expand Down
Loading