ollama.ts 733 B

1234567891011121314151617181920212223242526272829303132
  1. import { chromium } from 'playwright'
  2. import { ollama } from 'ollama-ai-provider'
  3. import { z } from 'zod'
  4. import LLMScraper from './../src'
  5. // Launch a browser instance
  6. const browser = await chromium.launch()
  7. // Initialize LLM provider
  8. const llm = ollama('gemma3:1b')
  9. // Initialize a new LLMScraper with local model
  10. const scraper = new LLMScraper(llm)
  11. // Open the page
  12. const page = await browser.newPage()
  13. await page.goto('https://example.com')
  14. // Define schema to extract contents into
  15. const schema = z.object({
  16. h1: z.string().describe('The main heading of the page'),
  17. })
  18. // Run the scraper
  19. const { data } = await scraper.run(page, schema, {
  20. format: 'html',
  21. })
  22. console.log(data)
  23. await page.close()
  24. await browser.close()