Skip to content

Commit dc796c8

Browse files
committed
fix: upd llamaindex example
1 parent b974fde commit dc796c8

File tree

1 file changed

+23
-47
lines changed

1 file changed

+23
-47
lines changed

integrations/llamaindex.mdx

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ This tool integrates ScrapeGraph with LlamaIndex, providing intelligent web scra
2020
Install the package using pip:
2121

2222
```bash
23-
pip install llama-index-tools-scrapegraph
23+
pip install llama-index-tools-scrapegraphai
2424
```
2525

2626
## Usage
2727

2828
First, import and initialize the ScrapegraphToolSpec:
2929

3030
```python
31-
from llama_index.tools.scrapegraph import ScrapegraphToolSpec
31+
from llama_index.tools.scrapegraph.base import ScrapegraphToolSpec
3232

3333
scrapegraph_tool = ScrapegraphToolSpec()
3434
```
@@ -40,20 +40,27 @@ scrapegraph_tool = ScrapegraphToolSpec()
4040
Extract structured data using a schema:
4141

4242
```python
43-
from pydantic import BaseModel
44-
45-
class ProductSchema(BaseModel):
46-
name: str
47-
price: float
48-
description: str
49-
50-
schema = [ProductSchema]
51-
result = scrapegraph_tool.scrapegraph_smartscraper(
52-
prompt="Extract product information",
53-
url="https://example.com/product",
54-
api_key="your-api-key",
55-
schema=schema,
56-
)
43+
from pydantic import BaseModel, Field
44+
45+
class FounderSchema(BaseModel):
46+
name: str = Field(description="Name of the founder")
47+
role: str = Field(description="Role of the founder")
48+
social_media: str = Field(description="Social media URL of the founder")
49+
50+
class ListFoundersSchema(BaseModel):
51+
founders: list[FounderSchema] = Field(description="List of founders")
52+
53+
response = scrapegraph_tool.scrapegraph_smartscraper(
54+
prompt="Extract product information",
55+
url="https://scrapegraphai.com/",
56+
api_key="sgai-***",
57+
schema=ListFoundersSchema,
58+
)
59+
60+
result = response["result"]
61+
62+
for founder in result["founders"]:
63+
print(founder)
5764
```
5865

5966
### Smart Scraping (Async)
@@ -107,37 +114,6 @@ credits = scrapegraph_tool.scrapegraph_get_credits(api_key="your-api-key")
107114
</Card>
108115
</CardGroup>
109116

110-
## Example: Product Information Extraction
111-
112-
```python
113-
from llama_index.tools.scrapegraph import ScrapegraphToolSpec
114-
from pydantic import BaseModel, Field
115-
from typing import List
116-
117-
# Define your schema
118-
class ProductInfo(BaseModel):
119-
name: str = Field(description="Product name")
120-
price: float = Field(description="Product price")
121-
features: List[str] = Field(description="Product features")
122-
description: str = Field(description="Product description")
123-
124-
# Initialize the tool
125-
tool = ScrapegraphToolSpec()
126-
127-
# Extract product information
128-
result = tool.scrapegraph_smartscraper(
129-
prompt="Extract detailed product information",
130-
url="https://example.com/product",
131-
api_key="your-api-key",
132-
schema=[ProductInfo]
133-
)
134-
135-
# Process the results
136-
print(f"Product Name: {result.name}")
137-
print(f"Price: ${result.price}")
138-
print("Features:", *result.features, sep="\n- ")
139-
```
140-
141117
## Support
142118

143119
Need help with the integration?

0 commit comments

Comments
 (0)