File size: 583 Bytes
a03292c
 
 
 
 
 
 
 
42b9715
 
 
 
 
a03292c
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import openai


def get_embedding(text, model="text-embedding-ada-002"):
    text = text.replace("\n", " ")
    return openai.Embedding.create(input=[text], model=model)["data"][0]["embedding"]


def get_embeddings(text_lists, model="text-embedding-ada-002"):
    res = openai.Embedding.create(input=text_lists, model=model)["data"]
    return [r["embedding"] for r in res]


def whisper_transcription(file_path) -> str:
    audio_file = open(file_path, "rb")

    result = openai.Audio.transcribe(
        model="whisper-1",
        file=audio_file,
    )
    return result["text"]