mirror of
https://github.com/trycua/computer.git
synced 2026-01-04 04:19:57 -06:00
Updated example, cua-core dep, and added --prompt
This commit is contained in:
@@ -92,26 +92,30 @@ def print_welcome(model: str, agent_loop: str, container_name: str):
|
||||
async def ainput(prompt: str = ""):
|
||||
return await asyncio.to_thread(input, prompt)
|
||||
|
||||
async def chat_loop(agent, model: str, container_name: str):
|
||||
async def chat_loop(agent, model: str, container_name: str, initial_prompt: str = ""):
|
||||
"""Main chat loop with the agent."""
|
||||
print_welcome(model, agent.agent_loop.__name__, container_name)
|
||||
|
||||
history = []
|
||||
|
||||
if initial_prompt:
|
||||
history.append({"role": "user", "content": initial_prompt})
|
||||
|
||||
while True:
|
||||
# Get user input with prompt
|
||||
print_colored("> ", end="")
|
||||
user_input = await ainput()
|
||||
|
||||
if user_input.lower() in ['exit', 'quit', 'q']:
|
||||
print_colored("\n👋 Goodbye!")
|
||||
break
|
||||
if history[-1].get("role") != "user":
|
||||
# Get user input with prompt
|
||||
print_colored("> ", end="")
|
||||
user_input = await ainput()
|
||||
|
||||
if not user_input:
|
||||
continue
|
||||
|
||||
# Add user message to history
|
||||
history.append({"role": "user", "content": user_input})
|
||||
if user_input.lower() in ['exit', 'quit', 'q']:
|
||||
print_colored("\n👋 Goodbye!")
|
||||
break
|
||||
|
||||
if not user_input:
|
||||
continue
|
||||
|
||||
# Add user message to history
|
||||
history.append({"role": "user", "content": user_input})
|
||||
|
||||
# Stream responses from the agent with spinner
|
||||
with yaspin(text="Thinking...", spinner="line", attrs=["dark"]) as spinner:
|
||||
@@ -204,6 +208,12 @@ Examples:
|
||||
action="store_true",
|
||||
help="Enable verbose logging"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-p", "--prompt",
|
||||
type=str,
|
||||
help="Initial prompt to send to the agent. Leave blank for interactive mode."
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -269,9 +279,11 @@ Examples:
|
||||
agent_kwargs = {
|
||||
"model": args.model,
|
||||
"tools": [computer],
|
||||
"only_n_most_recent_images": args.images,
|
||||
"verbosity": 20 if args.verbose else 30, # DEBUG vs WARNING
|
||||
}
|
||||
|
||||
if args.images > 0:
|
||||
agent_kwargs["only_n_most_recent_images"] = args.images
|
||||
|
||||
if args.trajectory:
|
||||
agent_kwargs["trajectory_dir"] = "trajectories"
|
||||
@@ -286,7 +298,7 @@ Examples:
|
||||
agent = ComputerAgent(**agent_kwargs)
|
||||
|
||||
# Start chat loop
|
||||
await chat_loop(agent, args.model, container_name)
|
||||
await chat_loop(agent, args.model, container_name, args.prompt)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ dependencies = [
|
||||
"rich>=13.7.1",
|
||||
"python-dotenv>=1.0.1",
|
||||
"cua-computer>=0.3.0,<0.5.0",
|
||||
"cua-core>=0.1.0,<0.2.0",
|
||||
"cua-core>=0.1.8,<0.2.0",
|
||||
"certifi>=2024.2.2",
|
||||
"litellm>=1.74.8"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user