File size: 961 Bytes
8ac01f6
8fe64f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ac01f6
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import openai
from io import BytesIO

from engines import TranscriptEngine


def transcribe(engine: TranscriptEngine, language: str, audio_file: BytesIO) -> str:
    return engine.transcribe(language, audio_file)


def summarize_transcript(
    openai_api_key: str,
    transcript: str,
    openai_model: str = 'gpt-4',
    prompt: str = 'Summarize the following audio transcription with a list of the key points with the speakers in the original language:',
) -> str:
    """Summarize the transcription using OpenAI's API"""
    openai.api_key = openai_api_key
    prompt = f'Please summarize the following audio transcription in the original language: {transcript}'
    
    response = openai.ChatCompletion.create(
        model=openai_model,
        messages=[{'role': 'user', 'content': f'{prompt}\n\n{transcript}'}],
        temperature=0.5,
        max_tokens=150,
    )
    
    summary = response['choices'][0]['message']['content']
    return summary