Created
May 2, 2024 21:14
-
-
Save belkarx/1e765bb75aa64387f61b68546fa3959d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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