mirror of
https://github.com/trycua/computer.git
synced 2026-05-07 23:51:55 -05:00
Remove unused refs
This commit is contained in:
+30
-39
@@ -23,52 +23,43 @@ async def run_agent_example():
|
|||||||
print("\n=== Example: ComputerAgent with OpenAI and Omni provider ===")
|
print("\n=== Example: ComputerAgent with OpenAI and Omni provider ===")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Create Computer instance with default parameters
|
# Create Computer instance with async context manager
|
||||||
computer = Computer(verbosity=logging.DEBUG)
|
async with Computer(verbosity=logging.DEBUG) as macos_computer:
|
||||||
|
# Create agent with loop and provider
|
||||||
|
agent = ComputerAgent(
|
||||||
|
computer=macos_computer,
|
||||||
|
loop=AgentLoop.OPENAI,
|
||||||
|
# loop=AgentLoop.ANTHROPIC,
|
||||||
|
# loop=AgentLoop.OMNI,
|
||||||
|
model=LLM(provider=LLMProvider.OPENAI), # No model name for Operator CUA
|
||||||
|
# model=LLM(provider=LLMProvider.OPENAI, name="gpt-4.5-preview"),
|
||||||
|
# model=LLM(provider=LLMProvider.ANTHROPIC, name="claude-3-7-sonnet-20250219"),
|
||||||
|
save_trajectory=True,
|
||||||
|
only_n_most_recent_images=3,
|
||||||
|
verbosity=logging.DEBUG,
|
||||||
|
)
|
||||||
|
|
||||||
# Create agent with loop and provider
|
tasks = [
|
||||||
agent = ComputerAgent(
|
"Look for a repository named trycua/cua on GitHub.",
|
||||||
computer=computer,
|
"Check the open issues, open the most recent one and read it.",
|
||||||
loop=AgentLoop.OPENAI,
|
"Clone the repository in users/lume/projects if it doesn't exist yet.",
|
||||||
# loop=AgentLoop.ANTHROPIC,
|
"Open the repository with an app named Cursor (on the dock, black background and white cube icon).",
|
||||||
# loop=AgentLoop.OMNI,
|
"From Cursor, open Composer if not already open.",
|
||||||
model=LLM(provider=LLMProvider.OPENAI), # No model name for Operator CUA
|
"Focus on the Composer text area, then write and submit a task to help resolve the GitHub issue.",
|
||||||
# model=LLM(provider=LLMProvider.OPENAI, name="gpt-4.5-preview"),
|
]
|
||||||
# model=LLM(provider=LLMProvider.ANTHROPIC, name="claude-3-7-sonnet-20250219"),
|
|
||||||
save_trajectory=True,
|
|
||||||
only_n_most_recent_images=3,
|
|
||||||
verbosity=logging.DEBUG,
|
|
||||||
)
|
|
||||||
|
|
||||||
tasks = [
|
for i, task in enumerate(tasks):
|
||||||
"Look for a repository named trycua/cua on GitHub.",
|
print(f"\nExecuting task {i}/{len(tasks)}: {task}")
|
||||||
"Check the open issues, open the most recent one and read it.",
|
async for result in agent.run(task):
|
||||||
"Clone the repository in users/lume/projects if it doesn't exist yet.",
|
# print(result)
|
||||||
"Open the repository with an app named Cursor (on the dock, black background and white cube icon).",
|
pass
|
||||||
"From Cursor, open Composer if not already open.",
|
|
||||||
"Focus on the Composer text area, then write and submit a task to help resolve the GitHub issue.",
|
|
||||||
]
|
|
||||||
|
|
||||||
for i, task in enumerate(tasks):
|
print(f"\n✅ Task {i+1}/{len(tasks)} completed: {task}")
|
||||||
print(f"\nExecuting task {i}/{len(tasks)}: {task}")
|
|
||||||
async for result in agent.run(task):
|
|
||||||
# print(result)
|
|
||||||
pass
|
|
||||||
|
|
||||||
print(f"\n✅ Task {i+1}/{len(tasks)} completed: {task}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in run_omni_agent_example: {e}")
|
logger.error(f"Error in run_agent_example: {e}")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise
|
raise
|
||||||
finally:
|
|
||||||
# Clean up resources
|
|
||||||
if computer and computer._initialized:
|
|
||||||
try:
|
|
||||||
# await computer.stop()
|
|
||||||
pass
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Error stopping computer: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from .api_handler import OpenAIAPIHandler
|
|||||||
from .response_handler import OpenAIResponseHandler
|
from .response_handler import OpenAIResponseHandler
|
||||||
from .tools.manager import ToolManager
|
from .tools.manager import ToolManager
|
||||||
from .types import LLMProvider, ResponseItemType
|
from .types import LLMProvider, ResponseItemType
|
||||||
from .prompts import SYSTEM_PROMPT
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
"""Prompts for OpenAI Agent Response API."""
|
|
||||||
|
|
||||||
# System prompt to be used when no specific system prompt is provided
|
|
||||||
SYSTEM_PROMPT = """
|
|
||||||
You are a helpful assistant that can control a computer to help users accomplish tasks.
|
|
||||||
You have access to a computer where you can:
|
|
||||||
- Click, scroll, and type to interact with the interface
|
|
||||||
- Use keyboard shortcuts and special keys
|
|
||||||
- Read text and images from the screen
|
|
||||||
- Navigate and interact with applications
|
|
||||||
|
|
||||||
A few important rules to follow:
|
|
||||||
1. Only perform actions that the user has requested or that directly support their task
|
|
||||||
2. If uncertain about what the user wants, ask for clarification
|
|
||||||
3. Explain your steps clearly when working on complex tasks
|
|
||||||
4. Be careful when interacting with sensitive data or performing potentially destructive actions
|
|
||||||
5. Always respect user privacy and avoid accessing personal information unless necessary for the task
|
|
||||||
|
|
||||||
When in doubt about how to accomplish something, try to break it down into simpler steps using available computer actions.
|
|
||||||
"""
|
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
from typing import Optional, List, Literal, Dict, Any, Union, TYPE_CHECKING, cast
|
from typing import Optional, List, Literal, Dict, Any, Union, TYPE_CHECKING, cast
|
||||||
from pylume import PyLume
|
from pylume import PyLume
|
||||||
from pylume.models import (
|
from pylume.models import VMRunOpts, VMUpdateOpts, ImageRef, SharedDirectory, VMStatus
|
||||||
VMRunOpts,
|
|
||||||
VMUpdateOpts,
|
|
||||||
ImageRef,
|
|
||||||
SharedDirectory,
|
|
||||||
VMStatus
|
|
||||||
)
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from .models import Computer as ComputerConfig, Display
|
from .models import Computer as ComputerConfig, Display
|
||||||
from .interface.factory import InterfaceFactory
|
from .interface.factory import InterfaceFactory
|
||||||
@@ -66,8 +60,6 @@ class Computer:
|
|||||||
port: Optional port to use for the PyLume server
|
port: Optional port to use for the PyLume server
|
||||||
host: Host to use for PyLume connections (e.g. "localhost", "host.docker.internal")
|
host: Host to use for PyLume connections (e.g. "localhost", "host.docker.internal")
|
||||||
"""
|
"""
|
||||||
if TYPE_CHECKING:
|
|
||||||
from .interface.base import BaseComputerInterface
|
|
||||||
|
|
||||||
self.logger = Logger("cua.computer", verbosity)
|
self.logger = Logger("cua.computer", verbosity)
|
||||||
self.logger.info("Initializing Computer...")
|
self.logger.info("Initializing Computer...")
|
||||||
@@ -159,6 +151,18 @@ class Computer:
|
|||||||
"""Exit async context manager."""
|
"""Exit async context manager."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
"""Enter synchronous context manager."""
|
||||||
|
# Run the event loop to call the async run method
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.run_until_complete(self.run())
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
"""Exit synchronous context manager."""
|
||||||
|
# We could add cleanup here if needed in the future
|
||||||
|
pass
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
"""Initialize the VM and computer interface."""
|
"""Initialize the VM and computer interface."""
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|||||||
Reference in New Issue
Block a user