You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
556 B
27 lines
556 B
import openai
|
|
from dotenv import load_dotenv
|
|
from os import getenv
|
|
|
|
load_dotenv()
|
|
|
|
|
|
def get_ada_embeddings(text: str, model: str = "text-embedding-ada-002"):
|
|
"""
|
|
Simple function to get embeddings from ada
|
|
|
|
Usage:
|
|
>>> get_ada_embeddings("Hello World")
|
|
>>> get_ada_embeddings("Hello World", model="text-embedding-ada-001")
|
|
|
|
"""
|
|
openai.api_key = getenv("OPENAI_API_KEY")
|
|
|
|
text = text.replace("\n", " ")
|
|
|
|
return openai.Embedding.create(
|
|
input=[text],
|
|
model=model,
|
|
)["data"][
|
|
0
|
|
]["embedding"]
|