Lambuda commited on
Commit
c5c69a3
·
1 Parent(s): 04a9b69
Files changed (1) hide show
  1. main.py +3 -2
main.py CHANGED
@@ -1,6 +1,7 @@
1
 
2
  from fastapi import FastAPI,Request
3
  from langchain.embeddings import HuggingFaceEmbeddings
 
4
 
5
  app = FastAPI()
6
 
@@ -16,13 +17,13 @@ async def process_post_request(request: Request):
16
  # 在这里可以对接收到的数据进行处理
17
  # 例如,可以通过data["key"]来访问请求体中的参数
18
  print(data)
19
- embeddings = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese", model_kwargs={'device': "cpu"})
20
  result= embeddings.embed_query(data['data'])
21
  return result
22
 
23
 
24
  if __name__ == '__main__':
25
- embeddings = HuggingFaceEmbeddings(model_name="M:\\hugging face model\\text2vec-large-chinese", model_kwargs={'device': "cpu"})
26
  result= embeddings.embed_query("你好")
27
  print(result)
28
 
 
1
 
2
  from fastapi import FastAPI,Request
3
  from langchain.embeddings import HuggingFaceEmbeddings
4
+ from sentence_transformers import SentenceTransformer
5
 
6
  app = FastAPI()
7
 
 
17
  # 在这里可以对接收到的数据进行处理
18
  # 例如,可以通过data["key"]来访问请求体中的参数
19
  print(data)
20
+ embeddings = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese", model_kwargs={'device': "cpu","cache_dir":'/cache'})
21
  result= embeddings.embed_query(data['data'])
22
  return result
23
 
24
 
25
  if __name__ == '__main__':
26
+ embeddings = HuggingFaceEmbeddings(model_name="GanymedeNil/text2vec-large-chinese", model_kwargs={'device': "cpu"})
27
  result= embeddings.embed_query("你好")
28
  print(result)
29