diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 3ab2a18..28ca833 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -19,6 +19,9 @@ min_comments = { default = 20, optional = false, nmin = 10, type = "int", explan [ai] ai_similarity_enabled = {optional = true, option = [true, false], default = false, type = "bool", explanation = "Threads read from Reddit are sorted based on their similarity to the keywords given below"} ai_similarity_keywords = {optional = true, type="str", example= 'Elon Musk, Twitter, Stocks', explanation = "Every keyword or even sentence, seperated with comma, is used to sort the reddit threads based on similarity"} +use_openai = { optional = true, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to use OpenAI" } +openai_api_key = {optional = true, type="str", example= 'sk-1234-567', explanation = "If you want to access chatGPT you'll need to enter an API Key"} + [settings] allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to allow NSFW content, True or False" } diff --git a/utils/chatgpt.py b/utils/chatgpt.py new file mode 100644 index 0000000..fe07786 --- /dev/null +++ b/utils/chatgpt.py @@ -0,0 +1,31 @@ +import openai +from utils import settings +from utils.console import print_step + + +def get_video_details( + subreddit: str, filename: str, reddit_title: str +): + """Gets a title, description and tags from chatGPT and saves as a txt file + + Args: + @param subreddit: + @param reddit_title: + """ + print_step("Now asking ChatGPT for Video Details") + openai.api_key = settings.config["ai"]["openai_api_key"] + messages = [ {"role": "system", "content": + "You are a intelligent assistant."} ] + messages.append( + {"role": "user", "content": "I would like you to supply a video title, description and tags comma-separated for a video about: " + reddit_title}, + ) + chat = openai.ChatCompletion.create( + model="gpt-3.5-turbo", messages=messages + ) + reply = chat.choices[0].message.content + print(f"ChatGPT: {reply}") + path = f"results/{subreddit}/{filename}" + path = path[:251] + path = path + ".txt" + with open(path, 'w', encoding="utf-8") as f: + f.write(reply) diff --git a/video_creation/final_video.py b/video_creation/final_video.py index 7ef9c2b..db4d0ca 100644 --- a/video_creation/final_video.py +++ b/video_creation/final_video.py @@ -17,6 +17,7 @@ from utils.cleanup import cleanup from utils.console import print_step, print_substep from utils.thumbnail import create_thumbnail from utils.videos import save_data +from utils.chatgpt import get_video_details console = Console() @@ -355,6 +356,7 @@ def make_final_video( pbar.update(100 - old_percentage) pbar.close() + get_video_details(subreddit, filename, title) save_data(subreddit, filename + ".mp4", title, idx, background_config[2]) print_step("Removing temporary files 🗑") cleanups = cleanup(reddit_id)