Links

Write an outline

Tags: #openai #outline #writing #topic #structure #organize
Author: Florent Ravenel​
Last update: 2023-04-12 (Created: 2023-02-24)
Description: This notebook will provide an outline for writing a specific topic. An outline is a structured plan or framework that serves as a blueprint for organizing and presenting information in a clear and logical way. Outlines can be used for a variety of purposes, such as organizing an essay or research paper, preparing a speech or presentation, or planning a project.
References:

Input

Import Libraries

try:
import openai
except:
!pip install openai --user
import openai
import naas

Setup Variables

  • api_key: OpenAI API key, to obtain an OpenAI API key, please refer to the OpenAI Documentation.
  • topic: the topic to be written about
  • subtopics: a list of subtopics related to the main topic
# Inputs
api_key = naas.secret.get(name="OPENAI_API_KEY") or "ENTER_YOUR_OPENAI_API_KEY"
topic = "OpenAI"
subtopics = "GPT-3, Reinforcement Learning, Generative Models"
prompt = f"Write an outline about '{topic}' with this subtopics '{subtopics}' and references and citations at the end."
​
# Outputs
file_path = f"Outline_{topic.replace(' ', '_')}.txt"

Model

Send requests to OpenAI API

openai.api_key = api_key
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=2048,
temperature=0.5,
)

Get text

text = response['choices'][0]['text']
print(text)

Output

Save text to txt file

text_file = open(file_path, "w")
text_file.write(text)
text_file.close()