Skip to content

Instantly share code, notes, and snippets.

@davepoon
Created March 20, 2025 11:33
Show Gist options
  • Save davepoon/fc92a6f179ce79d7a3a1e506d0837353 to your computer and use it in GitHub Desktop.
Save davepoon/fc92a6f179ce79d7a3a1e506d0837353 to your computer and use it in GitHub Desktop.
Crawl4AI example
from crawl4ai import WebCrawler
from crawl4ai.extraction_strategy import LLMExtractionStrategy
from pydantic import BaseModel, Field
class OpenAIModelFee(BaseModel):
model_name: str
input_fee: str
output_fee: str
url = 'https://openai.com/api/pricing/'
crawler = WebCrawler()
crawler.warmup()
result = crawler.run(
url=url,
extraction_strategy=LLMExtractionStrategy(
provider="openai/gpt-4o",
api_token='your_api_key',
schema=OpenAIModelFee.schema(),
instruction="Extract all model names and their fees."
)
)
print(result.extracted_content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment