| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --grpclib_python_out=. grpc_m/vector/vector.proto
- // https://github.com/vmagamedov/grpclib
- // https://github.com/danielgtaylor/python-betterproto
- // python -m grpc_tools.protoc -I. --python_out=. --grpclib_python_out=. langchain_service.proto
- // protoc -I . --python_betterproto_out=lib example.proto
- // * `-I./grpc`: 指定搜索导入的 `.proto` 文件的目录。这里,我们告诉 `protoc` 在 `./grpc` 目录中查找其他 `.proto` 文件(如果有的话)。
- // * `--python_out=./grpc/gen_code`: 指定生成的 Python 代码的输出目录。
- // * `--grpc_python_out=./grpc/gen_code`: 指定生成的 gRPC Python 代码的输出目录。注意,这通常会覆盖上面的 `--python_out`,但为了确保清晰,我在这里都包括了。实际上,对于 gRPC,你只需要 `--grpc_python_out`。但是,如果你也想生成纯的 Protobuf Python 代码(不包括 gRPC 服务和服务端/客户端代码),那么你需要同时指定两者。
- // * `./grpc/vector_service.proto`: 指定要编译的 `.proto` 文件的路径。
- syntax = "proto3";
- // grpc_m/vector_service.proto
- package langchain_service;
- // 定义错误枚举类型
- enum ErrorCode {
- SUCCESS = 0;
- DOC_CONVERT_ERROR = 1;
- VECTOR_SERVER_ERROR = 2;
- }
- service VectorService {
- rpc SaveDocToVector (SaveDocToVectorRequest) returns (SaveDocToVectorResponse) {}
- rpc DocChat (DocChatRequest) returns (DocChatResponse) {}
- rpc SearchWithIds (SearchWithIdsRequests) returns (SearchResponses) {}
- rpc SimilaritySearch (SearchRequest) returns (SearchResponses) {}
- }
- message SaveDocToVectorRequest {
- string collection_name = 1;
- // {open_id}/docs/exzample.pdf
- string user_doc_relative_path = 2;
- }
- message SaveDocToVectorResponse {
- ErrorCode status = 1;
- }
- message DocChatRequest {
- string collection_name = 1;
- string prompt = 2;
- }
- message DocChatResponse {
- string reply = 1;
- }
- message SearchRequest {
- string collection_name = 1;
- string query = 2;
- }
- message SearchWithIdsRequest {
- string uuid = 1;
- }
- message SearchWithIdsRequests {
- repeated SearchWithIdsRequest request = 1;
- }
- message SearchResponse {
- string chunk = 1;
- map<string, string> metadata = 2;
- float score = 3;
- string uuid = 4;
- }
- message SearchResponses {
- repeated SearchResponse data = 1;
- }
|