corfodemo / ailib.py
sergiolucero's picture
updated completion model
8b5626d verified
raw
history blame
1.2 kB
import openai
import time
OPENAI_TRANSCRIPTION_MODEL='whisper-1'
OPENAI_COMPLETION_MODEL = "gpt-4o-mini"
TOKEN_LIMIT = 4096
openai_client = openai.OpenAI()
def whisper_transcribe(fn, temperature=0):
t0 = time.time()
audio_file = open(fn,'rb') # redundant?
whisper = openai_client.audio.transcriptions.create
transcript = whisper(model=OPENAI_TRANSCRIPTION_MODEL,
file=audio_file, language='es',
temperature=0.0) # to do, explore temperature
dt = round(time.time()-t0,2)
transcript = transcript.text
print(f'Whisper transcribe [dt={dt} secs]')
return transcript
def summarize(text):
prompt = f"Resume todos los aspectos médicos de esta consulta: '{text}'"
response = openai_client.chat.completions.create(
model = OPENAI_COMPLETION_MODEL,
messages = [{'role': 'user',
'content': prompt}
],
temperature = 0, max_tokens = TOKEN_LIMIT,
top_p=1.0, frequency_penalty=0.0,
presence_penalty=0.0)
resp_text = response.choices[0].message.content # use others?
return resp_text