Created
December 7, 2022 13:40
-
-
Save qaixerabbas/72ac4b460b69a5c690422e7be02bc306 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 necessary libraries | |
# Need to install requests and openai using PIP | |
# Go to your openai page and get your API from there and update below in the code. | |
import openai | |
import requests | |
import os | |
# Set the OpenAI API key | |
openai.api_key = "YOUR_API_KEY" | |
# Set the prompt that you want to send to ChatGPT | |
prompt = "Hello, my name is John. How are you today?" | |
# Use the OpenAI API to generate a response from ChatGPT | |
response = openai.Completion.create( | |
engine="chatgpt", | |
prompt=prompt, | |
max_tokens=1024, | |
n=1, | |
temperature=0.5, | |
) | |
# Save the response text in a variable | |
response_text = response["choices"][0]["text"] | |
# Use requests to create a PDF file from the response text | |
pdf_file = requests.get( | |
"https://api.html2pdf.app/v1/generate", | |
params={"html": response_text, "apiKey": "YOUR_API_KEY"}, | |
) | |
# Save the PDF file to the local file system | |
with open("response.pdf", "wb") as f: | |
f.write(pdf_file.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment