Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v1] Release #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
92 changes: 50 additions & 42 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
app, err := firecrawl.NewFirecrawlApp("fc-YOUR_API_KEY", "https://api.firecrawl.dev")
app, err := firecrawl.NewFirecrawlApp("fc-YOUR_API_KEY", "https://api.firecrawl.dev", "v1")
if err != nil {
log.Fatalf("Failed to create FirecrawlApp: %v", err)
}
Expand All @@ -25,9 +25,7 @@ func main() {
// Crawl a website
idempotencyKey := uuid.New().String() // optional idempotency key
crawlParams := map[string]any{
"crawlerOptions": map[string]any{
"excludes": []string{"blog/*"},
},
"excludePaths": []string{"blog/*"},
}
crawlResult, err := app.CrawlURL("mendable.ai", crawlParams, true, 2, idempotencyKey)
if err != nil {
Expand All @@ -40,48 +38,58 @@ func main() {
fmt.Println(string(jsonCrawlResult))

// LLM Extraction using JSON schema
jsonSchema := map[string]any{
"type": "object",
"properties": map[string]any{
"top": map[string]any{
"type": "array",
"items": map[string]any{
"type": "object",
"properties": map[string]any{
"title": map[string]string{"type": "string"},
"points": map[string]string{"type": "number"},
"by": map[string]string{"type": "string"},
"commentsURL": map[string]string{"type": "string"},
},
"required": []string{"title", "points", "by", "commentsURL"},
},
"minItems": 5,
"maxItems": 5,
"description": "Top 5 stories on Hacker News",
},
},
"required": []string{"top"},
}
// jsonSchema := map[string]any{
// "type": "object",
// "properties": map[string]any{
// "top": map[string]any{
// "type": "array",
// "items": map[string]any{
// "type": "object",
// "properties": map[string]any{
// "title": map[string]string{"type": "string"},
// "points": map[string]string{"type": "number"},
// "by": map[string]string{"type": "string"},
// "commentsURL": map[string]string{"type": "string"},
// },
// "required": []string{"title", "points", "by", "commentsURL"},
// },
// "minItems": 5,
// "maxItems": 5,
// "description": "Top 5 stories on Hacker News",
// },
// },
// "required": []string{"top"},
// }

llmExtractionParams := map[string]any{
"extractorOptions": firecrawl.ExtractorOptions{
ExtractionSchema: jsonSchema,
Mode: "llm-extraction",
},
"pageOptions": map[string]any{
"onlyMainContent": true,
},
}
// llmExtractionParams := map[string]any{
// "extractorOptions": firecrawl.ExtractorOptions{
// ExtractionSchema: jsonSchema,
// Mode: "llm-extraction",
// },
// "pageOptions": map[string]any{
// "onlyMainContent": true,
// },
// }

llmExtractionResult, err := app.ScrapeURL("https://news.ycombinator.com", llmExtractionParams)
if err != nil {
log.Fatalf("Failed to perform LLM extraction: %v", err)
}
// llmExtractionResult, err := app.ScrapeURL("https://news.ycombinator.com", llmExtractionParams)
// if err != nil {
// log.Fatalf("Failed to perform LLM extraction: %v", err)
// }

// Pretty print the LLM extraction result
jsonResult, err := json.MarshalIndent(llmExtractionResult.LLMExtraction, "", " ")
// jsonResult, err := json.MarshalIndent(llmExtractionResult.LLMExtraction, "", " ")
// if err != nil {
// log.Fatalf("Failed to marshal LLM extraction result: %v", err)
// }
// fmt.Println(string(jsonResult))

mapResult, err := app.MapURL("https://roastmywebsite.ai", nil)
if err != nil {
log.Fatalf("Failed to map URL: %v", err)
}
jsonMapResult, err := json.MarshalIndent(mapResult, "", " ")
if err != nil {
log.Fatalf("Failed to marshal LLM extraction result: %v", err)
log.Fatalf("Failed to marshal map result: %v", err)
}
fmt.Println(string(jsonResult))
fmt.Println(string(jsonMapResult))
}
87 changes: 87 additions & 0 deletions exampleV0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"encoding/json"
"fmt"
"log"

"github.com/google/uuid"
"github.com/mendableai/firecrawl-go"
)

func main() {
app, err := firecrawl.NewFirecrawlApp("fc-YOUR_API_KEY", "https://api.firecrawl.dev", "v0")
if err != nil {
log.Fatalf("Failed to create FirecrawlApp: %v", err)
}

// Scrape a website
scrapeResult, err := app.ScrapeURL("firecrawl.dev", nil)
if err != nil {
log.Fatalf("Failed to scrape URL: %v", err)
}
fmt.Println(scrapeResult.Markdown)

// Crawl a website
idempotencyKey := uuid.New().String() // optional idempotency key
crawlParams := map[string]any{
"crawlerOptions": map[string]any{
"excludes": []string{"blog/*"},
},
}
crawlResult, err := app.CrawlURL("mendable.ai", crawlParams, true, 2, idempotencyKey)
if err != nil {
log.Fatalf("Failed to crawl URL: %v", err)
}
jsonCrawlResult, err := json.MarshalIndent(crawlResult, "", " ")
if err != nil {
log.Fatalf("Failed to marshal crawl result: %v", err)
}
fmt.Println(string(jsonCrawlResult))

// LLM Extraction using JSON schema
jsonSchema := map[string]any{
"type": "object",
"properties": map[string]any{
"top": map[string]any{
"type": "array",
"items": map[string]any{
"type": "object",
"properties": map[string]any{
"title": map[string]string{"type": "string"},
"points": map[string]string{"type": "number"},
"by": map[string]string{"type": "string"},
"commentsURL": map[string]string{"type": "string"},
},
"required": []string{"title", "points", "by", "commentsURL"},
},
"minItems": 5,
"maxItems": 5,
"description": "Top 5 stories on Hacker News",
},
},
"required": []string{"top"},
}

llmExtractionParams := map[string]any{
"extractorOptions": firecrawl.ExtractorOptions{
ExtractionSchema: jsonSchema,
Mode: "llm-extraction",
},
"pageOptions": map[string]any{
"onlyMainContent": true,
},
}

llmExtractionResult, err := app.ScrapeURL("https://news.ycombinator.com", llmExtractionParams)
if err != nil {
log.Fatalf("Failed to perform LLM extraction: %v", err)
}

// Pretty print the LLM extraction result
jsonResult, err := json.MarshalIndent(llmExtractionResult.LLMExtraction, "", " ")
if err != nil {
log.Fatalf("Failed to marshal LLM extraction result: %v", err)
}
fmt.Println(string(jsonResult))
}