Skip to content

Instantly share code, notes, and snippets.

@belkarx
Created May 2, 2024 21:14
Show Gist options
  • Save belkarx/1e765bb75aa64387f61b68546fa3959d to your computer and use it in GitHub Desktop.
Save belkarx/1e765bb75aa64387f61b68546fa3959d to your computer and use it in GitHub Desktop.
import sys
from anthropic import Client
def main():
# Get the API key from an environment variable or secret management system
client = Client()
# Get the input string from the command-line arguments
input_string = " ".join(sys.argv[1:])
print("got " + input_string)
print("calling api")
# Call the API with the input string
response = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=20,
temperature=0,
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"please write a bash command that does the following, in the simplest way possible. return only the bash code!!!: {input_string}"
}
]
}
]
)
# Print the API response
r = response.content[0].text.strip()
print(r)
i = input("Press Enter to continue...")
# execute response
print("executing")
import os
os.system(r)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment