Last active
March 1, 2023 15:55
-
-
Save aandvalenzuela/3131376ddb35fb85b5d50186a08dfa4d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 openai | |
| from openai_secret_manager import get_secret | |
| # Load the API key from the file | |
| secret = get_secret("openai")["api_key"] | |
| openai.api_key = secret | |
| # Define the prompt for the text generation | |
| prompt = "Once upon a time" | |
| # 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=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