2023-11-13 12:23:15 +00:00
|
|
|
from langchain.embeddings.openai import OpenAIEmbeddings
|
2023-11-14 10:52:55 +00:00
|
|
|
import json
|
2023-11-13 12:23:15 +00:00
|
|
|
|
|
|
|
question = "这个 yarn 为什么会发生错误,该怎么解决?使用中文回复"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 准备嵌入模型
|
|
|
|
embeddings = OpenAIEmbeddings(model="text-embedding-ada-002")
|
|
|
|
|
|
|
|
vec = embeddings.embed_query(question)
|
|
|
|
|
|
|
|
# 转换成 json 并保存到文件
|
|
|
|
|
|
|
|
v_json = json.dumps(vec)
|
|
|
|
|
|
|
|
f = open("question_vec.json", "w")
|
|
|
|
f.write(v_json)
|
|
|
|
f.close()
|