增加 document 结构和迁移
改进 api
This commit is contained in:
parent
33cc5f06fb
commit
385739194e
3
Makefile
3
Makefile
@ -2,8 +2,9 @@
|
||||
|
||||
setup:
|
||||
go run . setup
|
||||
|
||||
# Example: go run -mod=mod entgo.io/ent/cmd/ent new User
|
||||
ent:
|
||||
# go run -mod=mod entgo.io/ent/cmd/ent new User
|
||||
go generate ./ent
|
||||
grpc-web:
|
||||
grpcwebproxy --backend_addr=localhost:8081 --run_http_server --run_tls_server=false --server_http_debug_port 18081 --allow_all_origins --server_bind_address 127.0.0.1
|
||||
|
@ -132,6 +132,100 @@ func (x *CreateDocumentResponse) GetDocument() *Document {
|
||||
return nil
|
||||
}
|
||||
|
||||
type ListDocumentRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
LibraryId string `protobuf:"bytes,1,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ListDocumentRequest) Reset() {
|
||||
*x = ListDocumentRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_rag_document_proto_msgTypes[2]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ListDocumentRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListDocumentRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ListDocumentRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_rag_document_proto_msgTypes[2]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListDocumentRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ListDocumentRequest) Descriptor() ([]byte, []int) {
|
||||
return file_api_rag_document_proto_rawDescGZIP(), []int{2}
|
||||
}
|
||||
|
||||
func (x *ListDocumentRequest) GetLibraryId() string {
|
||||
if x != nil {
|
||||
return x.LibraryId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ListDocumentResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Documents []*Document `protobuf:"bytes,1,rep,name=documents,proto3" json:"documents,omitempty"`
|
||||
}
|
||||
|
||||
func (x *ListDocumentResponse) Reset() {
|
||||
*x = ListDocumentResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_rag_document_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ListDocumentResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListDocumentResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ListDocumentResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_rag_document_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListDocumentResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ListDocumentResponse) Descriptor() ([]byte, []int) {
|
||||
return file_api_rag_document_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *ListDocumentResponse) GetDocuments() []*Document {
|
||||
if x != nil {
|
||||
return x.Documents
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Document struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@ -141,14 +235,15 @@ type Document struct {
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
||||
LibraryId string `protobuf:"bytes,4,opt,name=library_id,json=libraryId,proto3" json:"library_id,omitempty"`
|
||||
CreatedAt string `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||
UpdatedAt string `protobuf:"bytes,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||
UserId string `protobuf:"bytes,5,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
|
||||
CreatedAt string `protobuf:"bytes,6,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||
UpdatedAt string `protobuf:"bytes,7,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Document) Reset() {
|
||||
*x = Document{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_rag_document_proto_msgTypes[2]
|
||||
mi := &file_api_rag_document_proto_msgTypes[4]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@ -161,7 +256,7 @@ func (x *Document) String() string {
|
||||
func (*Document) ProtoMessage() {}
|
||||
|
||||
func (x *Document) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_rag_document_proto_msgTypes[2]
|
||||
mi := &file_api_rag_document_proto_msgTypes[4]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@ -174,7 +269,7 @@ func (x *Document) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use Document.ProtoReflect.Descriptor instead.
|
||||
func (*Document) Descriptor() ([]byte, []int) {
|
||||
return file_api_rag_document_proto_rawDescGZIP(), []int{2}
|
||||
return file_api_rag_document_proto_rawDescGZIP(), []int{4}
|
||||
}
|
||||
|
||||
func (x *Document) GetId() int64 {
|
||||
@ -205,6 +300,13 @@ func (x *Document) GetLibraryId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Document) GetUserId() string {
|
||||
if x != nil {
|
||||
return x.UserId
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Document) GetCreatedAt() string {
|
||||
if x != nil {
|
||||
return x.CreatedAt
|
||||
@ -237,17 +339,26 @@ var file_api_rag_document_proto_rawDesc = []byte{
|
||||
0x65, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x12, 0x25, 0x0a, 0x08, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x08,
|
||||
0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0xa5, 0x01, 0x0a, 0x08, 0x44, 0x6f, 0x63,
|
||||
0x75, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
|
||||
0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
|
||||
0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69,
|
||||
0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79,
|
||||
0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x34, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74,
|
||||
0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
|
||||
0x1d, 0x0a, 0x0a, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x09, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x22, 0x3f,
|
||||
0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x09, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
|
||||
0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x44, 0x6f, 0x63, 0x75,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x52, 0x09, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22,
|
||||
0xbe, 0x01, 0x0a, 0x08, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02,
|
||||
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x6c, 0x69,
|
||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
|
||||
0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65,
|
||||
0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72,
|
||||
0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74,
|
||||
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41,
|
||||
0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41,
|
||||
0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18,
|
||||
0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74,
|
||||
0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74,
|
||||
0x42, 0x1e, 0x5a, 0x1c, 0x6c, 0x65, 0x61, 0x66, 0x64, 0x65, 0x76, 0x2e, 0x74, 0x6f, 0x70, 0x2f,
|
||||
0x6c, 0x65, 0x61, 0x66, 0x2f, 0x72, 0x61, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x61, 0x67,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
@ -265,19 +376,22 @@ func file_api_rag_document_proto_rawDescGZIP() []byte {
|
||||
return file_api_rag_document_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_api_rag_document_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_api_rag_document_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_api_rag_document_proto_goTypes = []interface{}{
|
||||
(*CreateDocumentRequest)(nil), // 0: CreateDocumentRequest
|
||||
(*CreateDocumentResponse)(nil), // 1: CreateDocumentResponse
|
||||
(*Document)(nil), // 2: Document
|
||||
(*ListDocumentRequest)(nil), // 2: ListDocumentRequest
|
||||
(*ListDocumentResponse)(nil), // 3: ListDocumentResponse
|
||||
(*Document)(nil), // 4: Document
|
||||
}
|
||||
var file_api_rag_document_proto_depIdxs = []int32{
|
||||
2, // 0: CreateDocumentResponse.document:type_name -> Document
|
||||
1, // [1:1] is the sub-list for method output_type
|
||||
1, // [1:1] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
4, // 0: CreateDocumentResponse.document:type_name -> Document
|
||||
4, // 1: ListDocumentResponse.documents:type_name -> Document
|
||||
2, // [2:2] is the sub-list for method output_type
|
||||
2, // [2:2] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_api_rag_document_proto_init() }
|
||||
@ -311,6 +425,30 @@ func file_api_rag_document_proto_init() {
|
||||
}
|
||||
}
|
||||
file_api_rag_document_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListDocumentRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_api_rag_document_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListDocumentResponse); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_api_rag_document_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Document); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@ -329,7 +467,7 @@ func file_api_rag_document_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_api_rag_document_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 3,
|
||||
NumMessages: 5,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -6,7 +6,6 @@ import "google/api/httpbody.proto";
|
||||
option go_package = "leafdev.top/leaf/rag/api/rag";
|
||||
|
||||
|
||||
|
||||
message CreateDocumentRequest {
|
||||
string name = 1;
|
||||
string content = 2;
|
||||
@ -17,11 +16,20 @@ message CreateDocumentResponse {
|
||||
Document document = 1;
|
||||
}
|
||||
|
||||
message ListDocumentRequest {
|
||||
string library_id = 1;
|
||||
}
|
||||
|
||||
message ListDocumentResponse {
|
||||
repeated Document documents = 1;
|
||||
}
|
||||
|
||||
message Document {
|
||||
int64 id = 1;
|
||||
string name = 2;
|
||||
string content = 3;
|
||||
string library_id = 4;
|
||||
string created_at = 5;
|
||||
string updated_at = 6;
|
||||
string user_id = 5;
|
||||
string created_at = 6;
|
||||
string updated_at = 7;
|
||||
}
|
@ -32,46 +32,56 @@ var file_api_rag_rag_proto_rawDesc = []byte{
|
||||
0x64, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x16, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x61,
|
||||
0x67, 0x2f, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x1a, 0x15, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x61, 0x67, 0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72,
|
||||
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x9a, 0x02, 0x0a, 0x0a, 0x52, 0x41, 0x47, 0x53,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5c, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0xf2, 0x02, 0x0a, 0x0a, 0x52, 0x41, 0x47, 0x53,
|
||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x53, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69,
|
||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x13, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69, 0x62, 0x72,
|
||||
0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76,
|
||||
0x31, 0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x65, 0x73, 0x12, 0x59, 0x0a, 0x0d, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x15, 0x2e, 0x43,
|
||||
0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
|
||||
0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72,
|
||||
0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4,
|
||||
0x93, 0x02, 0x13, 0x22, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x62,
|
||||
0x72, 0x61, 0x72, 0x69, 0x65, 0x73, 0x12, 0x5c, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
|
||||
0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74,
|
||||
0x65, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x17, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e,
|
||||
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02,
|
||||
0x13, 0x22, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x6f, 0x63, 0x75, 0x6d,
|
||||
0x65, 0x6e, 0x74, 0x73, 0x12, 0x53, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69, 0x62, 0x72,
|
||||
0x61, 0x72, 0x79, 0x12, 0x13, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72,
|
||||
0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4c,
|
||||
0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19,
|
||||
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f,
|
||||
0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x69, 0x65, 0x73, 0x12, 0x59, 0x0a, 0x0d, 0x43, 0x72, 0x65,
|
||||
0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x15, 0x2e, 0x43, 0x72, 0x65,
|
||||
0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x1a, 0x16, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72,
|
||||
0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02,
|
||||
0x13, 0x22, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61,
|
||||
0x72, 0x69, 0x65, 0x73, 0x42, 0x1e, 0x5a, 0x1c, 0x6c, 0x65, 0x61, 0x66, 0x64, 0x65, 0x76, 0x2e,
|
||||
0x74, 0x6f, 0x70, 0x2f, 0x6c, 0x65, 0x61, 0x66, 0x2f, 0x72, 0x61, 0x67, 0x2f, 0x61, 0x70, 0x69,
|
||||
0x2f, 0x72, 0x61, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x65, 0x6e, 0x74, 0x73, 0x12, 0x56, 0x0a, 0x0c, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x6f, 0x63, 0x75,
|
||||
0x6d, 0x65, 0x6e, 0x74, 0x12, 0x14, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x44, 0x6f, 0x63, 0x75, 0x6d,
|
||||
0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x61, 0x70, 0x69, 0x2f,
|
||||
0x76, 0x31, 0x2f, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x42, 0x1e, 0x5a, 0x1c,
|
||||
0x6c, 0x65, 0x61, 0x66, 0x64, 0x65, 0x76, 0x2e, 0x74, 0x6f, 0x70, 0x2f, 0x6c, 0x65, 0x61, 0x66,
|
||||
0x2f, 0x72, 0x61, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x72, 0x61, 0x67, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var file_api_rag_rag_proto_goTypes = []interface{}{
|
||||
(*CreateDocumentRequest)(nil), // 0: CreateDocumentRequest
|
||||
(*ListLibraryRequest)(nil), // 1: ListLibraryRequest
|
||||
(*CreateLibraryRequest)(nil), // 2: CreateLibraryRequest
|
||||
(*CreateDocumentResponse)(nil), // 3: CreateDocumentResponse
|
||||
(*ListLibraryRequest)(nil), // 0: ListLibraryRequest
|
||||
(*CreateLibraryRequest)(nil), // 1: CreateLibraryRequest
|
||||
(*CreateDocumentRequest)(nil), // 2: CreateDocumentRequest
|
||||
(*ListDocumentRequest)(nil), // 3: ListDocumentRequest
|
||||
(*ListLibraryResponse)(nil), // 4: ListLibraryResponse
|
||||
(*CreateLibraryResponse)(nil), // 5: CreateLibraryResponse
|
||||
(*CreateDocumentResponse)(nil), // 6: CreateDocumentResponse
|
||||
(*ListDocumentResponse)(nil), // 7: ListDocumentResponse
|
||||
}
|
||||
var file_api_rag_rag_proto_depIdxs = []int32{
|
||||
0, // 0: RagService.RAGService.CreateDocument:input_type -> CreateDocumentRequest
|
||||
1, // 1: RagService.RAGService.ListLibrary:input_type -> ListLibraryRequest
|
||||
2, // 2: RagService.RAGService.CreateLibrary:input_type -> CreateLibraryRequest
|
||||
3, // 3: RagService.RAGService.CreateDocument:output_type -> CreateDocumentResponse
|
||||
0, // 0: RagService.RAGService.ListLibrary:input_type -> ListLibraryRequest
|
||||
1, // 1: RagService.RAGService.CreateLibrary:input_type -> CreateLibraryRequest
|
||||
2, // 2: RagService.RAGService.CreateDocument:input_type -> CreateDocumentRequest
|
||||
3, // 3: RagService.RAGService.ListDocument:input_type -> ListDocumentRequest
|
||||
4, // 4: RagService.RAGService.ListLibrary:output_type -> ListLibraryResponse
|
||||
5, // 5: RagService.RAGService.CreateLibrary:output_type -> CreateLibraryResponse
|
||||
3, // [3:6] is the sub-list for method output_type
|
||||
0, // [0:3] is the sub-list for method input_type
|
||||
6, // 6: RagService.RAGService.CreateDocument:output_type -> CreateDocumentResponse
|
||||
7, // 7: RagService.RAGService.ListDocument:output_type -> ListDocumentResponse
|
||||
4, // [4:8] is the sub-list for method output_type
|
||||
0, // [0:4] is the sub-list for method input_type
|
||||
0, // [0:0] is the sub-list for extension type_name
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
|
@ -31,42 +31,6 @@ var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = metadata.Join
|
||||
|
||||
var (
|
||||
filter_RAGService_CreateDocument_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_RAGService_CreateDocument_0(ctx context.Context, marshaler runtime.Marshaler, client RAGServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_CreateDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.CreateDocument(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_RAGService_CreateDocument_0(ctx context.Context, marshaler runtime.Marshaler, server RAGServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_CreateDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.CreateDocument(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_RAGService_ListLibrary_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
@ -139,37 +103,84 @@ func local_request_RAGService_CreateLibrary_0(ctx context.Context, marshaler run
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_RAGService_CreateDocument_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_RAGService_CreateDocument_0(ctx context.Context, marshaler runtime.Marshaler, client RAGServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_CreateDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.CreateDocument(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_RAGService_CreateDocument_0(ctx context.Context, marshaler runtime.Marshaler, server RAGServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq CreateDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_CreateDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.CreateDocument(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_RAGService_ListDocument_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_RAGService_ListDocument_0(ctx context.Context, marshaler runtime.Marshaler, client RAGServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_ListDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ListDocument(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_RAGService_ListDocument_0(ctx context.Context, marshaler runtime.Marshaler, server RAGServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListDocumentRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_RAGService_ListDocument_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ListDocument(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterRAGServiceHandlerServer registers the http handlers for service RAGService to "mux".
|
||||
// UnaryRPC :call RAGServiceServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterRAGServiceHandlerFromEndpoint instead.
|
||||
func RegisterRAGServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server RAGServiceServer) error {
|
||||
|
||||
mux.Handle("POST", pattern_RAGService_CreateDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/RagService.RAGService/CreateDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_RAGService_CreateDocument_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_CreateDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_RAGService_ListLibrary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@ -220,6 +231,56 @@ func RegisterRAGServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_RAGService_CreateDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/RagService.RAGService/CreateDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_RAGService_CreateDocument_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_CreateDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_RAGService_ListDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/RagService.RAGService/ListDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_RAGService_ListDocument_0(annotatedContext, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_ListDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -261,28 +322,6 @@ func RegisterRAGServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn
|
||||
// "RAGServiceClient" to call the correct interceptors.
|
||||
func RegisterRAGServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client RAGServiceClient) error {
|
||||
|
||||
mux.Handle("POST", pattern_RAGService_CreateDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/RagService.RAGService/CreateDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_RAGService_CreateDocument_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_CreateDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_RAGService_ListLibrary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
@ -327,21 +366,69 @@ func RegisterRAGServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_RAGService_CreateDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/RagService.RAGService/CreateDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_RAGService_CreateDocument_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_CreateDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_RAGService_ListDocument_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
var err error
|
||||
var annotatedContext context.Context
|
||||
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/RagService.RAGService/ListDocument", runtime.WithHTTPPathPattern("/api/v1/documents"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_RAGService_ListDocument_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_RAGService_ListDocument_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_RAGService_CreateDocument_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "documents"}, ""))
|
||||
|
||||
pattern_RAGService_ListLibrary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "libraries"}, ""))
|
||||
|
||||
pattern_RAGService_CreateLibrary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "libraries"}, ""))
|
||||
|
||||
pattern_RAGService_CreateDocument_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "documents"}, ""))
|
||||
|
||||
pattern_RAGService_ListDocument_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "documents"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_RAGService_CreateDocument_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_RAGService_ListLibrary_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_RAGService_CreateLibrary_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_RAGService_CreateDocument_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_RAGService_ListDocument_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
@ -12,12 +12,6 @@ import "api/rag/library.proto";
|
||||
|
||||
|
||||
service RAGService {
|
||||
rpc CreateDocument(CreateDocumentRequest) returns (CreateDocumentResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v1/documents"
|
||||
};
|
||||
}
|
||||
|
||||
rpc ListLibrary(ListLibraryRequest) returns (ListLibraryResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/v1/libraries"
|
||||
@ -29,5 +23,19 @@ service RAGService {
|
||||
post: "/api/v1/libraries"
|
||||
};
|
||||
}
|
||||
|
||||
// DocumentService
|
||||
rpc CreateDocument(CreateDocumentRequest) returns (CreateDocumentResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/api/v1/documents"
|
||||
};
|
||||
}
|
||||
|
||||
rpc ListDocument(ListDocumentRequest) returns (ListDocumentResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/v1/documents"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,36 @@
|
||||
],
|
||||
"paths": {
|
||||
"/api/v1/documents": {
|
||||
"get": {
|
||||
"operationId": "RAGService_ListDocument",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ListDocumentResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "libraryId",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"RAGService"
|
||||
]
|
||||
},
|
||||
"post": {
|
||||
"summary": "DocumentService",
|
||||
"operationId": "RAGService_CreateDocument",
|
||||
"responses": {
|
||||
"200": {
|
||||
@ -151,6 +180,9 @@
|
||||
"libraryId": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
@ -181,6 +213,18 @@
|
||||
},
|
||||
"title": "import \"google.golang.org/grpc/health/grpc_health_v1\";"
|
||||
},
|
||||
"ListDocumentResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"documents": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/Document"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ListLibraryResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -22,9 +22,11 @@ const _ = grpc.SupportPackageIsVersion7
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type RAGServiceClient interface {
|
||||
CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error)
|
||||
ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error)
|
||||
CreateLibrary(ctx context.Context, in *CreateLibraryRequest, opts ...grpc.CallOption) (*CreateLibraryResponse, error)
|
||||
// DocumentService
|
||||
CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error)
|
||||
ListDocument(ctx context.Context, in *ListDocumentRequest, opts ...grpc.CallOption) (*ListDocumentResponse, error)
|
||||
}
|
||||
|
||||
type rAGServiceClient struct {
|
||||
@ -35,15 +37,6 @@ func NewRAGServiceClient(cc grpc.ClientConnInterface) RAGServiceClient {
|
||||
return &rAGServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *rAGServiceClient) CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error) {
|
||||
out := new(CreateDocumentResponse)
|
||||
err := c.cc.Invoke(ctx, "/RagService.RAGService/CreateDocument", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *rAGServiceClient) ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error) {
|
||||
out := new(ListLibraryResponse)
|
||||
err := c.cc.Invoke(ctx, "/RagService.RAGService/ListLibrary", in, out, opts...)
|
||||
@ -62,13 +55,33 @@ func (c *rAGServiceClient) CreateLibrary(ctx context.Context, in *CreateLibraryR
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *rAGServiceClient) CreateDocument(ctx context.Context, in *CreateDocumentRequest, opts ...grpc.CallOption) (*CreateDocumentResponse, error) {
|
||||
out := new(CreateDocumentResponse)
|
||||
err := c.cc.Invoke(ctx, "/RagService.RAGService/CreateDocument", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *rAGServiceClient) ListDocument(ctx context.Context, in *ListDocumentRequest, opts ...grpc.CallOption) (*ListDocumentResponse, error) {
|
||||
out := new(ListDocumentResponse)
|
||||
err := c.cc.Invoke(ctx, "/RagService.RAGService/ListDocument", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RAGServiceServer is the server API for RAGService service.
|
||||
// All implementations must embed UnimplementedRAGServiceServer
|
||||
// for forward compatibility
|
||||
type RAGServiceServer interface {
|
||||
CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error)
|
||||
ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error)
|
||||
CreateLibrary(context.Context, *CreateLibraryRequest) (*CreateLibraryResponse, error)
|
||||
// DocumentService
|
||||
CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error)
|
||||
ListDocument(context.Context, *ListDocumentRequest) (*ListDocumentResponse, error)
|
||||
mustEmbedUnimplementedRAGServiceServer()
|
||||
}
|
||||
|
||||
@ -76,15 +89,18 @@ type RAGServiceServer interface {
|
||||
type UnimplementedRAGServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedRAGServiceServer) CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateDocument not implemented")
|
||||
}
|
||||
func (UnimplementedRAGServiceServer) ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListLibrary not implemented")
|
||||
}
|
||||
func (UnimplementedRAGServiceServer) CreateLibrary(context.Context, *CreateLibraryRequest) (*CreateLibraryResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateLibrary not implemented")
|
||||
}
|
||||
func (UnimplementedRAGServiceServer) CreateDocument(context.Context, *CreateDocumentRequest) (*CreateDocumentResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateDocument not implemented")
|
||||
}
|
||||
func (UnimplementedRAGServiceServer) ListDocument(context.Context, *ListDocumentRequest) (*ListDocumentResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListDocument not implemented")
|
||||
}
|
||||
func (UnimplementedRAGServiceServer) mustEmbedUnimplementedRAGServiceServer() {}
|
||||
|
||||
// UnsafeRAGServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
@ -98,24 +114,6 @@ func RegisterRAGServiceServer(s grpc.ServiceRegistrar, srv RAGServiceServer) {
|
||||
s.RegisterService(&RAGService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _RAGService_CreateDocument_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateDocumentRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RAGServiceServer).CreateDocument(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/RagService.RAGService/CreateDocument",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RAGServiceServer).CreateDocument(ctx, req.(*CreateDocumentRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _RAGService_ListLibrary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListLibraryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@ -152,6 +150,42 @@ func _RAGService_CreateLibrary_Handler(srv interface{}, ctx context.Context, dec
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _RAGService_CreateDocument_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateDocumentRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RAGServiceServer).CreateDocument(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/RagService.RAGService/CreateDocument",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RAGServiceServer).CreateDocument(ctx, req.(*CreateDocumentRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _RAGService_ListDocument_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListDocumentRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RAGServiceServer).ListDocument(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/RagService.RAGService/ListDocument",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RAGServiceServer).ListDocument(ctx, req.(*ListDocumentRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// RAGService_ServiceDesc is the grpc.ServiceDesc for RAGService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@ -159,10 +193,6 @@ var RAGService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "RagService.RAGService",
|
||||
HandlerType: (*RAGServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateDocument",
|
||||
Handler: _RAGService_CreateDocument_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListLibrary",
|
||||
Handler: _RAGService_ListLibrary_Handler,
|
||||
@ -171,6 +201,14 @@ var RAGService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "CreateLibrary",
|
||||
Handler: _RAGService_CreateLibrary_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateDocument",
|
||||
Handler: _RAGService_CreateDocument_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListDocument",
|
||||
Handler: _RAGService_ListDocument_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "api/rag/rag.proto",
|
||||
|
4
buf.lock
4
buf.lock
@ -4,5 +4,5 @@ deps:
|
||||
- remote: buf.build
|
||||
owner: googleapis
|
||||
repository: googleapis
|
||||
commit: f0e53af8f2fc4556b94f482688b57223
|
||||
digest: shake256:de26a277fc28b8b411ecf58729d78d32fcf15090ffd998a4469225b17889bfb51442eaab04bb7a8d88d203ecdf0a9febd4ffd52c18ed1c2229160c7bd353ca95
|
||||
commit: 2bbd25900cb34c79bae97d85c948d3cf
|
||||
digest: shake256:a6446e23f4408160217c22738a0c8c370ff3ff966f601d678960b803829cf53b5cf5998d20fcb3f9c9be944b24337843e7beb6e681ddbf9d036fb6491c0e47e7
|
||||
|
309
ent/client.go
309
ent/client.go
@ -14,6 +14,9 @@ import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"leafdev.top/leaf/rag/ent/document"
|
||||
"leafdev.top/leaf/rag/ent/documentblock"
|
||||
"leafdev.top/leaf/rag/ent/library"
|
||||
)
|
||||
|
||||
@ -22,6 +25,10 @@ type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Document is the client for interacting with the Document builders.
|
||||
Document *DocumentClient
|
||||
// DocumentBlock is the client for interacting with the DocumentBlock builders.
|
||||
DocumentBlock *DocumentBlockClient
|
||||
// Library is the client for interacting with the Library builders.
|
||||
Library *LibraryClient
|
||||
}
|
||||
@ -35,6 +42,8 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Document = NewDocumentClient(c.config)
|
||||
c.DocumentBlock = NewDocumentBlockClient(c.config)
|
||||
c.Library = NewLibraryClient(c.config)
|
||||
}
|
||||
|
||||
@ -128,6 +137,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Document: NewDocumentClient(cfg),
|
||||
DocumentBlock: NewDocumentBlockClient(cfg),
|
||||
Library: NewLibraryClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@ -148,6 +159,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Document: NewDocumentClient(cfg),
|
||||
DocumentBlock: NewDocumentBlockClient(cfg),
|
||||
Library: NewLibraryClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@ -155,7 +168,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Library.
|
||||
// Document.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@ -177,18 +190,26 @@ func (c *Client) Close() error {
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.Document.Use(hooks...)
|
||||
c.DocumentBlock.Use(hooks...)
|
||||
c.Library.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.Document.Intercept(interceptors...)
|
||||
c.DocumentBlock.Intercept(interceptors...)
|
||||
c.Library.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *DocumentMutation:
|
||||
return c.Document.mutate(ctx, m)
|
||||
case *DocumentBlockMutation:
|
||||
return c.DocumentBlock.mutate(ctx, m)
|
||||
case *LibraryMutation:
|
||||
return c.Library.mutate(ctx, m)
|
||||
default:
|
||||
@ -196,6 +217,288 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// DocumentClient is a client for the Document schema.
|
||||
type DocumentClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewDocumentClient returns a client for the Document from the given config.
|
||||
func NewDocumentClient(c config) *DocumentClient {
|
||||
return &DocumentClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `document.Hooks(f(g(h())))`.
|
||||
func (c *DocumentClient) Use(hooks ...Hook) {
|
||||
c.hooks.Document = append(c.hooks.Document, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `document.Intercept(f(g(h())))`.
|
||||
func (c *DocumentClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Document = append(c.inters.Document, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Document entity.
|
||||
func (c *DocumentClient) Create() *DocumentCreate {
|
||||
mutation := newDocumentMutation(c.config, OpCreate)
|
||||
return &DocumentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Document entities.
|
||||
func (c *DocumentClient) CreateBulk(builders ...*DocumentCreate) *DocumentCreateBulk {
|
||||
return &DocumentCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *DocumentClient) MapCreateBulk(slice any, setFunc func(*DocumentCreate, int)) *DocumentCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &DocumentCreateBulk{err: fmt.Errorf("calling to DocumentClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*DocumentCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &DocumentCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Document.
|
||||
func (c *DocumentClient) Update() *DocumentUpdate {
|
||||
mutation := newDocumentMutation(c.config, OpUpdate)
|
||||
return &DocumentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *DocumentClient) UpdateOne(d *Document) *DocumentUpdateOne {
|
||||
mutation := newDocumentMutation(c.config, OpUpdateOne, withDocument(d))
|
||||
return &DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *DocumentClient) UpdateOneID(id int) *DocumentUpdateOne {
|
||||
mutation := newDocumentMutation(c.config, OpUpdateOne, withDocumentID(id))
|
||||
return &DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Document.
|
||||
func (c *DocumentClient) Delete() *DocumentDelete {
|
||||
mutation := newDocumentMutation(c.config, OpDelete)
|
||||
return &DocumentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *DocumentClient) DeleteOne(d *Document) *DocumentDeleteOne {
|
||||
return c.DeleteOneID(d.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DocumentClient) DeleteOneID(id int) *DocumentDeleteOne {
|
||||
builder := c.Delete().Where(document.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &DocumentDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Document.
|
||||
func (c *DocumentClient) Query() *DocumentQuery {
|
||||
return &DocumentQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeDocument},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Document entity by its id.
|
||||
func (c *DocumentClient) Get(ctx context.Context, id int) (*Document, error) {
|
||||
return c.Query().Where(document.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *DocumentClient) GetX(ctx context.Context, id int) *Document {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *DocumentClient) Hooks() []Hook {
|
||||
return c.hooks.Document
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *DocumentClient) Interceptors() []Interceptor {
|
||||
return c.inters.Document
|
||||
}
|
||||
|
||||
func (c *DocumentClient) mutate(ctx context.Context, m *DocumentMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&DocumentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&DocumentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&DocumentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&DocumentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Document mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// DocumentBlockClient is a client for the DocumentBlock schema.
|
||||
type DocumentBlockClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewDocumentBlockClient returns a client for the DocumentBlock from the given config.
|
||||
func NewDocumentBlockClient(c config) *DocumentBlockClient {
|
||||
return &DocumentBlockClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `documentblock.Hooks(f(g(h())))`.
|
||||
func (c *DocumentBlockClient) Use(hooks ...Hook) {
|
||||
c.hooks.DocumentBlock = append(c.hooks.DocumentBlock, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `documentblock.Intercept(f(g(h())))`.
|
||||
func (c *DocumentBlockClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.DocumentBlock = append(c.inters.DocumentBlock, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a DocumentBlock entity.
|
||||
func (c *DocumentBlockClient) Create() *DocumentBlockCreate {
|
||||
mutation := newDocumentBlockMutation(c.config, OpCreate)
|
||||
return &DocumentBlockCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of DocumentBlock entities.
|
||||
func (c *DocumentBlockClient) CreateBulk(builders ...*DocumentBlockCreate) *DocumentBlockCreateBulk {
|
||||
return &DocumentBlockCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *DocumentBlockClient) MapCreateBulk(slice any, setFunc func(*DocumentBlockCreate, int)) *DocumentBlockCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &DocumentBlockCreateBulk{err: fmt.Errorf("calling to DocumentBlockClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*DocumentBlockCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &DocumentBlockCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for DocumentBlock.
|
||||
func (c *DocumentBlockClient) Update() *DocumentBlockUpdate {
|
||||
mutation := newDocumentBlockMutation(c.config, OpUpdate)
|
||||
return &DocumentBlockUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *DocumentBlockClient) UpdateOne(db *DocumentBlock) *DocumentBlockUpdateOne {
|
||||
mutation := newDocumentBlockMutation(c.config, OpUpdateOne, withDocumentBlock(db))
|
||||
return &DocumentBlockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *DocumentBlockClient) UpdateOneID(id int) *DocumentBlockUpdateOne {
|
||||
mutation := newDocumentBlockMutation(c.config, OpUpdateOne, withDocumentBlockID(id))
|
||||
return &DocumentBlockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for DocumentBlock.
|
||||
func (c *DocumentBlockClient) Delete() *DocumentBlockDelete {
|
||||
mutation := newDocumentBlockMutation(c.config, OpDelete)
|
||||
return &DocumentBlockDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *DocumentBlockClient) DeleteOne(db *DocumentBlock) *DocumentBlockDeleteOne {
|
||||
return c.DeleteOneID(db.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DocumentBlockClient) DeleteOneID(id int) *DocumentBlockDeleteOne {
|
||||
builder := c.Delete().Where(documentblock.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &DocumentBlockDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for DocumentBlock.
|
||||
func (c *DocumentBlockClient) Query() *DocumentBlockQuery {
|
||||
return &DocumentBlockQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeDocumentBlock},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a DocumentBlock entity by its id.
|
||||
func (c *DocumentBlockClient) Get(ctx context.Context, id int) (*DocumentBlock, error) {
|
||||
return c.Query().Where(documentblock.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *DocumentBlockClient) GetX(ctx context.Context, id int) *DocumentBlock {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryDocument queries the document edge of a DocumentBlock.
|
||||
func (c *DocumentBlockClient) QueryDocument(db *DocumentBlock) *DocumentQuery {
|
||||
query := (&DocumentClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := db.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(documentblock.Table, documentblock.FieldID, id),
|
||||
sqlgraph.To(document.Table, document.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, documentblock.DocumentTable, documentblock.DocumentColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(db.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *DocumentBlockClient) Hooks() []Hook {
|
||||
return c.hooks.DocumentBlock
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *DocumentBlockClient) Interceptors() []Interceptor {
|
||||
return c.inters.DocumentBlock
|
||||
}
|
||||
|
||||
func (c *DocumentBlockClient) mutate(ctx context.Context, m *DocumentBlockMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&DocumentBlockCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&DocumentBlockUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&DocumentBlockUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&DocumentBlockDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown DocumentBlock mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// LibraryClient is a client for the Library schema.
|
||||
type LibraryClient struct {
|
||||
config
|
||||
@ -332,9 +635,9 @@ func (c *LibraryClient) mutate(ctx context.Context, m *LibraryMutation) (Value,
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
Library []ent.Hook
|
||||
Document, DocumentBlock, Library []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Library []ent.Interceptor
|
||||
Document, DocumentBlock, Library []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
@ -12,6 +12,8 @@ import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"leafdev.top/leaf/rag/ent/document"
|
||||
"leafdev.top/leaf/rag/ent/documentblock"
|
||||
"leafdev.top/leaf/rag/ent/library"
|
||||
)
|
||||
|
||||
@ -73,6 +75,8 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
document.Table: document.ValidColumn,
|
||||
documentblock.Table: documentblock.ValidColumn,
|
||||
library.Table: library.ValidColumn,
|
||||
})
|
||||
})
|
||||
|
@ -9,6 +9,30 @@ import (
|
||||
"leafdev.top/leaf/rag/ent"
|
||||
)
|
||||
|
||||
// The DocumentFunc type is an adapter to allow the use of ordinary
|
||||
// function as Document mutator.
|
||||
type DocumentFunc func(context.Context, *ent.DocumentMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.DocumentMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentMutation", m)
|
||||
}
|
||||
|
||||
// The DocumentBlockFunc type is an adapter to allow the use of ordinary
|
||||
// function as DocumentBlock mutator.
|
||||
type DocumentBlockFunc func(context.Context, *ent.DocumentBlockMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f DocumentBlockFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.DocumentBlockMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentBlockMutation", m)
|
||||
}
|
||||
|
||||
// The LibraryFunc type is an adapter to allow the use of ordinary
|
||||
// function as Library mutator.
|
||||
type LibraryFunc func(context.Context, *ent.LibraryMutation) (ent.Value, error)
|
||||
|
@ -8,6 +8,60 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// DocumentsColumns holds the columns for the "documents" table.
|
||||
DocumentsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "user_id", Type: field.TypeString},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "document_block_document", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// DocumentsTable holds the schema information for the "documents" table.
|
||||
DocumentsTable = &schema.Table{
|
||||
Name: "documents",
|
||||
Columns: DocumentsColumns,
|
||||
PrimaryKey: []*schema.Column{DocumentsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "documents_document_blocks_document",
|
||||
Columns: []*schema.Column{DocumentsColumns[5]},
|
||||
RefColumns: []*schema.Column{DocumentBlocksColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "document_name_user_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DocumentsColumns[1], DocumentsColumns[2]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// DocumentBlocksColumns holds the columns for the "document_blocks" table.
|
||||
DocumentBlocksColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString},
|
||||
{Name: "content", Type: field.TypeString},
|
||||
{Name: "order", Type: field.TypeInt},
|
||||
{Name: "document_id", Type: field.TypeInt},
|
||||
{Name: "user_id", Type: field.TypeString},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
}
|
||||
// DocumentBlocksTable holds the schema information for the "document_blocks" table.
|
||||
DocumentBlocksTable = &schema.Table{
|
||||
Name: "document_blocks",
|
||||
Columns: DocumentBlocksColumns,
|
||||
PrimaryKey: []*schema.Column{DocumentBlocksColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "documentblock_name_user_id_order",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{DocumentBlocksColumns[1], DocumentBlocksColumns[5], DocumentBlocksColumns[3]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// LibrariesColumns holds the columns for the "libraries" table.
|
||||
LibrariesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@ -31,9 +85,12 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
DocumentsTable,
|
||||
DocumentBlocksTable,
|
||||
LibrariesTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
DocumentsTable.ForeignKeys[0].RefTable = DocumentBlocksTable
|
||||
}
|
||||
|
1304
ent/mutation.go
1304
ent/mutation.go
File diff suppressed because it is too large
Load Diff
@ -6,5 +6,11 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Document is the predicate function for document builders.
|
||||
type Document func(*sql.Selector)
|
||||
|
||||
// DocumentBlock is the predicate function for documentblock builders.
|
||||
type DocumentBlock func(*sql.Selector)
|
||||
|
||||
// Library is the predicate function for library builders.
|
||||
type Library func(*sql.Selector)
|
||||
|
@ -5,6 +5,8 @@ package ent
|
||||
import (
|
||||
"time"
|
||||
|
||||
"leafdev.top/leaf/rag/ent/document"
|
||||
"leafdev.top/leaf/rag/ent/documentblock"
|
||||
"leafdev.top/leaf/rag/ent/library"
|
||||
"leafdev.top/leaf/rag/ent/schema"
|
||||
)
|
||||
@ -13,6 +15,26 @@ import (
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
documentFields := schema.Document{}.Fields()
|
||||
_ = documentFields
|
||||
// documentDescCreatedAt is the schema descriptor for created_at field.
|
||||
documentDescCreatedAt := documentFields[2].Descriptor()
|
||||
// document.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
document.DefaultCreatedAt = documentDescCreatedAt.Default.(func() time.Time)
|
||||
// documentDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
documentDescUpdatedAt := documentFields[3].Descriptor()
|
||||
// document.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
document.DefaultUpdatedAt = documentDescUpdatedAt.Default.(func() time.Time)
|
||||
documentblockFields := schema.DocumentBlock{}.Fields()
|
||||
_ = documentblockFields
|
||||
// documentblockDescCreatedAt is the schema descriptor for created_at field.
|
||||
documentblockDescCreatedAt := documentblockFields[5].Descriptor()
|
||||
// documentblock.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
documentblock.DefaultCreatedAt = documentblockDescCreatedAt.Default.(func() time.Time)
|
||||
// documentblockDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
documentblockDescUpdatedAt := documentblockFields[6].Descriptor()
|
||||
// documentblock.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
documentblock.DefaultUpdatedAt = documentblockDescUpdatedAt.Default.(func() time.Time)
|
||||
libraryFields := schema.Library{}.Fields()
|
||||
_ = libraryFields
|
||||
// libraryDescCreatedAt is the schema descriptor for created_at field.
|
||||
|
@ -12,6 +12,10 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Document is the client for interacting with the Document builders.
|
||||
Document *DocumentClient
|
||||
// DocumentBlock is the client for interacting with the DocumentBlock builders.
|
||||
DocumentBlock *DocumentBlockClient
|
||||
// Library is the client for interacting with the Library builders.
|
||||
Library *LibraryClient
|
||||
|
||||
@ -145,6 +149,8 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Document = NewDocumentClient(tx.config)
|
||||
tx.DocumentBlock = NewDocumentBlockClient(tx.config)
|
||||
tx.Library = NewLibraryClient(tx.config)
|
||||
}
|
||||
|
||||
@ -155,7 +161,7 @@ func (tx *Tx) init() {
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Library.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: Document.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
@ -1 +1,8 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"leafdev.top/leaf/rag/ent"
|
||||
"leafdev.top/leaf/rag/internal/providers"
|
||||
)
|
||||
|
||||
var orm = providers.MustGet[ent.Client]()
|
||||
|
25
internal/logic/document.go
Normal file
25
internal/logic/document.go
Normal file
@ -0,0 +1,25 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"leafdev.top/leaf/rag/ent"
|
||||
"leafdev.top/leaf/rag/ent/document"
|
||||
)
|
||||
|
||||
type DocumentLogic struct {
|
||||
}
|
||||
|
||||
func NewDocumentLogic() *DocumentLogic {
|
||||
return &DocumentLogic{}
|
||||
}
|
||||
|
||||
func (DocumentLogic) ListDocument(ctx context.Context) ([]*ent.Document, error) {
|
||||
return orm.Document.Query().Where(document.UserIDEQ(GetUserId(ctx))).All(ctx)
|
||||
}
|
||||
|
||||
func (DocumentLogic) CreateDocument(ctx context.Context, name string) (*ent.Document, error) {
|
||||
return orm.Document.Create().
|
||||
SetName(name).
|
||||
SetUserID(GetUserId(ctx)).
|
||||
Save(ctx)
|
||||
}
|
@ -5,20 +5,17 @@ import (
|
||||
"errors"
|
||||
"leafdev.top/leaf/rag/ent"
|
||||
"leafdev.top/leaf/rag/ent/library"
|
||||
"leafdev.top/leaf/rag/internal/providers"
|
||||
)
|
||||
|
||||
type LibraryLogic struct {
|
||||
}
|
||||
|
||||
var client = providers.MustGet[ent.Client]()
|
||||
|
||||
func NewLibraryLogic() *LibraryLogic {
|
||||
return &LibraryLogic{}
|
||||
}
|
||||
|
||||
func (l *LibraryLogic) ListLibrary(ctx context.Context) ([]*ent.Library, error) {
|
||||
return client.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
|
||||
return orm.Library.Query().Where(library.UserID(GetUserId(ctx))).All(ctx)
|
||||
}
|
||||
|
||||
func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Library, error) {
|
||||
@ -27,7 +24,7 @@ func (l *LibraryLogic) CreateLibrary(ctx context.Context, name string) (*ent.Lib
|
||||
return nil, errors.New("名称不能为空")
|
||||
}
|
||||
|
||||
return client.Library.Create().
|
||||
return orm.Library.Create().
|
||||
SetName(name).
|
||||
SetUserID(GetUserId(ctx)).
|
||||
Save(ctx)
|
||||
|
@ -56,3 +56,11 @@ func JwtAuth(ctx context.Context) (context.Context, error) {
|
||||
|
||||
return context.WithValue(ctx, consts.AuthMiddlewareKey, &jwtIdToken), nil
|
||||
}
|
||||
|
||||
func Gate(ctx context.Context) (context.Context, error) {
|
||||
// 检查调用的方法
|
||||
|
||||
//
|
||||
|
||||
return ctx, nil
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
h1:gAvB+J97CWicumiwquwzeenMmWbnkb2SkIa7TZ9+r2w=
|
||||
20240714155720_create_library.sql h1:JzdeQPcsm2609MV/6DbYu5N7tg583qpxoaXgFtazOzE=
|
||||
20240714164619_update_user_id.sql h1:YiqNbf8FcKJCH9cj3PIFqOtr/pqzLKJgXza8nw8iO/w=
|
||||
h1:sLEQ6Lxd6zOalx8i43YLFGrjyKJrnXXnj8KDE/eqF3A=
|
||||
20240714155720_create_library.sql h1:nfzvzMxwqJRhmvUQSnXcK/LZDyAfy/vnjx7ZD2vY3AU=
|
||||
20240714164619_update_user_id.sql h1:AUCFOY9OVkR4W/sFc7Ipb5Cz3xR4gY61jDuTN4MN7w8=
|
||||
20240720092815_add_documents_tables.sql h1:S0OeUzCLWqXtA1Wi2Wvmlj/2eg2Kl0NkPNRy7Mu+2MY=
|
||||
20240720093157_add_order_to_document_blocks.sql h1:6CHgxARw5yXmXfHTzFFPxqZZ8bWl3g76KHXlB3XYeLQ=
|
||||
|
@ -1,4 +1,47 @@
|
||||
package rag
|
||||
|
||||
type DocumentService struct {
|
||||
import (
|
||||
"context"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
ragApi "leafdev.top/leaf/rag/api/rag"
|
||||
)
|
||||
|
||||
func (Service) ListDocument(ctx context.Context, req *ragApi.ListDocumentRequest) (*ragApi.ListDocumentResponse, error) {
|
||||
document, err := documentLogic.ListDocument(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var documentApiResponse ragApi.ListDocumentResponse
|
||||
for _, document := range document {
|
||||
var documentApiResponseItem = ragApi.Document{
|
||||
Id: int64(document.ID),
|
||||
Name: document.Name,
|
||||
UserId: document.UserID,
|
||||
CreatedAt: document.CreatedAt.String(),
|
||||
UpdatedAt: document.UpdatedAt.String(),
|
||||
}
|
||||
documentApiResponse.Documents = append(documentApiResponse.Documents, &documentApiResponseItem)
|
||||
}
|
||||
|
||||
return &documentApiResponse, nil
|
||||
}
|
||||
|
||||
func (Service) CreateDocument(ctx context.Context, req *ragApi.CreateDocumentRequest) (*ragApi.CreateDocumentResponse, error) {
|
||||
document, err := documentLogic.CreateDocument(ctx, req.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var documentApiResponse ragApi.CreateDocumentResponse
|
||||
err = mapstructure.Decode(document, &documentApiResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &documentApiResponse, nil
|
||||
}
|
||||
|
||||
//func (Service) UpdateDocument(ctx context.Context, _ *ragApi.UpdateDocumentRequest) (*ragApi.UpdateDocumentResponse, error) {
|
||||
// panic("implement me")
|
||||
//}
|
||||
|
@ -4,11 +4,8 @@ import (
|
||||
"context"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
ragApi "leafdev.top/leaf/rag/api/rag"
|
||||
"leafdev.top/leaf/rag/internal/logic"
|
||||
)
|
||||
|
||||
var libraryLogic = logic.NewLibraryLogic()
|
||||
|
||||
func (Service) ListLibrary(ctx context.Context, _ *ragApi.ListLibraryRequest) (*ragApi.ListLibraryResponse, error) {
|
||||
libraries, err := libraryLogic.ListLibrary(ctx)
|
||||
if err != nil {
|
||||
|
@ -1,6 +1,12 @@
|
||||
package rag
|
||||
|
||||
import ragApi "leafdev.top/leaf/rag/api/rag"
|
||||
import (
|
||||
ragApi "leafdev.top/leaf/rag/api/rag"
|
||||
"leafdev.top/leaf/rag/internal/logic"
|
||||
)
|
||||
|
||||
var libraryLogic = logic.NewLibraryLogic()
|
||||
var documentLogic = logic.NewDocumentLogic()
|
||||
|
||||
type Service struct {
|
||||
ragApi.UnimplementedRAGServiceServer
|
||||
|
Loading…
Reference in New Issue
Block a user