t2v_client.py 862 B

1234567891011121314151617181920212223242526272829
  1. # coding:utf-8
  2. import grpc
  3. from a2s.a2s_client import a2s_execute
  4. # from proto import service_pb2, service_pb2_grpc
  5. from proto.text2vector_pb2 import Text2VectorReq, Text2VectorResp
  6. def start(data: str):
  7. # 本次不使用SSL,所以channel是不安全的
  8. result = []
  9. try:
  10. # 调用服务端方法
  11. resp = Text2VectorReq(text=data)
  12. response=a2s_execute("192.168.3.240:9090","t2v2",timeout=60,bytes_data=resp.SerializeToString())
  13. # 获取结果
  14. req = Text2VectorResp()
  15. req.ParseFromString(response)
  16. result = list(req.vector)
  17. except Exception as e:
  18. print(e)
  19. return result
  20. if __name__ == '__main__':
  21. r = start("公共厕所服务")
  22. print(len(r))
  23. print(r)
  24. # http://172.17.145.164:19805,http://172.17.148.50:19805,http://172.17.4.184:19805