Skip to content

Commit

Permalink
docs: Add missing section headers and fix broken links (#1232)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex M <alex.martin@cabinetoffice.gov.uk>
Co-authored-by: Jason Liu <jxnl@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 3c5c113 commit d15209a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 0 additions & 2 deletions docs/examples/bulk_classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,4 @@ async def get_tags(text: List[str], tags: List[Tag]) -> List[Tag]:
tag_results = asyncio.run(get_tags(text, tags))
for tag in tag_results:
print(tag)
#> id=0 name='personal'
#> id=1 name='phone'
```
15 changes: 15 additions & 0 deletions docs/integrations/anthropic.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pip install "instructor[anthropic]"

Once we've done so, getting started is as simple as using our `from_anthropic` method to patch the client up.

### Basic Usage

```python
from pydantic import BaseModel
from typing import List
Expand Down Expand Up @@ -71,6 +73,19 @@ print(user_response.model_dump_json(indent=2))
"""
```

### Beta API Features

Anthropic provides beta features through their beta API endpoint. To use these features, enable the beta parameter when creating the client:

```python
client = instructor.from_anthropic(
anthropic.Anthropic(),
beta=True # Enable beta API features
)
```

This allows you to access beta features like PDF support and other experimental capabilities. For more information about available beta features, refer to [Anthropic's documentation](https://docs.anthropic.com/claude/docs/beta-features).

## Streaming Support

Instructor has two main ways that you can use to stream responses out
Expand Down
21 changes: 21 additions & 0 deletions instructor/client_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def from_anthropic(
),
mode: instructor.Mode = instructor.Mode.ANTHROPIC_TOOLS,
enable_prompt_caching: bool = False,
beta: bool = False,
**kwargs: Any,
) -> instructor.Instructor: ...

Expand All @@ -26,6 +27,7 @@ def from_anthropic(
),
mode: instructor.Mode = instructor.Mode.ANTHROPIC_TOOLS,
enable_prompt_caching: bool = False,
beta: bool = False,
**kwargs: Any,
) -> instructor.AsyncInstructor: ...

Expand All @@ -41,8 +43,25 @@ def from_anthropic(
),
mode: instructor.Mode = instructor.Mode.ANTHROPIC_TOOLS,
enable_prompt_caching: bool = False,
beta: bool = False,
**kwargs: Any,
) -> instructor.Instructor | instructor.AsyncInstructor:
"""Create an Instructor instance from an Anthropic client.
Args:
client: An instance of Anthropic client (sync or async)
mode: The mode to use for the client (ANTHROPIC_JSON or ANTHROPIC_TOOLS)
enable_prompt_caching: Whether to enable prompt caching (requires Anthropic or AsyncAnthropic client)
beta: Whether to use beta API features (uses client.beta.messages.create)
**kwargs: Additional keyword arguments to pass to the Instructor constructor
Returns:
An Instructor instance (sync or async depending on the client type)
Raises:
TypeError: If enable_prompt_caching is True and client is not Anthropic or AsyncAnthropic
AssertionError: If mode is not ANTHROPIC_JSON or ANTHROPIC_TOOLS
"""
assert (
mode
in {
Expand Down Expand Up @@ -70,6 +89,8 @@ def from_anthropic(
raise TypeError(
"Client must be an instance of {anthropic.Anthropic, anthropic.AsyncAnthropic} to enable prompt caching"
)
elif beta:
create = client.beta.messages.create
else:
create = client.messages.create

Expand Down

0 comments on commit d15209a

Please sign in to comment.