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/02-Embedding实操-LangChian.py

24 lines
539 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 langchain_openai import OpenAIEmbeddings
from openai import OpenAI
from env_util import OPENAI_BASE_URL, OPENAI_API_KEY
# 这里采用Langchain的API访问,模型还是OpenAI的模型
# 1、 拿到OpenAI的Client
llm = OpenAIEmbeddings(
base_url=OPENAI_BASE_URL,
api_key=OPENAI_API_KEY,
model='text-embedding-3-large',
dimensions=512, # 向量的维度~~
);
# 2、 调用Embedding模型获取text的向量
text = "i like LLM.";
resp = llm.embed_query(text);
# 3、输出结果
print(resp)
# print(len(resp))