Skip to content
Open
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
51 changes: 34 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ async def main():

# Check if the instruction is provided via command line arguments
if len(sys.argv) > 1:
instruction = " ".join(sys.argv[1:])
initial_instruction = " ".join(sys.argv[1:])
else:
instruction = "Save an image of a cat to the desktop."
initial_instruction = "Save an image of a cat to the desktop."

print(
f"Starting Claude 'Computer Use'.\nPress ctrl+c to stop.\nInstructions provided: '{instruction}'"
f"Starting Claude 'Computer Use'.\nPress ctrl+c to stop.\nInitial instructions: '{initial_instruction}'"
)

# Set up the initial messages
messages: list[BetaMessageParam] = [
{
"role": "user",
"content": instruction,
"content": initial_instruction,
}
]

Expand Down Expand Up @@ -62,19 +62,36 @@ def api_response_callback(response: APIResponse[BetaMessage]):
"\n",
)

# Run the sampling loop
messages = await sampling_loop(
model="claude-3-5-sonnet-20241022",
provider=provider,
system_prompt_suffix="",
messages=messages,
output_callback=output_callback,
tool_output_callback=tool_output_callback,
api_response_callback=api_response_callback,
api_key=api_key,
only_n_most_recent_images=10,
max_tokens=4096,
)
while True:
try:
# Run the sampling loop for current message
messages = await sampling_loop(
model="claude-3-5-sonnet-20241022",
provider=provider,
system_prompt_suffix="",
messages=messages,
output_callback=output_callback,
tool_output_callback=tool_output_callback,
api_response_callback=api_response_callback,
api_key=api_key,
only_n_most_recent_images=10,
max_tokens=4096,
)

# Get next user input
print("\nYou:", end=" ")
user_input = input().strip()

if user_input.lower() in ["exit", "quit"]:
print("Ending conversation...")
break

# Add the new user message to the conversation
messages.append({"role": "user", "content": user_input})

except KeyboardInterrupt:
print("\nEnding conversation...")
break


if __name__ == "__main__":
Expand Down