from openai import OpenAI
from orgo import Computer
computer = Computer()
client = OpenAI()
response = client.responses.create(
model="computer-use-preview",
tools=[{
"type": "computer_use_preview",
"display_width": 1024,
"display_height": 768,
"environment": "linux",
}],
input=[{
"role": "user",
"content": [{"type": "input_text", "text": "Open Firefox and search for AI news"}],
}],
truncation="auto",
)
# Process computer_call actions
for item in response.output:
if item.type == "computer_call":
action = item.action
if action.type == "click":
computer.left_click(action.x, action.y)
elif action.type == "double_click":
computer.double_click(action.x, action.y)
elif action.type == "type":
computer.type(action.text)
elif action.type == "key" or action.type == "keypress":
keys = getattr(action, "keys", [getattr(action, "key", [])])
computer.key("+".join(keys).lower() if len(keys) > 1 else keys[0])
elif action.type == "scroll":
scroll_y = getattr(action, "scroll_y", 0)
computer.scroll("down" if scroll_y > 0 else "up", abs(scroll_y) // 100)
computer.destroy()