mirror of
https://github.com/Paillat-dev/FABLE.git
synced 2026-01-02 01:06:20 +00:00
feat(generators/montage.py): add check to skip slide if it already exists feat(generators/montage.py): add support for DEEPL_ACCESS_KEY and UNSPLASH_ACCESS_KEY environment variables feat(generators/speak.py): add support for Johanne voice feat(generators/speak.py): add emotion parameter to generate_voice function feat(generators/uploader.py): add success message and authorization prompt message to run_local_server method fix(main.py): check if credits is None before writing to meta.txt file feat(prompts/marp.md): change theme to gaia and add lead and invert classes
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import openai
|
|
import os
|
|
import json
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
with open('prompts/ideas.txt') as f:
|
|
prompt = f.read()
|
|
f.close()
|
|
|
|
|
|
async def generate_ideas(path, subject):
|
|
prmpt = prompt.replace('[subject]', subject)
|
|
try:
|
|
with open(f'{path}/ideas.json', 'r') as f:
|
|
ideas = f.read()
|
|
ides_json = json.loads(ideas)
|
|
f.close()
|
|
except:
|
|
ides_json = []
|
|
ideas = "There are no existing ideas."
|
|
exuisting_ideas = ""
|
|
for idea in ides_json:
|
|
exuisting_ideas += f"{idea['title']}\n"
|
|
prmpt = prmpt.replace('[existing ideas]', exuisting_ideas)
|
|
print(prmpt)
|
|
response = await openai.ChatCompletion.acreate(
|
|
model="gpt-3.5-turbo",
|
|
messages=[
|
|
{"role":"user","content":prmpt},
|
|
],
|
|
)
|
|
json_in_str= response['choices'][0]['message']['content']
|
|
json_obj = json.loads(json_in_str)
|
|
for idea in json_obj:
|
|
ides_json.append(idea)
|
|
with open(f'{path}/ideas.json', 'w') as f:
|
|
f.write(json.dumps(ides_json))
|
|
f.close() |