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.
llm/05-Embedding/01-Embedding实操-OpenAI.py

24 lines
521 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from openai import OpenAI
from env_util import OPENAI_BASE_URL, OPENAI_API_KEY
# 这里采用原生的OpenAI的API去玩。
# 1、 拿到OpenAI的Client
client = OpenAI(
base_url=OPENAI_BASE_URL,
api_key=OPENAI_API_KEY,
);
# 2、 调用Embedding模型获取text的向量
text = "i like LLM.";
resp = client.embeddings.create(
model='text-embedding-3-large',
dimensions=512, # 向量的维度~~
input=text
);
# 3、输出结果
print(resp.data[0].embedding)
print(len(resp.data[0].embedding))