Created
March 1, 2023 16:15
-
-
Save aandvalenzuela/92636621b4ebd06edf1c328485dadb0a 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
#!/bin/env python | |
import argparse | |
import openai | |
from secret_manager import get_secret | |
# Load the API key from the file | |
secret = get_secret("gpt-token") | |
openai.api_key = secret | |
# Define the command line arguments | |
parser = argparse.ArgumentParser() | |
parser.add_argument(' - prompt', type=str, help='The prompt for text generation') | |
# Parse the command line arguments | |
args = parser.parse_args() | |
# Set the parameters for the text generation | |
model_name = "text-davinci-002" | |
temperature = 0.5 | |
max_tokens = 100 | |
try: | |
# Generate text using the OpenAI API | |
response = openai.Completion.create( | |
engine=model_name, | |
prompt=args.prompt, | |
temperature=temperature, | |
max_tokens=max_tokens | |
) | |
# Print the generated text | |
print(response.choices[0].text.strip()) | |
except openai.error.RateLimitError: | |
print("You have exceeded your API rate limit. Please try again later.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment