@@ -6,115 +6,116 @@ import (
6
6
"github.com/go-skynet/LocalAI/core/schema"
7
7
"github.com/go-skynet/LocalAI/pkg/store"
8
8
"github.com/gofiber/fiber/v2"
9
+ "github.com/rs/zerolog/log"
9
10
)
10
11
11
- func StoresSetEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
12
- return func (c * fiber.Ctx ) error {
13
- input := new (schema.StoresSet )
14
-
15
- if err := c .BodyParser (input ); err != nil {
16
- return err
17
- }
18
-
19
- sb , err := backend .StoreBackend (sl , appConfig , input .Store )
20
- if err != nil {
21
- return err
22
- }
23
-
24
- vals := make ([][]byte , len (input .Values ))
25
- for i , v := range input .Values {
26
- vals [i ] = []byte (v )
27
- }
28
-
29
- err = store .SetCols (c .Context (), sb , input .Keys , vals )
30
- if err != nil {
31
- return err
32
- }
33
-
34
- return c .Send (nil )
35
- }
12
+ func StoresSetEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
13
+ return func (c * fiber.Ctx ) error {
14
+ input := new (schema.StoresSet )
15
+
16
+ if err := c .BodyParser (input ); err != nil {
17
+ return err
18
+ }
19
+
20
+ sb , err := backend .StoreBackend (sl , appConfig , input .Store )
21
+ if err != nil {
22
+ return err
23
+ }
24
+
25
+ vals := make ([][]byte , len (input .Values ))
26
+ for i , v := range input .Values {
27
+ vals [i ] = []byte (v )
28
+ }
29
+
30
+ err = store .SetCols (c .Context (), sb , input .Keys , vals )
31
+ if err != nil {
32
+ return err
33
+ }
34
+
35
+ return c .Send (nil )
36
+ }
36
37
}
37
38
38
- func StoresDeleteEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
39
- return func (c * fiber.Ctx ) error {
40
- input := new (schema.StoresDelete )
41
-
42
- if err := c .BodyParser (input ); err != nil {
43
- return err
44
- }
45
-
46
- sb , err := backend .StoreBackend (sl , appConfig , input .Store )
47
- if err != nil {
48
- return err
49
- }
50
-
51
- if err := store .DeleteCols (c .Context (), sb , input .Keys ); err != nil {
52
- return err
53
- }
54
-
55
- return c .Send (nil )
56
- }
39
+ func StoresDeleteEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
40
+ return func (c * fiber.Ctx ) error {
41
+ input := new (schema.StoresDelete )
42
+
43
+ if err := c .BodyParser (input ); err != nil {
44
+ return err
45
+ }
46
+
47
+ sb , err := backend .StoreBackend (sl , appConfig , input .Store )
48
+ if err != nil {
49
+ return err
50
+ }
51
+
52
+ if err := store .DeleteCols (c .Context (), sb , input .Keys ); err != nil {
53
+ return err
54
+ }
55
+
56
+ return c .Send (nil )
57
+ }
57
58
}
58
59
59
- func StoresGetEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
60
- return func (c * fiber.Ctx ) error {
61
- input := new (schema.StoresGet )
60
+ func StoresGetEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
61
+ return func (c * fiber.Ctx ) error {
62
+ input := new (schema.StoresGet )
62
63
63
- if err := c .BodyParser (input ); err != nil {
64
- return err
65
- }
64
+ if err := c .BodyParser (input ); err != nil {
65
+ return err
66
+ }
66
67
67
- sb , err := backend .StoreBackend (sl , appConfig , input .Store )
68
- if err != nil {
69
- return err
70
- }
68
+ sb , err := backend .StoreBackend (sl , appConfig , input .Store )
69
+ if err != nil {
70
+ return err
71
+ }
71
72
72
- keys , vals , err := store .GetCols (c .Context (), sb , input .Keys )
73
- if err != nil {
74
- return err
75
- }
73
+ keys , vals , err := store .GetCols (c .Context (), sb , input .Keys )
74
+ if err != nil {
75
+ return err
76
+ }
76
77
77
- res := schema.StoresGetResponse {
78
- Keys : keys ,
79
- Values : make ([]string , len (vals )),
80
- }
78
+ res := schema.StoresGetResponse {
79
+ Keys : keys ,
80
+ Values : make ([]string , len (vals )),
81
+ }
81
82
82
- for i , v := range vals {
83
- res .Values [i ] = string (v )
84
- }
83
+ for i , v := range vals {
84
+ res .Values [i ] = string (v )
85
+ }
85
86
86
- return c .JSON (res )
87
- }
87
+ return c .JSON (res )
88
+ }
88
89
}
89
90
90
- func StoresFindEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
91
- return func (c * fiber.Ctx ) error {
92
- input := new (schema.StoresFind )
91
+ func StoresFindEndpoint (sl * store.StoreLoader , appConfig * config.ApplicationConfig ) func (c * fiber.Ctx ) error {
92
+ return func (c * fiber.Ctx ) error {
93
+ input := new (schema.StoresFind )
93
94
94
- if err := c .BodyParser (input ); err != nil {
95
- return err
96
- }
95
+ if err := c .BodyParser (input ); err != nil {
96
+ return err
97
+ }
97
98
98
- sb , err := backend .StoreBackend (sl , appConfig , input .Store )
99
- if err != nil {
100
- return err
101
- }
99
+ sb , err := backend .StoreBackend (sl , appConfig , input .Store )
100
+ if err != nil {
101
+ return err
102
+ }
102
103
103
- keys , vals , similarities , err := store .Find (c .Context (), sb , input .Key , input .Topk )
104
- if err != nil {
105
- return err
106
- }
104
+ keys , vals , similarities , err := store .Find (c .Context (), sb , input .Key , input .Topk )
105
+ if err != nil {
106
+ return err
107
+ }
107
108
108
- res := schema.StoresFindResponse {
109
- Keys : keys ,
110
- Values : make ([]string , len (vals )),
111
- Similarities : similarities ,
112
- }
109
+ res := schema.StoresFindResponse {
110
+ Keys : keys ,
111
+ Values : make ([]string , len (vals )),
112
+ Similarities : similarities ,
113
+ }
113
114
114
- for i , v := range vals {
115
- res .Values [i ] = string (v )
116
- }
115
+ for i , v := range vals {
116
+ res .Values [i ] = string (v )
117
+ }
117
118
118
- return c .JSON (res )
119
- }
119
+ return c .JSON (res )
120
+ }
120
121
}
0 commit comments