feat(ideas.py): add support for generating ideas for a specific subject

feat(ideas.py): add support for appending new ideas to existing ideas.json file
This commit is contained in:
Paillat
2023-05-15 11:50:33 +02:00
parent 5410752853
commit be20abb833
2 changed files with 22 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import openai
import os
import json
from dotenv import load_dotenv
load_dotenv()
@@ -10,16 +11,22 @@ with open('prompts/ideas.txt') as f:
f.close()
async def generate_ideas():
with open('ideas/ideas.json', 'r') as f:
async def generate_ideas(path):
with open(f'{path}/ideas.json', 'r') as f:
ideas = f.read()
ides_json = json.loads(ideas)
f.close()
prmpt = prompt.replace('[existing ideas]', ideas)
print(prmpt)
response = await openai.ChatCompletion.acreate(
model="gpt-3.5-turbo",
messages=[
{"role":"user","content":prmpt},
],
)
return response['choices'][0]['message']['content']
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()