Last active
November 21, 2023 01:59
Revisions
-
itrobotics revised this gist
Nov 21, 2023 . 1 changed file with 21 additions and 11 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,23 @@ import openai # Replace 'YOUR_API_KEY' with your actual API key from OpenAI api_key = 'YOUR_API_KEY' # Initialize the OpenAI API client openai.api_key = api_key # Specify the prompt for text generation prompt = "Once upon a time," # Generate text using the GPT-3 model response = openai.Completion.create( engine="text-davinci-002", # You can choose different engines based on your use case prompt=prompt, max_tokens=50, # Adjust the number of tokens in the generated text ) # Extract the generated text from the response generated_text = response.choices[0].text # Print the generated text print(generated_text) -
itrobotics revised this gist
Nov 21, 2023 . No changes.There are no files selected for viewing
-
itrobotics created this gist
Nov 21, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ os.environ['OPENAI_API_KEY'] = "your_openai_api_key" from openai import OpenAI client = OpenAI() completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[ {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."}, {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."} ] ) print(completion.choices[0].message)