commit a150d02d7ac48a024723998a19e6fd6d2723eefa Author: mxr612 Date: Tue May 14 02:43:50 2024 +0800 embedding.py diff --git a/embedding.py b/embedding.py new file mode 100644 index 0000000..5306bfd --- /dev/null +++ b/embedding.py @@ -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) \ No newline at end of file