Skip to content
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
4 changes: 3 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ src/scrapybara/client.py
src/scrapybara/anthropic/
src/scrapybara/prompts/
src/scrapybara/tools/
src/scrapybara/types/__init__.py
src/scrapybara/types/act.py
src/scrapybara/types/tool.py
tests/custom/test_client.py
.github/workflows/ci.yml
.github/workflows/ci.yml
README.md
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pip install scrapybara

## Reference

A full reference for this library is available [here](./reference.md).
Please refer to [docs](https://docs.scrapybara.com) for more information.

## Requirements

Expand All @@ -22,10 +22,6 @@ A full reference for this library is available [here](./reference.md).
- `anthropic` ^0.39.0
- `pydantic` ^2.0.0

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Usage

Instantiate and use the client with the following:
Expand All @@ -36,7 +32,7 @@ from scrapybara import Scrapybara
client = Scrapybara(
api_key="YOUR_API_KEY",
)
client.start()
client.start_ubuntu()
```

## Async Client
Expand All @@ -54,7 +50,7 @@ client = AsyncScrapybara(


async def main() -> None:
await client.start()
await client.start_ubuntu()


asyncio.run(main())
Expand All @@ -69,7 +65,7 @@ will be thrown.
from scrapybara.core.api_error import ApiError

try:
client.start(...)
client.start_ubuntu()
except ApiError as e:
print(e.status_code)
print(e.body)
Expand All @@ -92,7 +88,7 @@ A request is deemed retriable when any of the following HTTP status codes is ret
Use the `max_retries` request option to configure this behavior.

```python
client.start(..., request_options={
client.start_ubuntu(..., request_options={
"max_retries": 1
})
```
Expand All @@ -112,7 +108,7 @@ client = Scrapybara(


# Override timeout for a specific method
client.start(..., request_options={
client.start_ubuntu(..., request_options={
"timeout_in_seconds": 1
})
```
Expand All @@ -121,6 +117,7 @@ client.start(..., request_options={

You can override the `httpx` client to customize it for your use-case. Some common use-cases include support for proxies
and transports.

```python
import httpx
from scrapybara import Scrapybara
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scrapybara"
version = "2.1.3"
version = "2.2.0"
description = ""
readme = "README.md"
authors = []
Expand Down
2 changes: 2 additions & 0 deletions src/scrapybara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
FileDownloadResponse,
FileReadResponse,
GetInstanceResponse,
GetInstanceResponseInstanceType,
HttpValidationError,
InstanceGetStreamUrlResponse,
InstanceScreenshotResponse,
Expand Down Expand Up @@ -48,6 +49,7 @@
"FileDownloadResponse",
"FileReadResponse",
"GetInstanceResponse",
"GetInstanceResponseInstanceType",
"HttpValidationError",
"InstanceGetStreamUrlResponse",
"InstanceScreenshotResponse",
Expand Down
44 changes: 22 additions & 22 deletions src/scrapybara/anthropic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import asyncio
from pydantic import Field

from ..client import Instance
from ..client import BaseInstance, UbuntuInstance
from ..types.act import Model
from .base import BaseAnthropicTool, CLIResult, ToolError, ToolResult

Expand Down Expand Up @@ -47,19 +47,19 @@ class ComputerToolOptions(TypedDict):


class ComputerTool(BaseAnthropicTool):
"""
A computer interaction tool that allows the agent to control mouse and keyboard.
The tool parameters are defined by Anthropic and are not editable.
"""
"""A computer interaction tool that allows the agent to control mouse and keyboard.

Available for Ubuntu, Browser, and Windows instances."""

api_type: Literal["computer_20241022"] = "computer_20241022"
name: Literal["computer"] = "computer"
width: int = 1024
height: int = 768
display_num: Optional[int] = 1
_instance: BaseInstance

def __init__(self, instance: Instance):
self.instance = instance
def __init__(self, instance: BaseInstance):
self._instance = instance
super().__init__()

@property
Expand Down Expand Up @@ -88,7 +88,7 @@ async def __call__(self, **kwargs: Any) -> ToolResult:
loop = asyncio.get_event_loop()
result = await loop.run_in_executor(
None,
lambda: self.instance.computer(
lambda: self._instance.computer(
action=action,
coordinate=tuple(coordinate) if coordinate else None,
text=text,
Expand All @@ -105,16 +105,16 @@ async def __call__(self, **kwargs: Any) -> ToolResult:


class EditTool(BaseAnthropicTool):
"""
A filesystem editor tool that allows the agent to view, create, and edit files.
The tool parameters are defined by Anthropic and are not editable.
"""
"""A filesystem editor tool that allows the agent to view, create, and edit files.

Available for Ubuntu instances."""

api_type: Literal["text_editor_20241022"] = "text_editor_20241022"
name: Literal["str_replace_editor"] = "str_replace_editor"
_instance: UbuntuInstance

def __init__(self, instance: Instance):
self.instance = instance
def __init__(self, instance: UbuntuInstance):
self._instance = instance
super().__init__()

def to_params(self) -> BetaToolTextEditor20241022Param:
Expand All @@ -135,7 +135,7 @@ async def __call__(self, **kwargs: Any) -> ToolResult:
loop = asyncio.get_event_loop()
result = await loop.run_in_executor(
None,
lambda: self.instance.edit(
lambda: self._instance.edit(
command=command,
path=path,
file_text=file_text,
Expand All @@ -156,16 +156,16 @@ async def __call__(self, **kwargs: Any) -> ToolResult:


class BashTool(BaseAnthropicTool):
"""
A shell execution tool that allows the agent to run bash commands.
The tool parameters are defined by Anthropic and are not editable.
"""
"""A shell execution tool that allows the agent to run bash commands.

Available for Ubuntu instances."""

api_type: Literal["bash_20241022"] = "bash_20241022"
name: Literal["bash"] = "bash"
_instance: UbuntuInstance

def __init__(self, instance: Instance):
self.instance = instance
def __init__(self, instance: UbuntuInstance):
self._instance = instance
super().__init__()

def to_params(self) -> BetaToolBash20241022Param:
Expand All @@ -181,7 +181,7 @@ async def __call__(self, **kwargs: Any) -> ToolResult:
loop = asyncio.get_event_loop()
result = await loop.run_in_executor(
None,
lambda: self.instance.bash(command=command, restart=restart),
lambda: self._instance.bash(command=command, restart=restart),
)
return CLIResult(
output=result.get("output") if result else "",
Expand Down
Loading