File size: 950 Bytes
20c430a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Configuration for generating 3000 words using OpenAI API

import openai

# Estimate: 1 word β‰ˆ 1.3 tokens, so 3000 words β‰ˆ 3900 tokens
# max_tokens is the *maximum* the model can return in tokens
# GPT-4-turbo currently allows up to 4096 tokens in one response (or 128k in some versions)

config = {
    "model": "gpt-4",
    "temperature": 0.7,
    "max_tokens": 3900,  # aiming for ~3000 words (3900 tokens β‰ˆ 3000 words)
    "top_p": 1,
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "stop": None
}

prompt = "Write a detailed story about a lone warrior in a post-apocalyptic world who discovers a hidden underground city. The story should be around 3000 words long."

response = openai.ChatCompletion.create(
    messages=[
        {"role": "system", "content": "You are a helpful, descriptive storyteller."},
        {"role": "user", "content": prompt}
    ],
    **config
)

print(response["choices"][0]["message"]["content"])