- 转用json对象方式存储
- 新增文件存储计算结果
This commit is contained in:
parent
b69975d124
commit
8717b81bbc
@ -14,18 +14,9 @@ def embedding(s:str):
|
||||
return
|
||||
else:
|
||||
return client.embeddings.create(
|
||||
input=s, model="text-embedding-3-small" # nomic-embed-text text-embedding-3-small
|
||||
input=s, model="nomic-embed-text" # nomic-embed-text text-embedding-3-small
|
||||
).data[0].embedding
|
||||
|
||||
class edge:
|
||||
a:str
|
||||
b:str
|
||||
sim:float
|
||||
def __init__(self, a:str, b:str, sim:float):
|
||||
self.a=a
|
||||
self.b=b
|
||||
self.sim=sim
|
||||
|
||||
def main(scale:json):
|
||||
|
||||
item=[]
|
||||
@ -42,9 +33,9 @@ def main(scale:json):
|
||||
for i,v in enumerate(simi):
|
||||
for j in range(0,i):
|
||||
# print(simi[i][j],',',item[i],',',item[j])
|
||||
que.append(edge(item[i], item[j], simi[i][j]))
|
||||
que.append({"from":item[j], "i":item[i], "similarity":simi[i][j]})
|
||||
# print("\n")
|
||||
|
||||
sorted(que,key= lambda t : t.sim)
|
||||
sorted(que,key= lambda t : t["similarity"])
|
||||
|
||||
return que
|
15
main.py
15
main.py
@ -1,10 +1,15 @@
|
||||
from ItemRelate import main as relate
|
||||
import json
|
||||
import os
|
||||
|
||||
with open("TestFile/adhd.json") as json_file:
|
||||
if os.path.getsize("TestFile/items.json") == 0:
|
||||
with open("TestFile/adhd.json","r") as json_file:
|
||||
scale = json.load(json_file)
|
||||
que=relate(scale)
|
||||
with open("TestFile/items.json","w") as items:
|
||||
items.write(json.dumps(que))
|
||||
else:
|
||||
with open("TestFile/items.json","r") as items:
|
||||
que = json.load(items)
|
||||
|
||||
que=relate(scale)
|
||||
|
||||
for i in que:
|
||||
print(i.a, i.b, i.sim)
|
||||
print(que)
|
||||
|
Loading…
Reference in New Issue
Block a user