embedding.py
This commit is contained in:
commit
a150d02d7a
25
embedding.py
Normal file
25
embedding.py
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
os.environ["OPENAI_API_KEY"]= "sk-PRJ811XeKzEy20Ug3dA98a34Af8b40B5816dE15503D33599"
|
||||
os.environ["OPENAI_BASE_URL"]= "http://154.9.28.247:3000/v1/"
|
||||
|
||||
from openai import OpenAI
|
||||
client = OpenAI()
|
||||
|
||||
from sklearn.metrics.pairwise import cosine_similarity
|
||||
|
||||
def embedding(s:str):
|
||||
if len(s)==0:
|
||||
return
|
||||
else:
|
||||
return client.embeddings.create(
|
||||
input=s, model="text-embedding-3-large" # nomic-embed-text text-embedding-3-small
|
||||
).data[0].embedding
|
||||
|
||||
a=embedding("I tend to draw fine distinctions between similar feelings (e.g., depressed and blue; annoyed and irritated).")
|
||||
# b=embedding("我喜欢界定两种相似的情绪(如沮丧和忧伤,烦恼和被激怒)。")
|
||||
# c=embedding("I like to define two similar emotions (e.g., frustration and sadness, annoyance and irritation).")
|
||||
|
||||
print(a,"\n",len(a))
|
||||
|
||||
# s = cosine_similarity([a, b, c])
|
||||
# print(s)
|
Loading…
Reference in New Issue
Block a user