in services/openai.py [0:0]
def get_embeddings(texts: List[str]) -> List[List[float]]:
"""
Embed texts using OpenAI's ada model.
Args:
texts: The list of texts to embed.
Returns:
A list of embeddings, each of which is a list of floats.
Raises:
Exception: If the OpenAI API call fails.
"""
# Call the OpenAI API to get the embeddings
# NOTE: Azure Open AI requires deployment id
deployment = os.environ.get("OPENAI_EMBEDDINGMODEL_DEPLOYMENTID")
response = {}
if deployment is None:
response = openai.Embedding.create(input=texts, model=EMBEDDING_MODEL, dimensions=EMBEDDING_DIMENSION)
else:
response = openai.Embedding.create(input=texts, deployment_id=deployment)
# Extract the embedding data from the response
data = response["data"] # type: ignore
# Return the embeddings as a list of lists of floats
return [result["embedding"] for result in data]