Created
February 25, 2022 04:29
-
-
Save shahidcsebd/de8e141f4da62430d6b9e85df895e4ba to your computer and use it in GitHub Desktop.
AI Generated FAQ for a keyword
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 openai | |
import random | |
def random_number(): | |
number = random.randint(2, 4) | |
return number | |
def get_answer(question): | |
openai.api_key = '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' | |
response = openai.Completion.create( | |
engine="text-davinci-001", | |
prompt=question, | |
temperature=0.7, | |
max_tokens=200, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
content = response.choices[0].text.split('.') | |
# print(content) | |
return response.choices[0].text | |
def generate_questions(get_keyword): | |
formatted_text = f'Generate {random_number()} frequently ask questions about this keyword: {get_keyword}' | |
openai.api_key = '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' | |
response = openai.Completion.create( | |
engine="text-davinci-001", | |
prompt=formatted_text, | |
temperature=0.7, | |
max_tokens=200, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
content = response.choices[0].text.split('.') | |
return content | |
keyword = 'best laptop' | |
question_list = generate_questions(keyword) | |
print(question_list) | |
# Trying to do this but not working as expected. | |
# for question in question_list: | |
# print(question) | |
# print(get_answer(question)) | |
# What we need? | |
# I'm trying to print this in h2 heading tag. Example: What is the best laptop? | |
# Then under this heading tag, print the answer to question in paragraph text from get_answer() function. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment