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

update examples #1032

Merged
merged 1 commit into from
Jan 24, 2025
Merged
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
32 changes: 11 additions & 21 deletions docs/functions/cast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ For complex transformations, consider creating a custom task. The `cast` functio

Convert natural language descriptions of numbers into their numeric representation:

<CodeGroup>
```python Code
```python
import marvin

# Convert text to a number
price = marvin.cast("three dollars and fifty cents", float)
print(price)
```

```python Result
```python
3.5
```
</CodeGroup>

## Parameters

Expand Down Expand Up @@ -63,42 +61,37 @@ asyncio.run(main())

Convert natural language descriptions of quantities into numeric values:

<CodeGroup>
```python Code
```python
import marvin

price = marvin.cast("three dollars and fifty cents", float)
print(price)
```

```python Result
```python
3.5
```
</CodeGroup>

### Boolean Conversion

Interpret natural language expressions as boolean values:

<CodeGroup>
```python Code
```python
import marvin

answer = marvin.cast("that sounds great!", bool)
print(answer)
```

```python Result
```python
True
```
</CodeGroup>

### Structured Data

Extract structured information from natural language descriptions:

<CodeGroup>
```python Code
```python
import marvin
from dataclasses import dataclass

Expand All @@ -115,17 +108,15 @@ address = marvin.cast(
print(f"{address.street}, {address.city}, {address.country}")
```

```python Result
```python
"123 Main St", "New York", "USA"
```
</CodeGroup>

### Custom Instructions

Use instructions to control how text is interpreted and formatted:

<CodeGroup>
```python Code
```python
import marvin

phone = marvin.cast(
Expand All @@ -136,7 +127,6 @@ phone = marvin.cast(
print(phone)
```

```python Result
```python
"555-0123"
```
</CodeGroup>
```
32 changes: 11 additions & 21 deletions docs/functions/classify.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ For complex classification needs, consider creating a custom task. The `classify

Classify text into predefined categories:

<CodeGroup>
```python Code
```python
import marvin

sentiment = marvin.classify(
Expand All @@ -27,10 +26,9 @@ sentiment = marvin.classify(
print(sentiment)
```

```python Result
```python
"positive"
```
</CodeGroup>

## Parameters

Expand Down Expand Up @@ -66,8 +64,7 @@ asyncio.run(main())

Use simple string labels to categorize content:

<CodeGroup>
```python Code
```python
import marvin

priority = marvin.classify(
Expand All @@ -77,17 +74,15 @@ priority = marvin.classify(
print(priority)
```

```python Result
```python
"critical"
```
</CodeGroup>

### Using Enums

Add type safety with Python enums:

<CodeGroup>
```python Code
```python
import marvin
from enum import Enum

Expand All @@ -105,18 +100,16 @@ print(priority)
print(priority.value)
```

```python Result
```python
Priority.LOW
"low"
```
</CodeGroup>

### Multi-label Classification

Identify multiple applicable categories:

<CodeGroup>
```python Code
```python
import marvin

genres = marvin.classify(
Expand All @@ -127,17 +120,15 @@ genres = marvin.classify(
print(genres)
```

```python Result
```python
["comedy", "romance", "sci-fi"]
```
</CodeGroup>

### Custom Instructions

Guide the classification with specific criteria:

<CodeGroup>
```python Code
```python
import marvin

sentiment = marvin.classify(
Expand All @@ -148,7 +139,6 @@ sentiment = marvin.classify(
print(sentiment)
```

```python Result
```python
"negative"
```
</CodeGroup>
```
34 changes: 12 additions & 22 deletions docs/functions/extract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ For complex extraction patterns, consider creating a custom task. The `extract`

Pull email addresses from text:

<CodeGroup>
```python Code
```python
import marvin

emails = marvin.extract(
Expand All @@ -28,10 +27,9 @@ emails = marvin.extract(
print(emails)
```

```python Result
```python
["[email protected]", "[email protected]"]
```
</CodeGroup>

## Parameters

Expand Down Expand Up @@ -66,8 +64,7 @@ asyncio.run(main())

Find all numbers in text:

<CodeGroup>
```python Code
```python
import marvin

temperatures = marvin.extract(
Expand All @@ -77,17 +74,15 @@ temperatures = marvin.extract(
print(temperatures)
```

```python Result
```python
[75.0, 62.0]
```
</CodeGroup>

### Named Entities

Extract specific types of information:

<CodeGroup>
```python Code
```python
import marvin

cities = marvin.extract(
Expand All @@ -98,17 +93,15 @@ cities = marvin.extract(
print(cities)
```

```python Result
```python
["New York", "London"]
```
</CodeGroup>

### Dates and Times

Find temporal information in text:

<CodeGroup>
```python Code
```python
import marvin
from datetime import datetime

Expand All @@ -120,17 +113,15 @@ dates = marvin.extract(
print(dates)
```

```python Result
```python
[datetime(2024, 3, 15, 14, 30)]
```
</CodeGroup>

### Structured Data

Pull complex information into structured types:

<CodeGroup>
```python Code
```python
import marvin
from dataclasses import dataclass

Expand All @@ -151,8 +142,7 @@ print(f"{contacts[0].name}: {contacts[0].phone}")
print(f"{contacts[1].name}: {contacts[1].phone}")
```

```python Result
"John Smith: 555-0123"
"Mary Johnson: None"
```python
John Smith: 555-0123
Mary Johnson: None
```
</CodeGroup>
Loading
Loading