Spaces:
No application file
No application file
# 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"]) |