Use completions endpoint

This commit is contained in:
Eric Meehan 2025-03-28 10:33:04 -04:00
parent 42bf3f0e98
commit f1b7787553
2 changed files with 24 additions and 8 deletions

13
app.py
View File

@ -5,7 +5,8 @@ from moviepy import VideoFileClip
from openai import OpenAI from openai import OpenAI
from pydub import AudioSegment from pydub import AudioSegment
DEFAULT_PROMPT = "The user will provided a video transcription for which you are to generate a blog post in Markdown format summarizing the video contents. Please only output the blog post content." from prompt import DEFAULT_PROMPT
VIDEO_URL = os.getenv('INPUT_VIDEO_URL', None) VIDEO_URL = os.getenv('INPUT_VIDEO_URL', None)
OUTPUT_PATH = os.getenv('OUTPUT_PATH', 'tmp') OUTPUT_PATH = os.getenv('OUTPUT_PATH', 'tmp')
AUDIO_SEGMENT_DURATION = 30000 AUDIO_SEGMENT_DURATION = 30000
@ -59,13 +60,9 @@ def transcribe_audio(openai_client, audio_segments):
]) ])
def summarize_transcription(openai_client, transcription): def summarize_transcription(openai_client, transcription):
return openai_client.chat.completions.create( return openai_client.completions.create(
model=OPENAI_CHAT_MODEL, model=OPENAI_CHAT_MODEL,
n=OPENAI_CHAT_N, prompt=OPENAI_CHAT_SYSTEM_PROMPT.format(transcription)
messages = [
{"role": "developer", "content": OPENAI_CHAT_SYSTEM_PROMPT},
{"role": "user", "content": transcription}
]
).choices ).choices
def setup(): def setup():
@ -79,4 +76,4 @@ if __name__ == '__main__':
setup() setup()
for each in main(): for each in main():
print("========") print("========")
print(each.message.content) print(each.text)

19
prompt.py Normal file
View File

@ -0,0 +1,19 @@
DEFAULT_PROMPT = """
You are a professional blog writer and SEO expert. You will be given the transcript of a live stream for which you are to generate
a blog post.
Instructions:
- The blog post title should be SEO optimized.
- The blog post should be properly and beautifully formatted using markdown.
- Each blog post should have around 5 sections with 3 sub-sections each.
- Each sub section should have about 3 paragraphs.
- Sub-section headings should be clearly marked.
- Ensure that the content flows logically from one section to another, maintaining coherence and readability.
- In the final section, provide a forward-looking perspective on the topic and a conclusion.
- Make the blog post sound as human and as engaging as possible, add real world examples and make it as informative as possible.
- Please ensure proper and standard markdown formatting always.
Transcription: {}
Blog Post:
"""