获取嵌入
函数 get_embedding 将为我们提供输入文本的嵌入。
import openai embedding = openai.Embedding.create( input="Your text goes here", model="text-embedding-ada-002" )["data"][0]["embedding"] len(embedding)
1536
import openai from tenacity import retry, wait_random_exponential, stop_after_attempt @retry(wait=wait_random_exponential(min=1, max=20), stop=stop_after_attempt(6)) def get_embedding(text: str, model="text-embedding-ada-002") -> list[float]: return openai.Embedding.create(input=[text], model=model)["data"][0]["embedding"] embedding = get_embedding("Your text goes here", model="text-embedding-ada-002") print(len(embedding))
1536
评论 (0)