I would like to create a script to write full books using chat gpt
I got the following script, but I want longer content (output). How can I force it?
<code>from openai import OpenAI
model = "gpt-3.5-turbo"
client = OpenAI(api_key='...')
with open('sysprompt') as f:
sysprompt = f.read()
with open('index') as f:
index = f.read()
conversation = [{
"role": "system",
"content": sysprompt
}]
out = ""
chapters = index.split('-')
i = 1
for c in chapters:
conversation.append({
"role": "user",
"content": f"nWrite the content for: {c}"
})
response = client.chat.completions.create(model=model, messages=conversation)
out += response.choices[0].message.content + "n"
print(f"Wrote: {i}/{len(chapters)}")
i += 1
with open('out.txt', 'w') as f:
f.write(out)
</code>
<code>from openai import OpenAI
model = "gpt-3.5-turbo"
client = OpenAI(api_key='...')
with open('sysprompt') as f:
sysprompt = f.read()
with open('index') as f:
index = f.read()
conversation = [{
"role": "system",
"content": sysprompt
}]
out = ""
chapters = index.split('-')
i = 1
for c in chapters:
conversation.append({
"role": "user",
"content": f"nWrite the content for: {c}"
})
response = client.chat.completions.create(model=model, messages=conversation)
out += response.choices[0].message.content + "n"
print(f"Wrote: {i}/{len(chapters)}")
i += 1
with open('out.txt', 'w') as f:
f.write(out)
</code>
from openai import OpenAI
model = "gpt-3.5-turbo"
client = OpenAI(api_key='...')
with open('sysprompt') as f:
sysprompt = f.read()
with open('index') as f:
index = f.read()
conversation = [{
"role": "system",
"content": sysprompt
}]
out = ""
chapters = index.split('-')
i = 1
for c in chapters:
conversation.append({
"role": "user",
"content": f"nWrite the content for: {c}"
})
response = client.chat.completions.create(model=model, messages=conversation)
out += response.choices[0].message.content + "n"
print(f"Wrote: {i}/{len(chapters)}")
i += 1
with open('out.txt', 'w') as f:
f.write(out)
In sysprompt there is the prompt to write a story book
In index there is the list of chapters (37) for the book
I tryed with the code above but I want longer output
New contributor
Raffa50 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1