introducing chatgpt

pull/1573/head
liamb 2 years ago
parent ded12d8b15
commit c94e976b89

@ -19,6 +19,9 @@ min_comments = { default = 20, optional = false, nmin = 10, type = "int", explan
[ai] [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_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"} 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] [settings]
allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to allow NSFW content, True or False" } allow_nsfw = { optional = false, type = "bool", default = false, example = false, options = [true, false, ], explanation = "Whether to allow NSFW content, True or False" }

@ -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)

@ -17,6 +17,7 @@ from utils.cleanup import cleanup
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.thumbnail import create_thumbnail from utils.thumbnail import create_thumbnail
from utils.videos import save_data from utils.videos import save_data
from utils.chatgpt import get_video_details
console = Console() console = Console()
@ -355,6 +356,7 @@ def make_final_video(
pbar.update(100 - old_percentage) pbar.update(100 - old_percentage)
pbar.close() pbar.close()
get_video_details(subreddit, filename, title)
save_data(subreddit, filename + ".mp4", title, idx, background_config[2]) save_data(subreddit, filename + ".mp4", title, idx, background_config[2])
print_step("Removing temporary files 🗑") print_step("Removing temporary files 🗑")
cleanups = cleanup(reddit_id) cleanups = cleanup(reddit_id)

Loading…
Cancel
Save