Claude Integration

How to connect the remote cloud-os instance to your code and configure the anthropic claude.

Basic Setup

Main.py
import asyncio
import os
import json
import base64
from io import BytesIO
from PIL import Image
from IPython.display import display
from typing import Any
from datetime import datetime

# Import relevant ToyStack libraries
from toystack import ToyStackClient
from toystack.tools import BashTool, ComputerTool, EditTool, ToolResult

# Initialize ToyStack Client
toystack_client = ToyStackClient(api_key="your_toystack_api_key")
instance = toystack_client.start_instance(instance_type="medium")

# Define Anthropic Client if still using Claude (Optional)
from anthropic import Anthropic
anthropic_client = Anthropic(api_key="your_claude_api_key")

# System prompt adapted for ToyStack
SYSTEM_PROMPT = f"""<SYSTEM_CAPABILITY>
* You are utilizing an Ubuntu virtual machine managed via ToyStack with internet access.
* You can install Ubuntu applications using the bash tool. Use curl instead of wget.
* Firefox (firefox-esr) is pre-installed. To open it, click the Firefox icon.
* GUI applications can be started using the bash tool by setting export DISPLAY=:1 and using a subshell, e.g., "(DISPLAY=:1 xterm &)". GUI apps will appear in the desktop environment but may take some time. Use screenshots to confirm their state.
* For commands generating extensive text outputs, redirect the output to a tmp file and utilize grep or other tools to parse it.
* When browsing a page, either zoom out to view the entire content or scroll through it thoroughly before deciding that something isn't present.
* Chain multiple function calls where possible to optimize execution.
* The current date is {datetime.today().strftime('%A, %B %-d, %Y')}.
</SYSTEM_CAPABILITY>

<IMPORTANT>
* When using Firefox, if a startup wizard appears, IGNORE IT. Do not click "skip this step." Instead, navigate to the address bar, enter the URL or search term directly.
* If you encounter a PDF and need to extract text, determine its URL, use curl to download it, install pdftotext, and convert it to a text file for easier reading.
</IMPORTANT>"""

# Example usage of ToyStack tools
bash_tool = BashTool(instance=instance)
computer_tool = ComputerTool(instance=instance)
edit_tool = EditTool(instance=instance)

# Example function to execute a bash command using ToyStack's BashTool
async def run_bash_command(command: str):
    result = await bash_tool.run(command)
    print("Command Output:", result)

# Example usage
async def main():
    await run_bash_command("echo 'Hello from ToyStack!'")
    # Add more commands or tool usage as needed

# Run the script
asyncio.run(main())

Define Collection Tool

Sampling Loop

Execute

Last updated