Stevross commited on
Commit
cf57c77
1 Parent(s): 3d49dd4

Upload 18 files

Browse files
Files changed (17) hide show
  1. .dockerignore +2 -0
  2. .env +2 -0
  3. .gitignore +112 -0
  4. Cargo.lock +2330 -0
  5. Cargo.toml +24 -0
  6. Dockerfile +31 -0
  7. LICENSE +201 -0
  8. README.md +127 -10
  9. docker-compose.yml +21 -0
  10. src/healthcheck.rs +15 -0
  11. src/long_term_memory.rs +81 -0
  12. src/main.rs +122 -0
  13. src/memory.rs +248 -0
  14. src/models.rs +276 -0
  15. src/redis_utils.rs +46 -0
  16. src/reducer.rs +145 -0
  17. src/retrieval.rs +33 -0
.dockerignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ target/
2
+ .git/
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ OPENAI_API_KEY=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
2
+ REDIS_URL=
.gitignore ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+
9
+ # Diagnostic reports (https://nodejs.org/api/report.html)
10
+ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11
+
12
+ # Runtime data
13
+ pids
14
+ *.pid
15
+ *.seed
16
+ *.pid.lock
17
+
18
+ # Directory for instrumented libs generated by jscoverage/JSCover
19
+ lib-cov
20
+
21
+ # Coverage directory used by tools like istanbul
22
+ coverage
23
+ *.lcov
24
+
25
+ # nyc test coverage
26
+ .nyc_output
27
+
28
+ # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29
+ .grunt
30
+
31
+ # Bower dependency directory (https://bower.io/)
32
+ bower_components
33
+
34
+ # node-waf configuration
35
+ .lock-wscript
36
+
37
+ # Compiled binary addons (https://nodejs.org/api/addons.html)
38
+ build/Release
39
+
40
+ # Dependency directories
41
+ node_modules/
42
+ jspm_packages/
43
+
44
+ # TypeScript v1 declaration files
45
+ typings/
46
+
47
+ # TypeScript cache
48
+ *.tsbuildinfo
49
+
50
+ # Optional npm cache directory
51
+ .npm
52
+
53
+ # Optional eslint cache
54
+ .eslintcache
55
+
56
+ # Microbundle cache
57
+ .rpt2_cache/
58
+ .rts2_cache_cjs/
59
+ .rts2_cache_es/
60
+ .rts2_cache_umd/
61
+
62
+ # Optional REPL history
63
+ .node_repl_history
64
+
65
+ # Output of 'npm pack'
66
+ *.tgz
67
+
68
+ # Yarn Integrity file
69
+ .yarn-integrity
70
+
71
+ # dotenv environment variables file
72
+ .env
73
+ .env.test
74
+
75
+ # parcel-bundler cache (https://parceljs.org/)
76
+ .cache
77
+
78
+ # Next.js build output
79
+ .next
80
+
81
+ # Nuxt.js build / generate output
82
+ .nuxt
83
+ dist
84
+
85
+ # Gatsby files
86
+ .cache/
87
+ # Comment in the public line in if your project uses Gatsby and *not* Next.js
88
+ # https://nextjs.org/blog/next-9-1#public-directory-support
89
+ # public
90
+
91
+ # vuepress build output
92
+ .vuepress/dist
93
+
94
+ # Serverless directories
95
+ .serverless/
96
+
97
+ # FuseBox cache
98
+ .fusebox/
99
+
100
+ # DynamoDB Local files
101
+ .dynamodb/
102
+
103
+ # TernJS port file
104
+ .tern-port
105
+
106
+ .cert
107
+ .vscode
108
+
109
+
110
+ # Added by cargo
111
+
112
+ /target
Cargo.lock ADDED
@@ -0,0 +1,2330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "actix-codec"
7
+ version = "0.5.0"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "57a7559404a7f3573127aab53c08ce37a6c6a315c374a31070f3c91cd1b4a7fe"
10
+ dependencies = [
11
+ "bitflags",
12
+ "bytes",
13
+ "futures-core",
14
+ "futures-sink",
15
+ "log",
16
+ "memchr",
17
+ "pin-project-lite",
18
+ "tokio",
19
+ "tokio-util",
20
+ ]
21
+
22
+ [[package]]
23
+ name = "actix-http"
24
+ version = "3.3.1"
25
+ source = "registry+https://github.com/rust-lang/crates.io-index"
26
+ checksum = "c2079246596c18b4a33e274ae10c0e50613f4d32a4198e09c7b93771013fed74"
27
+ dependencies = [
28
+ "actix-codec",
29
+ "actix-rt",
30
+ "actix-service",
31
+ "actix-utils",
32
+ "ahash 0.8.3",
33
+ "base64",
34
+ "bitflags",
35
+ "brotli",
36
+ "bytes",
37
+ "bytestring",
38
+ "derive_more",
39
+ "encoding_rs",
40
+ "flate2",
41
+ "futures-core",
42
+ "h2",
43
+ "http",
44
+ "httparse",
45
+ "httpdate",
46
+ "itoa",
47
+ "language-tags",
48
+ "local-channel",
49
+ "mime",
50
+ "percent-encoding",
51
+ "pin-project-lite",
52
+ "rand",
53
+ "sha1",
54
+ "smallvec",
55
+ "tokio",
56
+ "tokio-util",
57
+ "tracing",
58
+ "zstd",
59
+ ]
60
+
61
+ [[package]]
62
+ name = "actix-macros"
63
+ version = "0.2.3"
64
+ source = "registry+https://github.com/rust-lang/crates.io-index"
65
+ checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
66
+ dependencies = [
67
+ "quote",
68
+ "syn 1.0.109",
69
+ ]
70
+
71
+ [[package]]
72
+ name = "actix-router"
73
+ version = "0.5.1"
74
+ source = "registry+https://github.com/rust-lang/crates.io-index"
75
+ checksum = "d66ff4d247d2b160861fa2866457e85706833527840e4133f8f49aa423a38799"
76
+ dependencies = [
77
+ "bytestring",
78
+ "http",
79
+ "regex",
80
+ "serde",
81
+ "tracing",
82
+ ]
83
+
84
+ [[package]]
85
+ name = "actix-rt"
86
+ version = "2.8.0"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "15265b6b8e2347670eb363c47fc8c75208b4a4994b27192f345fcbe707804f3e"
89
+ dependencies = [
90
+ "futures-core",
91
+ "tokio",
92
+ ]
93
+
94
+ [[package]]
95
+ name = "actix-server"
96
+ version = "2.2.0"
97
+ source = "registry+https://github.com/rust-lang/crates.io-index"
98
+ checksum = "3e8613a75dd50cc45f473cee3c34d59ed677c0f7b44480ce3b8247d7dc519327"
99
+ dependencies = [
100
+ "actix-rt",
101
+ "actix-service",
102
+ "actix-utils",
103
+ "futures-core",
104
+ "futures-util",
105
+ "mio",
106
+ "num_cpus",
107
+ "socket2",
108
+ "tokio",
109
+ "tracing",
110
+ ]
111
+
112
+ [[package]]
113
+ name = "actix-service"
114
+ version = "2.0.2"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "3b894941f818cfdc7ccc4b9e60fa7e53b5042a2e8567270f9147d5591893373a"
117
+ dependencies = [
118
+ "futures-core",
119
+ "paste",
120
+ "pin-project-lite",
121
+ ]
122
+
123
+ [[package]]
124
+ name = "actix-utils"
125
+ version = "3.0.1"
126
+ source = "registry+https://github.com/rust-lang/crates.io-index"
127
+ checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8"
128
+ dependencies = [
129
+ "local-waker",
130
+ "pin-project-lite",
131
+ ]
132
+
133
+ [[package]]
134
+ name = "actix-web"
135
+ version = "4.3.1"
136
+ source = "registry+https://github.com/rust-lang/crates.io-index"
137
+ checksum = "cd3cb42f9566ab176e1ef0b8b3a896529062b4efc6be0123046095914c4c1c96"
138
+ dependencies = [
139
+ "actix-codec",
140
+ "actix-http",
141
+ "actix-macros",
142
+ "actix-router",
143
+ "actix-rt",
144
+ "actix-server",
145
+ "actix-service",
146
+ "actix-utils",
147
+ "actix-web-codegen",
148
+ "ahash 0.7.6",
149
+ "bytes",
150
+ "bytestring",
151
+ "cfg-if",
152
+ "cookie",
153
+ "derive_more",
154
+ "encoding_rs",
155
+ "futures-core",
156
+ "futures-util",
157
+ "http",
158
+ "itoa",
159
+ "language-tags",
160
+ "log",
161
+ "mime",
162
+ "once_cell",
163
+ "pin-project-lite",
164
+ "regex",
165
+ "serde",
166
+ "serde_json",
167
+ "serde_urlencoded",
168
+ "smallvec",
169
+ "socket2",
170
+ "time 0.3.20",
171
+ "url",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "actix-web-codegen"
176
+ version = "4.2.0"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ checksum = "2262160a7ae29e3415554a3f1fc04c764b1540c116aa524683208078b7a75bc9"
179
+ dependencies = [
180
+ "actix-router",
181
+ "proc-macro2",
182
+ "quote",
183
+ "syn 1.0.109",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "adler"
188
+ version = "1.0.2"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
191
+
192
+ [[package]]
193
+ name = "ahash"
194
+ version = "0.7.6"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
197
+ dependencies = [
198
+ "getrandom",
199
+ "once_cell",
200
+ "version_check",
201
+ ]
202
+
203
+ [[package]]
204
+ name = "ahash"
205
+ version = "0.8.3"
206
+ source = "registry+https://github.com/rust-lang/crates.io-index"
207
+ checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
208
+ dependencies = [
209
+ "cfg-if",
210
+ "getrandom",
211
+ "once_cell",
212
+ "version_check",
213
+ ]
214
+
215
+ [[package]]
216
+ name = "aho-corasick"
217
+ version = "0.7.20"
218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
219
+ checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
220
+ dependencies = [
221
+ "memchr",
222
+ ]
223
+
224
+ [[package]]
225
+ name = "alloc-no-stdlib"
226
+ version = "2.0.4"
227
+ source = "registry+https://github.com/rust-lang/crates.io-index"
228
+ checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3"
229
+
230
+ [[package]]
231
+ name = "alloc-stdlib"
232
+ version = "0.2.2"
233
+ source = "registry+https://github.com/rust-lang/crates.io-index"
234
+ checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece"
235
+ dependencies = [
236
+ "alloc-no-stdlib",
237
+ ]
238
+
239
+ [[package]]
240
+ name = "android_system_properties"
241
+ version = "0.1.5"
242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
243
+ checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
244
+ dependencies = [
245
+ "libc",
246
+ ]
247
+
248
+ [[package]]
249
+ name = "anyhow"
250
+ version = "1.0.71"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
253
+
254
+ [[package]]
255
+ name = "arc-swap"
256
+ version = "1.6.0"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6"
259
+
260
+ [[package]]
261
+ name = "async-openai"
262
+ version = "0.11.0"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "207db2dadafe69aeab087dd54263e04ec9b01836a2d75335707b408eb7ad3f40"
265
+ dependencies = [
266
+ "backoff",
267
+ "base64",
268
+ "derive_builder",
269
+ "futures",
270
+ "rand",
271
+ "reqwest",
272
+ "reqwest-eventsource",
273
+ "serde",
274
+ "serde_json",
275
+ "thiserror",
276
+ "tokio",
277
+ "tokio-stream",
278
+ "tokio-util",
279
+ "tracing",
280
+ ]
281
+
282
+ [[package]]
283
+ name = "async-trait"
284
+ version = "0.1.68"
285
+ source = "registry+https://github.com/rust-lang/crates.io-index"
286
+ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842"
287
+ dependencies = [
288
+ "proc-macro2",
289
+ "quote",
290
+ "syn 2.0.10",
291
+ ]
292
+
293
+ [[package]]
294
+ name = "autocfg"
295
+ version = "1.1.0"
296
+ source = "registry+https://github.com/rust-lang/crates.io-index"
297
+ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
298
+
299
+ [[package]]
300
+ name = "backoff"
301
+ version = "0.4.0"
302
+ source = "registry+https://github.com/rust-lang/crates.io-index"
303
+ checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1"
304
+ dependencies = [
305
+ "futures-core",
306
+ "getrandom",
307
+ "instant",
308
+ "pin-project-lite",
309
+ "rand",
310
+ "tokio",
311
+ ]
312
+
313
+ [[package]]
314
+ name = "base64"
315
+ version = "0.21.0"
316
+ source = "registry+https://github.com/rust-lang/crates.io-index"
317
+ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
318
+
319
+ [[package]]
320
+ name = "bit-set"
321
+ version = "0.5.3"
322
+ source = "registry+https://github.com/rust-lang/crates.io-index"
323
+ checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
324
+ dependencies = [
325
+ "bit-vec",
326
+ ]
327
+
328
+ [[package]]
329
+ name = "bit-vec"
330
+ version = "0.6.3"
331
+ source = "registry+https://github.com/rust-lang/crates.io-index"
332
+ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
333
+
334
+ [[package]]
335
+ name = "bitflags"
336
+ version = "1.3.2"
337
+ source = "registry+https://github.com/rust-lang/crates.io-index"
338
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
339
+
340
+ [[package]]
341
+ name = "block-buffer"
342
+ version = "0.10.4"
343
+ source = "registry+https://github.com/rust-lang/crates.io-index"
344
+ checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
345
+ dependencies = [
346
+ "generic-array",
347
+ ]
348
+
349
+ [[package]]
350
+ name = "brotli"
351
+ version = "3.3.4"
352
+ source = "registry+https://github.com/rust-lang/crates.io-index"
353
+ checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68"
354
+ dependencies = [
355
+ "alloc-no-stdlib",
356
+ "alloc-stdlib",
357
+ "brotli-decompressor",
358
+ ]
359
+
360
+ [[package]]
361
+ name = "brotli-decompressor"
362
+ version = "2.3.4"
363
+ source = "registry+https://github.com/rust-lang/crates.io-index"
364
+ checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744"
365
+ dependencies = [
366
+ "alloc-no-stdlib",
367
+ "alloc-stdlib",
368
+ ]
369
+
370
+ [[package]]
371
+ name = "bstr"
372
+ version = "1.4.0"
373
+ source = "registry+https://github.com/rust-lang/crates.io-index"
374
+ checksum = "c3d4260bcc2e8fc9df1eac4919a720effeb63a3f0952f5bf4944adfa18897f09"
375
+ dependencies = [
376
+ "memchr",
377
+ "once_cell",
378
+ "regex-automata",
379
+ "serde",
380
+ ]
381
+
382
+ [[package]]
383
+ name = "bumpalo"
384
+ version = "3.12.0"
385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
386
+ checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
387
+
388
+ [[package]]
389
+ name = "byteorder"
390
+ version = "1.4.3"
391
+ source = "registry+https://github.com/rust-lang/crates.io-index"
392
+ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
393
+
394
+ [[package]]
395
+ name = "bytes"
396
+ version = "1.4.0"
397
+ source = "registry+https://github.com/rust-lang/crates.io-index"
398
+ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
399
+
400
+ [[package]]
401
+ name = "bytestring"
402
+ version = "1.3.0"
403
+ source = "registry+https://github.com/rust-lang/crates.io-index"
404
+ checksum = "238e4886760d98c4f899360c834fa93e62cf7f721ac3c2da375cbdf4b8679aae"
405
+ dependencies = [
406
+ "bytes",
407
+ ]
408
+
409
+ [[package]]
410
+ name = "cc"
411
+ version = "1.0.79"
412
+ source = "registry+https://github.com/rust-lang/crates.io-index"
413
+ checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
414
+ dependencies = [
415
+ "jobserver",
416
+ ]
417
+
418
+ [[package]]
419
+ name = "cfg-if"
420
+ version = "1.0.0"
421
+ source = "registry+https://github.com/rust-lang/crates.io-index"
422
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
423
+
424
+ [[package]]
425
+ name = "chrono"
426
+ version = "0.4.24"
427
+ source = "registry+https://github.com/rust-lang/crates.io-index"
428
+ checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
429
+ dependencies = [
430
+ "iana-time-zone",
431
+ "js-sys",
432
+ "num-integer",
433
+ "num-traits",
434
+ "time 0.1.45",
435
+ "wasm-bindgen",
436
+ "winapi",
437
+ ]
438
+
439
+ [[package]]
440
+ name = "combine"
441
+ version = "4.6.6"
442
+ source = "registry+https://github.com/rust-lang/crates.io-index"
443
+ checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
444
+ dependencies = [
445
+ "bytes",
446
+ "futures-core",
447
+ "memchr",
448
+ "pin-project-lite",
449
+ "tokio",
450
+ "tokio-util",
451
+ ]
452
+
453
+ [[package]]
454
+ name = "convert_case"
455
+ version = "0.4.0"
456
+ source = "registry+https://github.com/rust-lang/crates.io-index"
457
+ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
458
+
459
+ [[package]]
460
+ name = "cookie"
461
+ version = "0.16.2"
462
+ source = "registry+https://github.com/rust-lang/crates.io-index"
463
+ checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
464
+ dependencies = [
465
+ "percent-encoding",
466
+ "time 0.3.20",
467
+ "version_check",
468
+ ]
469
+
470
+ [[package]]
471
+ name = "core-foundation"
472
+ version = "0.9.3"
473
+ source = "registry+https://github.com/rust-lang/crates.io-index"
474
+ checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
475
+ dependencies = [
476
+ "core-foundation-sys",
477
+ "libc",
478
+ ]
479
+
480
+ [[package]]
481
+ name = "core-foundation-sys"
482
+ version = "0.8.3"
483
+ source = "registry+https://github.com/rust-lang/crates.io-index"
484
+ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
485
+
486
+ [[package]]
487
+ name = "cpufeatures"
488
+ version = "0.2.6"
489
+ source = "registry+https://github.com/rust-lang/crates.io-index"
490
+ checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181"
491
+ dependencies = [
492
+ "libc",
493
+ ]
494
+
495
+ [[package]]
496
+ name = "crc32fast"
497
+ version = "1.3.2"
498
+ source = "registry+https://github.com/rust-lang/crates.io-index"
499
+ checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
500
+ dependencies = [
501
+ "cfg-if",
502
+ ]
503
+
504
+ [[package]]
505
+ name = "crypto-common"
506
+ version = "0.1.6"
507
+ source = "registry+https://github.com/rust-lang/crates.io-index"
508
+ checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
509
+ dependencies = [
510
+ "generic-array",
511
+ "typenum",
512
+ ]
513
+
514
+ [[package]]
515
+ name = "darling"
516
+ version = "0.14.4"
517
+ source = "registry+https://github.com/rust-lang/crates.io-index"
518
+ checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
519
+ dependencies = [
520
+ "darling_core",
521
+ "darling_macro",
522
+ ]
523
+
524
+ [[package]]
525
+ name = "darling_core"
526
+ version = "0.14.4"
527
+ source = "registry+https://github.com/rust-lang/crates.io-index"
528
+ checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
529
+ dependencies = [
530
+ "fnv",
531
+ "ident_case",
532
+ "proc-macro2",
533
+ "quote",
534
+ "strsim",
535
+ "syn 1.0.109",
536
+ ]
537
+
538
+ [[package]]
539
+ name = "darling_macro"
540
+ version = "0.14.4"
541
+ source = "registry+https://github.com/rust-lang/crates.io-index"
542
+ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
543
+ dependencies = [
544
+ "darling_core",
545
+ "quote",
546
+ "syn 1.0.109",
547
+ ]
548
+
549
+ [[package]]
550
+ name = "deadpool"
551
+ version = "0.9.5"
552
+ source = "registry+https://github.com/rust-lang/crates.io-index"
553
+ checksum = "421fe0f90f2ab22016f32a9881be5134fdd71c65298917084b0c7477cbc3856e"
554
+ dependencies = [
555
+ "async-trait",
556
+ "deadpool-runtime",
557
+ "num_cpus",
558
+ "retain_mut",
559
+ "tokio",
560
+ ]
561
+
562
+ [[package]]
563
+ name = "deadpool-runtime"
564
+ version = "0.1.2"
565
+ source = "registry+https://github.com/rust-lang/crates.io-index"
566
+ checksum = "eaa37046cc0f6c3cc6090fbdbf73ef0b8ef4cfcc37f6befc0020f63e8cf121e1"
567
+
568
+ [[package]]
569
+ name = "derive_builder"
570
+ version = "0.12.0"
571
+ source = "registry+https://github.com/rust-lang/crates.io-index"
572
+ checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8"
573
+ dependencies = [
574
+ "derive_builder_macro",
575
+ ]
576
+
577
+ [[package]]
578
+ name = "derive_builder_core"
579
+ version = "0.12.0"
580
+ source = "registry+https://github.com/rust-lang/crates.io-index"
581
+ checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f"
582
+ dependencies = [
583
+ "darling",
584
+ "proc-macro2",
585
+ "quote",
586
+ "syn 1.0.109",
587
+ ]
588
+
589
+ [[package]]
590
+ name = "derive_builder_macro"
591
+ version = "0.12.0"
592
+ source = "registry+https://github.com/rust-lang/crates.io-index"
593
+ checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e"
594
+ dependencies = [
595
+ "derive_builder_core",
596
+ "syn 1.0.109",
597
+ ]
598
+
599
+ [[package]]
600
+ name = "derive_more"
601
+ version = "0.99.17"
602
+ source = "registry+https://github.com/rust-lang/crates.io-index"
603
+ checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
604
+ dependencies = [
605
+ "convert_case",
606
+ "proc-macro2",
607
+ "quote",
608
+ "rustc_version",
609
+ "syn 1.0.109",
610
+ ]
611
+
612
+ [[package]]
613
+ name = "digest"
614
+ version = "0.10.6"
615
+ source = "registry+https://github.com/rust-lang/crates.io-index"
616
+ checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
617
+ dependencies = [
618
+ "block-buffer",
619
+ "crypto-common",
620
+ ]
621
+
622
+ [[package]]
623
+ name = "encoding_rs"
624
+ version = "0.8.32"
625
+ source = "registry+https://github.com/rust-lang/crates.io-index"
626
+ checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394"
627
+ dependencies = [
628
+ "cfg-if",
629
+ ]
630
+
631
+ [[package]]
632
+ name = "env_logger"
633
+ version = "0.10.0"
634
+ source = "registry+https://github.com/rust-lang/crates.io-index"
635
+ checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
636
+ dependencies = [
637
+ "humantime",
638
+ "is-terminal",
639
+ "log",
640
+ "regex",
641
+ "termcolor",
642
+ ]
643
+
644
+ [[package]]
645
+ name = "errno"
646
+ version = "0.3.0"
647
+ source = "registry+https://github.com/rust-lang/crates.io-index"
648
+ checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0"
649
+ dependencies = [
650
+ "errno-dragonfly",
651
+ "libc",
652
+ "windows-sys 0.45.0",
653
+ ]
654
+
655
+ [[package]]
656
+ name = "errno-dragonfly"
657
+ version = "0.1.2"
658
+ source = "registry+https://github.com/rust-lang/crates.io-index"
659
+ checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
660
+ dependencies = [
661
+ "cc",
662
+ "libc",
663
+ ]
664
+
665
+ [[package]]
666
+ name = "eventsource-stream"
667
+ version = "0.2.3"
668
+ source = "registry+https://github.com/rust-lang/crates.io-index"
669
+ checksum = "74fef4569247a5f429d9156b9d0a2599914385dd189c539334c625d8099d90ab"
670
+ dependencies = [
671
+ "futures-core",
672
+ "nom",
673
+ "pin-project-lite",
674
+ ]
675
+
676
+ [[package]]
677
+ name = "fancy-regex"
678
+ version = "0.11.0"
679
+ source = "registry+https://github.com/rust-lang/crates.io-index"
680
+ checksum = "b95f7c0680e4142284cf8b22c14a476e87d61b004a3a0861872b32ef7ead40a2"
681
+ dependencies = [
682
+ "bit-set",
683
+ "regex",
684
+ ]
685
+
686
+ [[package]]
687
+ name = "flate2"
688
+ version = "1.0.25"
689
+ source = "registry+https://github.com/rust-lang/crates.io-index"
690
+ checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
691
+ dependencies = [
692
+ "crc32fast",
693
+ "miniz_oxide",
694
+ ]
695
+
696
+ [[package]]
697
+ name = "fnv"
698
+ version = "1.0.7"
699
+ source = "registry+https://github.com/rust-lang/crates.io-index"
700
+ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
701
+
702
+ [[package]]
703
+ name = "form_urlencoded"
704
+ version = "1.1.0"
705
+ source = "registry+https://github.com/rust-lang/crates.io-index"
706
+ checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8"
707
+ dependencies = [
708
+ "percent-encoding",
709
+ ]
710
+
711
+ [[package]]
712
+ name = "futures"
713
+ version = "0.3.28"
714
+ source = "registry+https://github.com/rust-lang/crates.io-index"
715
+ checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
716
+ dependencies = [
717
+ "futures-channel",
718
+ "futures-core",
719
+ "futures-executor",
720
+ "futures-io",
721
+ "futures-sink",
722
+ "futures-task",
723
+ "futures-util",
724
+ ]
725
+
726
+ [[package]]
727
+ name = "futures-channel"
728
+ version = "0.3.28"
729
+ source = "registry+https://github.com/rust-lang/crates.io-index"
730
+ checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
731
+ dependencies = [
732
+ "futures-core",
733
+ "futures-sink",
734
+ ]
735
+
736
+ [[package]]
737
+ name = "futures-core"
738
+ version = "0.3.28"
739
+ source = "registry+https://github.com/rust-lang/crates.io-index"
740
+ checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
741
+
742
+ [[package]]
743
+ name = "futures-executor"
744
+ version = "0.3.28"
745
+ source = "registry+https://github.com/rust-lang/crates.io-index"
746
+ checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
747
+ dependencies = [
748
+ "futures-core",
749
+ "futures-task",
750
+ "futures-util",
751
+ ]
752
+
753
+ [[package]]
754
+ name = "futures-io"
755
+ version = "0.3.28"
756
+ source = "registry+https://github.com/rust-lang/crates.io-index"
757
+ checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964"
758
+
759
+ [[package]]
760
+ name = "futures-macro"
761
+ version = "0.3.28"
762
+ source = "registry+https://github.com/rust-lang/crates.io-index"
763
+ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
764
+ dependencies = [
765
+ "proc-macro2",
766
+ "quote",
767
+ "syn 2.0.10",
768
+ ]
769
+
770
+ [[package]]
771
+ name = "futures-sink"
772
+ version = "0.3.28"
773
+ source = "registry+https://github.com/rust-lang/crates.io-index"
774
+ checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e"
775
+
776
+ [[package]]
777
+ name = "futures-task"
778
+ version = "0.3.28"
779
+ source = "registry+https://github.com/rust-lang/crates.io-index"
780
+ checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65"
781
+
782
+ [[package]]
783
+ name = "futures-timer"
784
+ version = "3.0.2"
785
+ source = "registry+https://github.com/rust-lang/crates.io-index"
786
+ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
787
+
788
+ [[package]]
789
+ name = "futures-util"
790
+ version = "0.3.28"
791
+ source = "registry+https://github.com/rust-lang/crates.io-index"
792
+ checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
793
+ dependencies = [
794
+ "futures-channel",
795
+ "futures-core",
796
+ "futures-io",
797
+ "futures-macro",
798
+ "futures-sink",
799
+ "futures-task",
800
+ "memchr",
801
+ "pin-project-lite",
802
+ "pin-utils",
803
+ "slab",
804
+ ]
805
+
806
+ [[package]]
807
+ name = "generic-array"
808
+ version = "0.14.6"
809
+ source = "registry+https://github.com/rust-lang/crates.io-index"
810
+ checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
811
+ dependencies = [
812
+ "typenum",
813
+ "version_check",
814
+ ]
815
+
816
+ [[package]]
817
+ name = "getrandom"
818
+ version = "0.2.8"
819
+ source = "registry+https://github.com/rust-lang/crates.io-index"
820
+ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
821
+ dependencies = [
822
+ "cfg-if",
823
+ "libc",
824
+ "wasi 0.11.0+wasi-snapshot-preview1",
825
+ ]
826
+
827
+ [[package]]
828
+ name = "h2"
829
+ version = "0.3.17"
830
+ source = "registry+https://github.com/rust-lang/crates.io-index"
831
+ checksum = "66b91535aa35fea1523ad1b86cb6b53c28e0ae566ba4a460f4457e936cad7c6f"
832
+ dependencies = [
833
+ "bytes",
834
+ "fnv",
835
+ "futures-core",
836
+ "futures-sink",
837
+ "futures-util",
838
+ "http",
839
+ "indexmap",
840
+ "slab",
841
+ "tokio",
842
+ "tokio-util",
843
+ "tracing",
844
+ ]
845
+
846
+ [[package]]
847
+ name = "hashbrown"
848
+ version = "0.12.3"
849
+ source = "registry+https://github.com/rust-lang/crates.io-index"
850
+ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
851
+
852
+ [[package]]
853
+ name = "hermit-abi"
854
+ version = "0.2.6"
855
+ source = "registry+https://github.com/rust-lang/crates.io-index"
856
+ checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
857
+ dependencies = [
858
+ "libc",
859
+ ]
860
+
861
+ [[package]]
862
+ name = "hermit-abi"
863
+ version = "0.3.1"
864
+ source = "registry+https://github.com/rust-lang/crates.io-index"
865
+ checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
866
+
867
+ [[package]]
868
+ name = "http"
869
+ version = "0.2.9"
870
+ source = "registry+https://github.com/rust-lang/crates.io-index"
871
+ checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
872
+ dependencies = [
873
+ "bytes",
874
+ "fnv",
875
+ "itoa",
876
+ ]
877
+
878
+ [[package]]
879
+ name = "http-body"
880
+ version = "0.4.5"
881
+ source = "registry+https://github.com/rust-lang/crates.io-index"
882
+ checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
883
+ dependencies = [
884
+ "bytes",
885
+ "http",
886
+ "pin-project-lite",
887
+ ]
888
+
889
+ [[package]]
890
+ name = "httparse"
891
+ version = "1.8.0"
892
+ source = "registry+https://github.com/rust-lang/crates.io-index"
893
+ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
894
+
895
+ [[package]]
896
+ name = "httpdate"
897
+ version = "1.0.2"
898
+ source = "registry+https://github.com/rust-lang/crates.io-index"
899
+ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
900
+
901
+ [[package]]
902
+ name = "humantime"
903
+ version = "2.1.0"
904
+ source = "registry+https://github.com/rust-lang/crates.io-index"
905
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
906
+
907
+ [[package]]
908
+ name = "hyper"
909
+ version = "0.14.26"
910
+ source = "registry+https://github.com/rust-lang/crates.io-index"
911
+ checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4"
912
+ dependencies = [
913
+ "bytes",
914
+ "futures-channel",
915
+ "futures-core",
916
+ "futures-util",
917
+ "h2",
918
+ "http",
919
+ "http-body",
920
+ "httparse",
921
+ "httpdate",
922
+ "itoa",
923
+ "pin-project-lite",
924
+ "socket2",
925
+ "tokio",
926
+ "tower-service",
927
+ "tracing",
928
+ "want",
929
+ ]
930
+
931
+ [[package]]
932
+ name = "hyper-rustls"
933
+ version = "0.24.0"
934
+ source = "registry+https://github.com/rust-lang/crates.io-index"
935
+ checksum = "0646026eb1b3eea4cd9ba47912ea5ce9cc07713d105b1a14698f4e6433d348b7"
936
+ dependencies = [
937
+ "http",
938
+ "hyper",
939
+ "rustls",
940
+ "tokio",
941
+ "tokio-rustls",
942
+ ]
943
+
944
+ [[package]]
945
+ name = "iana-time-zone"
946
+ version = "0.1.56"
947
+ source = "registry+https://github.com/rust-lang/crates.io-index"
948
+ checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c"
949
+ dependencies = [
950
+ "android_system_properties",
951
+ "core-foundation-sys",
952
+ "iana-time-zone-haiku",
953
+ "js-sys",
954
+ "wasm-bindgen",
955
+ "windows",
956
+ ]
957
+
958
+ [[package]]
959
+ name = "iana-time-zone-haiku"
960
+ version = "0.1.2"
961
+ source = "registry+https://github.com/rust-lang/crates.io-index"
962
+ checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
963
+ dependencies = [
964
+ "cc",
965
+ ]
966
+
967
+ [[package]]
968
+ name = "ident_case"
969
+ version = "1.0.1"
970
+ source = "registry+https://github.com/rust-lang/crates.io-index"
971
+ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
972
+
973
+ [[package]]
974
+ name = "idna"
975
+ version = "0.3.0"
976
+ source = "registry+https://github.com/rust-lang/crates.io-index"
977
+ checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6"
978
+ dependencies = [
979
+ "unicode-bidi",
980
+ "unicode-normalization",
981
+ ]
982
+
983
+ [[package]]
984
+ name = "indexmap"
985
+ version = "1.9.3"
986
+ source = "registry+https://github.com/rust-lang/crates.io-index"
987
+ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
988
+ dependencies = [
989
+ "autocfg",
990
+ "hashbrown",
991
+ ]
992
+
993
+ [[package]]
994
+ name = "instant"
995
+ version = "0.1.12"
996
+ source = "registry+https://github.com/rust-lang/crates.io-index"
997
+ checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
998
+ dependencies = [
999
+ "cfg-if",
1000
+ ]
1001
+
1002
+ [[package]]
1003
+ name = "io-lifetimes"
1004
+ version = "1.0.9"
1005
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1006
+ checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb"
1007
+ dependencies = [
1008
+ "hermit-abi 0.3.1",
1009
+ "libc",
1010
+ "windows-sys 0.45.0",
1011
+ ]
1012
+
1013
+ [[package]]
1014
+ name = "ipnet"
1015
+ version = "2.7.2"
1016
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1017
+ checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
1018
+
1019
+ [[package]]
1020
+ name = "is-terminal"
1021
+ version = "0.4.6"
1022
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1023
+ checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8"
1024
+ dependencies = [
1025
+ "hermit-abi 0.3.1",
1026
+ "io-lifetimes",
1027
+ "rustix",
1028
+ "windows-sys 0.45.0",
1029
+ ]
1030
+
1031
+ [[package]]
1032
+ name = "itoa"
1033
+ version = "1.0.6"
1034
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1035
+ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
1036
+
1037
+ [[package]]
1038
+ name = "jobserver"
1039
+ version = "0.1.26"
1040
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1041
+ checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
1042
+ dependencies = [
1043
+ "libc",
1044
+ ]
1045
+
1046
+ [[package]]
1047
+ name = "js-sys"
1048
+ version = "0.3.61"
1049
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1050
+ checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
1051
+ dependencies = [
1052
+ "wasm-bindgen",
1053
+ ]
1054
+
1055
+ [[package]]
1056
+ name = "language-tags"
1057
+ version = "0.3.2"
1058
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1059
+ checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388"
1060
+
1061
+ [[package]]
1062
+ name = "lazy_static"
1063
+ version = "1.4.0"
1064
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1065
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
1066
+
1067
+ [[package]]
1068
+ name = "libc"
1069
+ version = "0.2.140"
1070
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1071
+ checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
1072
+
1073
+ [[package]]
1074
+ name = "linux-raw-sys"
1075
+ version = "0.3.0"
1076
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1077
+ checksum = "cd550e73688e6d578f0ac2119e32b797a327631a42f9433e59d02e139c8df60d"
1078
+
1079
+ [[package]]
1080
+ name = "local-channel"
1081
+ version = "0.1.3"
1082
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1083
+ checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c"
1084
+ dependencies = [
1085
+ "futures-core",
1086
+ "futures-sink",
1087
+ "futures-util",
1088
+ "local-waker",
1089
+ ]
1090
+
1091
+ [[package]]
1092
+ name = "local-waker"
1093
+ version = "0.1.3"
1094
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1095
+ checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1"
1096
+
1097
+ [[package]]
1098
+ name = "lock_api"
1099
+ version = "0.4.9"
1100
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1101
+ checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
1102
+ dependencies = [
1103
+ "autocfg",
1104
+ "scopeguard",
1105
+ ]
1106
+
1107
+ [[package]]
1108
+ name = "log"
1109
+ version = "0.4.17"
1110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1111
+ checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
1112
+ dependencies = [
1113
+ "cfg-if",
1114
+ ]
1115
+
1116
+ [[package]]
1117
+ name = "memchr"
1118
+ version = "2.5.0"
1119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1120
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
1121
+
1122
+ [[package]]
1123
+ name = "mime"
1124
+ version = "0.3.17"
1125
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1126
+ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
1127
+
1128
+ [[package]]
1129
+ name = "mime_guess"
1130
+ version = "2.0.4"
1131
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1132
+ checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
1133
+ dependencies = [
1134
+ "mime",
1135
+ "unicase",
1136
+ ]
1137
+
1138
+ [[package]]
1139
+ name = "minimal-lexical"
1140
+ version = "0.2.1"
1141
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1142
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
1143
+
1144
+ [[package]]
1145
+ name = "miniz_oxide"
1146
+ version = "0.6.2"
1147
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1148
+ checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
1149
+ dependencies = [
1150
+ "adler",
1151
+ ]
1152
+
1153
+ [[package]]
1154
+ name = "mio"
1155
+ version = "0.8.6"
1156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1157
+ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9"
1158
+ dependencies = [
1159
+ "libc",
1160
+ "log",
1161
+ "wasi 0.11.0+wasi-snapshot-preview1",
1162
+ "windows-sys 0.45.0",
1163
+ ]
1164
+
1165
+ [[package]]
1166
+ name = "motorhead"
1167
+ version = "0.1.0"
1168
+ dependencies = [
1169
+ "actix-web",
1170
+ "async-openai",
1171
+ "async-trait",
1172
+ "byteorder",
1173
+ "chrono",
1174
+ "deadpool",
1175
+ "env_logger",
1176
+ "futures-util",
1177
+ "log",
1178
+ "nanoid",
1179
+ "redis",
1180
+ "serde",
1181
+ "tiktoken-rs",
1182
+ "tokio",
1183
+ ]
1184
+
1185
+ [[package]]
1186
+ name = "nanoid"
1187
+ version = "0.4.0"
1188
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1189
+ checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8"
1190
+ dependencies = [
1191
+ "rand",
1192
+ ]
1193
+
1194
+ [[package]]
1195
+ name = "nom"
1196
+ version = "7.1.3"
1197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1198
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
1199
+ dependencies = [
1200
+ "memchr",
1201
+ "minimal-lexical",
1202
+ ]
1203
+
1204
+ [[package]]
1205
+ name = "num-integer"
1206
+ version = "0.1.45"
1207
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1208
+ checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
1209
+ dependencies = [
1210
+ "autocfg",
1211
+ "num-traits",
1212
+ ]
1213
+
1214
+ [[package]]
1215
+ name = "num-traits"
1216
+ version = "0.2.15"
1217
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1218
+ checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
1219
+ dependencies = [
1220
+ "autocfg",
1221
+ ]
1222
+
1223
+ [[package]]
1224
+ name = "num_cpus"
1225
+ version = "1.15.0"
1226
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1227
+ checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
1228
+ dependencies = [
1229
+ "hermit-abi 0.2.6",
1230
+ "libc",
1231
+ ]
1232
+
1233
+ [[package]]
1234
+ name = "once_cell"
1235
+ version = "1.17.1"
1236
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1237
+ checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
1238
+
1239
+ [[package]]
1240
+ name = "openssl-probe"
1241
+ version = "0.1.5"
1242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1243
+ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
1244
+
1245
+ [[package]]
1246
+ name = "parking_lot"
1247
+ version = "0.12.1"
1248
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1249
+ checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
1250
+ dependencies = [
1251
+ "lock_api",
1252
+ "parking_lot_core",
1253
+ ]
1254
+
1255
+ [[package]]
1256
+ name = "parking_lot_core"
1257
+ version = "0.9.7"
1258
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1259
+ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
1260
+ dependencies = [
1261
+ "cfg-if",
1262
+ "libc",
1263
+ "redox_syscall",
1264
+ "smallvec",
1265
+ "windows-sys 0.45.0",
1266
+ ]
1267
+
1268
+ [[package]]
1269
+ name = "paste"
1270
+ version = "1.0.12"
1271
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1272
+ checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79"
1273
+
1274
+ [[package]]
1275
+ name = "percent-encoding"
1276
+ version = "2.2.0"
1277
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1278
+ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
1279
+
1280
+ [[package]]
1281
+ name = "pin-project-lite"
1282
+ version = "0.2.9"
1283
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1284
+ checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
1285
+
1286
+ [[package]]
1287
+ name = "pin-utils"
1288
+ version = "0.1.0"
1289
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1290
+ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
1291
+
1292
+ [[package]]
1293
+ name = "pkg-config"
1294
+ version = "0.3.26"
1295
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1296
+ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
1297
+
1298
+ [[package]]
1299
+ name = "ppv-lite86"
1300
+ version = "0.2.17"
1301
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1302
+ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1303
+
1304
+ [[package]]
1305
+ name = "proc-macro2"
1306
+ version = "1.0.54"
1307
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1308
+ checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
1309
+ dependencies = [
1310
+ "unicode-ident",
1311
+ ]
1312
+
1313
+ [[package]]
1314
+ name = "quote"
1315
+ version = "1.0.26"
1316
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1317
+ checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
1318
+ dependencies = [
1319
+ "proc-macro2",
1320
+ ]
1321
+
1322
+ [[package]]
1323
+ name = "rand"
1324
+ version = "0.8.5"
1325
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1326
+ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
1327
+ dependencies = [
1328
+ "libc",
1329
+ "rand_chacha",
1330
+ "rand_core",
1331
+ ]
1332
+
1333
+ [[package]]
1334
+ name = "rand_chacha"
1335
+ version = "0.3.1"
1336
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1337
+ checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
1338
+ dependencies = [
1339
+ "ppv-lite86",
1340
+ "rand_core",
1341
+ ]
1342
+
1343
+ [[package]]
1344
+ name = "rand_core"
1345
+ version = "0.6.4"
1346
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1347
+ checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
1348
+ dependencies = [
1349
+ "getrandom",
1350
+ ]
1351
+
1352
+ [[package]]
1353
+ name = "redis"
1354
+ version = "0.22.3"
1355
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1356
+ checksum = "aa8455fa3621f6b41c514946de66ea0531f57ca017b2e6c7cc368035ea5b46df"
1357
+ dependencies = [
1358
+ "arc-swap",
1359
+ "async-trait",
1360
+ "bytes",
1361
+ "combine",
1362
+ "futures",
1363
+ "futures-util",
1364
+ "itoa",
1365
+ "percent-encoding",
1366
+ "pin-project-lite",
1367
+ "ryu",
1368
+ "tokio",
1369
+ "tokio-util",
1370
+ "url",
1371
+ ]
1372
+
1373
+ [[package]]
1374
+ name = "redox_syscall"
1375
+ version = "0.2.16"
1376
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1377
+ checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
1378
+ dependencies = [
1379
+ "bitflags",
1380
+ ]
1381
+
1382
+ [[package]]
1383
+ name = "regex"
1384
+ version = "1.7.3"
1385
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1386
+ checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
1387
+ dependencies = [
1388
+ "aho-corasick",
1389
+ "memchr",
1390
+ "regex-syntax",
1391
+ ]
1392
+
1393
+ [[package]]
1394
+ name = "regex-automata"
1395
+ version = "0.1.10"
1396
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1397
+ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
1398
+
1399
+ [[package]]
1400
+ name = "regex-syntax"
1401
+ version = "0.6.29"
1402
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1403
+ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
1404
+
1405
+ [[package]]
1406
+ name = "reqwest"
1407
+ version = "0.11.18"
1408
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1409
+ checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55"
1410
+ dependencies = [
1411
+ "base64",
1412
+ "bytes",
1413
+ "encoding_rs",
1414
+ "futures-core",
1415
+ "futures-util",
1416
+ "h2",
1417
+ "http",
1418
+ "http-body",
1419
+ "hyper",
1420
+ "hyper-rustls",
1421
+ "ipnet",
1422
+ "js-sys",
1423
+ "log",
1424
+ "mime",
1425
+ "mime_guess",
1426
+ "once_cell",
1427
+ "percent-encoding",
1428
+ "pin-project-lite",
1429
+ "rustls",
1430
+ "rustls-native-certs",
1431
+ "rustls-pemfile",
1432
+ "serde",
1433
+ "serde_json",
1434
+ "serde_urlencoded",
1435
+ "tokio",
1436
+ "tokio-rustls",
1437
+ "tokio-util",
1438
+ "tower-service",
1439
+ "url",
1440
+ "wasm-bindgen",
1441
+ "wasm-bindgen-futures",
1442
+ "wasm-streams",
1443
+ "web-sys",
1444
+ "winreg",
1445
+ ]
1446
+
1447
+ [[package]]
1448
+ name = "reqwest-eventsource"
1449
+ version = "0.4.0"
1450
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1451
+ checksum = "8f03f570355882dd8d15acc3a313841e6e90eddbc76a93c748fd82cc13ba9f51"
1452
+ dependencies = [
1453
+ "eventsource-stream",
1454
+ "futures-core",
1455
+ "futures-timer",
1456
+ "mime",
1457
+ "nom",
1458
+ "pin-project-lite",
1459
+ "reqwest",
1460
+ "thiserror",
1461
+ ]
1462
+
1463
+ [[package]]
1464
+ name = "retain_mut"
1465
+ version = "0.1.9"
1466
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1467
+ checksum = "4389f1d5789befaf6029ebd9f7dac4af7f7e3d61b69d4f30e2ac02b57e7712b0"
1468
+
1469
+ [[package]]
1470
+ name = "ring"
1471
+ version = "0.16.20"
1472
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1473
+ checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc"
1474
+ dependencies = [
1475
+ "cc",
1476
+ "libc",
1477
+ "once_cell",
1478
+ "spin",
1479
+ "untrusted",
1480
+ "web-sys",
1481
+ "winapi",
1482
+ ]
1483
+
1484
+ [[package]]
1485
+ name = "rustc-hash"
1486
+ version = "1.1.0"
1487
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1488
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
1489
+
1490
+ [[package]]
1491
+ name = "rustc_version"
1492
+ version = "0.4.0"
1493
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1494
+ checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
1495
+ dependencies = [
1496
+ "semver",
1497
+ ]
1498
+
1499
+ [[package]]
1500
+ name = "rustix"
1501
+ version = "0.37.4"
1502
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1503
+ checksum = "c348b5dc624ecee40108aa2922fed8bad89d7fcc2b9f8cb18f632898ac4a37f9"
1504
+ dependencies = [
1505
+ "bitflags",
1506
+ "errno",
1507
+ "io-lifetimes",
1508
+ "libc",
1509
+ "linux-raw-sys",
1510
+ "windows-sys 0.45.0",
1511
+ ]
1512
+
1513
+ [[package]]
1514
+ name = "rustls"
1515
+ version = "0.21.2"
1516
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1517
+ checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f"
1518
+ dependencies = [
1519
+ "log",
1520
+ "ring",
1521
+ "rustls-webpki",
1522
+ "sct",
1523
+ ]
1524
+
1525
+ [[package]]
1526
+ name = "rustls-native-certs"
1527
+ version = "0.6.3"
1528
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1529
+ checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00"
1530
+ dependencies = [
1531
+ "openssl-probe",
1532
+ "rustls-pemfile",
1533
+ "schannel",
1534
+ "security-framework",
1535
+ ]
1536
+
1537
+ [[package]]
1538
+ name = "rustls-pemfile"
1539
+ version = "1.0.2"
1540
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1541
+ checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b"
1542
+ dependencies = [
1543
+ "base64",
1544
+ ]
1545
+
1546
+ [[package]]
1547
+ name = "rustls-webpki"
1548
+ version = "0.100.1"
1549
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1550
+ checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b"
1551
+ dependencies = [
1552
+ "ring",
1553
+ "untrusted",
1554
+ ]
1555
+
1556
+ [[package]]
1557
+ name = "ryu"
1558
+ version = "1.0.13"
1559
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1560
+ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
1561
+
1562
+ [[package]]
1563
+ name = "schannel"
1564
+ version = "0.1.21"
1565
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1566
+ checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3"
1567
+ dependencies = [
1568
+ "windows-sys 0.42.0",
1569
+ ]
1570
+
1571
+ [[package]]
1572
+ name = "scopeguard"
1573
+ version = "1.1.0"
1574
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1575
+ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1576
+
1577
+ [[package]]
1578
+ name = "sct"
1579
+ version = "0.7.0"
1580
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1581
+ checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4"
1582
+ dependencies = [
1583
+ "ring",
1584
+ "untrusted",
1585
+ ]
1586
+
1587
+ [[package]]
1588
+ name = "security-framework"
1589
+ version = "2.9.1"
1590
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1591
+ checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8"
1592
+ dependencies = [
1593
+ "bitflags",
1594
+ "core-foundation",
1595
+ "core-foundation-sys",
1596
+ "libc",
1597
+ "security-framework-sys",
1598
+ ]
1599
+
1600
+ [[package]]
1601
+ name = "security-framework-sys"
1602
+ version = "2.9.0"
1603
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1604
+ checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7"
1605
+ dependencies = [
1606
+ "core-foundation-sys",
1607
+ "libc",
1608
+ ]
1609
+
1610
+ [[package]]
1611
+ name = "semver"
1612
+ version = "1.0.17"
1613
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1614
+ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
1615
+
1616
+ [[package]]
1617
+ name = "serde"
1618
+ version = "1.0.158"
1619
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1620
+ checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9"
1621
+ dependencies = [
1622
+ "serde_derive",
1623
+ ]
1624
+
1625
+ [[package]]
1626
+ name = "serde_derive"
1627
+ version = "1.0.158"
1628
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1629
+ checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad"
1630
+ dependencies = [
1631
+ "proc-macro2",
1632
+ "quote",
1633
+ "syn 2.0.10",
1634
+ ]
1635
+
1636
+ [[package]]
1637
+ name = "serde_json"
1638
+ version = "1.0.94"
1639
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1640
+ checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea"
1641
+ dependencies = [
1642
+ "itoa",
1643
+ "ryu",
1644
+ "serde",
1645
+ ]
1646
+
1647
+ [[package]]
1648
+ name = "serde_urlencoded"
1649
+ version = "0.7.1"
1650
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1651
+ checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
1652
+ dependencies = [
1653
+ "form_urlencoded",
1654
+ "itoa",
1655
+ "ryu",
1656
+ "serde",
1657
+ ]
1658
+
1659
+ [[package]]
1660
+ name = "sha1"
1661
+ version = "0.10.5"
1662
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1663
+ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3"
1664
+ dependencies = [
1665
+ "cfg-if",
1666
+ "cpufeatures",
1667
+ "digest",
1668
+ ]
1669
+
1670
+ [[package]]
1671
+ name = "signal-hook-registry"
1672
+ version = "1.4.1"
1673
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1674
+ checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
1675
+ dependencies = [
1676
+ "libc",
1677
+ ]
1678
+
1679
+ [[package]]
1680
+ name = "slab"
1681
+ version = "0.4.8"
1682
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1683
+ checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d"
1684
+ dependencies = [
1685
+ "autocfg",
1686
+ ]
1687
+
1688
+ [[package]]
1689
+ name = "smallvec"
1690
+ version = "1.10.0"
1691
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1692
+ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
1693
+
1694
+ [[package]]
1695
+ name = "socket2"
1696
+ version = "0.4.9"
1697
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1698
+ checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
1699
+ dependencies = [
1700
+ "libc",
1701
+ "winapi",
1702
+ ]
1703
+
1704
+ [[package]]
1705
+ name = "spin"
1706
+ version = "0.5.2"
1707
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1708
+ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
1709
+
1710
+ [[package]]
1711
+ name = "strsim"
1712
+ version = "0.10.0"
1713
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1714
+ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
1715
+
1716
+ [[package]]
1717
+ name = "syn"
1718
+ version = "1.0.109"
1719
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1720
+ checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
1721
+ dependencies = [
1722
+ "proc-macro2",
1723
+ "quote",
1724
+ "unicode-ident",
1725
+ ]
1726
+
1727
+ [[package]]
1728
+ name = "syn"
1729
+ version = "2.0.10"
1730
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1731
+ checksum = "5aad1363ed6d37b84299588d62d3a7d95b5a5c2d9aad5c85609fda12afaa1f40"
1732
+ dependencies = [
1733
+ "proc-macro2",
1734
+ "quote",
1735
+ "unicode-ident",
1736
+ ]
1737
+
1738
+ [[package]]
1739
+ name = "termcolor"
1740
+ version = "1.2.0"
1741
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1742
+ checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
1743
+ dependencies = [
1744
+ "winapi-util",
1745
+ ]
1746
+
1747
+ [[package]]
1748
+ name = "thiserror"
1749
+ version = "1.0.40"
1750
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1751
+ checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
1752
+ dependencies = [
1753
+ "thiserror-impl",
1754
+ ]
1755
+
1756
+ [[package]]
1757
+ name = "thiserror-impl"
1758
+ version = "1.0.40"
1759
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1760
+ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
1761
+ dependencies = [
1762
+ "proc-macro2",
1763
+ "quote",
1764
+ "syn 2.0.10",
1765
+ ]
1766
+
1767
+ [[package]]
1768
+ name = "tiktoken-rs"
1769
+ version = "0.4.1"
1770
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1771
+ checksum = "cb22485be61c6206171beb39fbc39104b31850025296710ff42ae60c1f9123c4"
1772
+ dependencies = [
1773
+ "anyhow",
1774
+ "base64",
1775
+ "bstr",
1776
+ "fancy-regex",
1777
+ "lazy_static",
1778
+ "parking_lot",
1779
+ "rustc-hash",
1780
+ ]
1781
+
1782
+ [[package]]
1783
+ name = "time"
1784
+ version = "0.1.45"
1785
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1786
+ checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
1787
+ dependencies = [
1788
+ "libc",
1789
+ "wasi 0.10.0+wasi-snapshot-preview1",
1790
+ "winapi",
1791
+ ]
1792
+
1793
+ [[package]]
1794
+ name = "time"
1795
+ version = "0.3.20"
1796
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1797
+ checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890"
1798
+ dependencies = [
1799
+ "itoa",
1800
+ "serde",
1801
+ "time-core",
1802
+ "time-macros",
1803
+ ]
1804
+
1805
+ [[package]]
1806
+ name = "time-core"
1807
+ version = "0.1.0"
1808
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1809
+ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
1810
+
1811
+ [[package]]
1812
+ name = "time-macros"
1813
+ version = "0.2.8"
1814
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1815
+ checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36"
1816
+ dependencies = [
1817
+ "time-core",
1818
+ ]
1819
+
1820
+ [[package]]
1821
+ name = "tinyvec"
1822
+ version = "1.6.0"
1823
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1824
+ checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
1825
+ dependencies = [
1826
+ "tinyvec_macros",
1827
+ ]
1828
+
1829
+ [[package]]
1830
+ name = "tinyvec_macros"
1831
+ version = "0.1.1"
1832
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1833
+ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
1834
+
1835
+ [[package]]
1836
+ name = "tokio"
1837
+ version = "1.26.0"
1838
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1839
+ checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64"
1840
+ dependencies = [
1841
+ "autocfg",
1842
+ "bytes",
1843
+ "libc",
1844
+ "memchr",
1845
+ "mio",
1846
+ "num_cpus",
1847
+ "parking_lot",
1848
+ "pin-project-lite",
1849
+ "signal-hook-registry",
1850
+ "socket2",
1851
+ "tokio-macros",
1852
+ "windows-sys 0.45.0",
1853
+ ]
1854
+
1855
+ [[package]]
1856
+ name = "tokio-macros"
1857
+ version = "1.8.2"
1858
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1859
+ checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
1860
+ dependencies = [
1861
+ "proc-macro2",
1862
+ "quote",
1863
+ "syn 1.0.109",
1864
+ ]
1865
+
1866
+ [[package]]
1867
+ name = "tokio-rustls"
1868
+ version = "0.24.1"
1869
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1870
+ checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081"
1871
+ dependencies = [
1872
+ "rustls",
1873
+ "tokio",
1874
+ ]
1875
+
1876
+ [[package]]
1877
+ name = "tokio-stream"
1878
+ version = "0.1.14"
1879
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1880
+ checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842"
1881
+ dependencies = [
1882
+ "futures-core",
1883
+ "pin-project-lite",
1884
+ "tokio",
1885
+ ]
1886
+
1887
+ [[package]]
1888
+ name = "tokio-util"
1889
+ version = "0.7.7"
1890
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1891
+ checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2"
1892
+ dependencies = [
1893
+ "bytes",
1894
+ "futures-core",
1895
+ "futures-sink",
1896
+ "pin-project-lite",
1897
+ "tokio",
1898
+ "tracing",
1899
+ ]
1900
+
1901
+ [[package]]
1902
+ name = "tower-service"
1903
+ version = "0.3.2"
1904
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1905
+ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
1906
+
1907
+ [[package]]
1908
+ name = "tracing"
1909
+ version = "0.1.37"
1910
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1911
+ checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8"
1912
+ dependencies = [
1913
+ "cfg-if",
1914
+ "log",
1915
+ "pin-project-lite",
1916
+ "tracing-attributes",
1917
+ "tracing-core",
1918
+ ]
1919
+
1920
+ [[package]]
1921
+ name = "tracing-attributes"
1922
+ version = "0.1.24"
1923
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1924
+ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
1925
+ dependencies = [
1926
+ "proc-macro2",
1927
+ "quote",
1928
+ "syn 2.0.10",
1929
+ ]
1930
+
1931
+ [[package]]
1932
+ name = "tracing-core"
1933
+ version = "0.1.30"
1934
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1935
+ checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
1936
+ dependencies = [
1937
+ "once_cell",
1938
+ ]
1939
+
1940
+ [[package]]
1941
+ name = "try-lock"
1942
+ version = "0.2.4"
1943
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1944
+ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
1945
+
1946
+ [[package]]
1947
+ name = "typenum"
1948
+ version = "1.16.0"
1949
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1950
+ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
1951
+
1952
+ [[package]]
1953
+ name = "unicase"
1954
+ version = "2.6.0"
1955
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1956
+ checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
1957
+ dependencies = [
1958
+ "version_check",
1959
+ ]
1960
+
1961
+ [[package]]
1962
+ name = "unicode-bidi"
1963
+ version = "0.3.13"
1964
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1965
+ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
1966
+
1967
+ [[package]]
1968
+ name = "unicode-ident"
1969
+ version = "1.0.8"
1970
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1971
+ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
1972
+
1973
+ [[package]]
1974
+ name = "unicode-normalization"
1975
+ version = "0.1.22"
1976
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1977
+ checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
1978
+ dependencies = [
1979
+ "tinyvec",
1980
+ ]
1981
+
1982
+ [[package]]
1983
+ name = "untrusted"
1984
+ version = "0.7.1"
1985
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1986
+ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a"
1987
+
1988
+ [[package]]
1989
+ name = "url"
1990
+ version = "2.3.1"
1991
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1992
+ checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643"
1993
+ dependencies = [
1994
+ "form_urlencoded",
1995
+ "idna",
1996
+ "percent-encoding",
1997
+ ]
1998
+
1999
+ [[package]]
2000
+ name = "version_check"
2001
+ version = "0.9.4"
2002
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2003
+ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
2004
+
2005
+ [[package]]
2006
+ name = "want"
2007
+ version = "0.3.1"
2008
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2009
+ checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
2010
+ dependencies = [
2011
+ "try-lock",
2012
+ ]
2013
+
2014
+ [[package]]
2015
+ name = "wasi"
2016
+ version = "0.10.0+wasi-snapshot-preview1"
2017
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2018
+ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
2019
+
2020
+ [[package]]
2021
+ name = "wasi"
2022
+ version = "0.11.0+wasi-snapshot-preview1"
2023
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2024
+ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
2025
+
2026
+ [[package]]
2027
+ name = "wasm-bindgen"
2028
+ version = "0.2.84"
2029
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2030
+ checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
2031
+ dependencies = [
2032
+ "cfg-if",
2033
+ "wasm-bindgen-macro",
2034
+ ]
2035
+
2036
+ [[package]]
2037
+ name = "wasm-bindgen-backend"
2038
+ version = "0.2.84"
2039
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2040
+ checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
2041
+ dependencies = [
2042
+ "bumpalo",
2043
+ "log",
2044
+ "once_cell",
2045
+ "proc-macro2",
2046
+ "quote",
2047
+ "syn 1.0.109",
2048
+ "wasm-bindgen-shared",
2049
+ ]
2050
+
2051
+ [[package]]
2052
+ name = "wasm-bindgen-futures"
2053
+ version = "0.4.34"
2054
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2055
+ checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454"
2056
+ dependencies = [
2057
+ "cfg-if",
2058
+ "js-sys",
2059
+ "wasm-bindgen",
2060
+ "web-sys",
2061
+ ]
2062
+
2063
+ [[package]]
2064
+ name = "wasm-bindgen-macro"
2065
+ version = "0.2.84"
2066
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2067
+ checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
2068
+ dependencies = [
2069
+ "quote",
2070
+ "wasm-bindgen-macro-support",
2071
+ ]
2072
+
2073
+ [[package]]
2074
+ name = "wasm-bindgen-macro-support"
2075
+ version = "0.2.84"
2076
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2077
+ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
2078
+ dependencies = [
2079
+ "proc-macro2",
2080
+ "quote",
2081
+ "syn 1.0.109",
2082
+ "wasm-bindgen-backend",
2083
+ "wasm-bindgen-shared",
2084
+ ]
2085
+
2086
+ [[package]]
2087
+ name = "wasm-bindgen-shared"
2088
+ version = "0.2.84"
2089
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2090
+ checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
2091
+
2092
+ [[package]]
2093
+ name = "wasm-streams"
2094
+ version = "0.2.3"
2095
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2096
+ checksum = "6bbae3363c08332cadccd13b67db371814cd214c2524020932f0804b8cf7c078"
2097
+ dependencies = [
2098
+ "futures-util",
2099
+ "js-sys",
2100
+ "wasm-bindgen",
2101
+ "wasm-bindgen-futures",
2102
+ "web-sys",
2103
+ ]
2104
+
2105
+ [[package]]
2106
+ name = "web-sys"
2107
+ version = "0.3.61"
2108
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2109
+ checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97"
2110
+ dependencies = [
2111
+ "js-sys",
2112
+ "wasm-bindgen",
2113
+ ]
2114
+
2115
+ [[package]]
2116
+ name = "winapi"
2117
+ version = "0.3.9"
2118
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2119
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
2120
+ dependencies = [
2121
+ "winapi-i686-pc-windows-gnu",
2122
+ "winapi-x86_64-pc-windows-gnu",
2123
+ ]
2124
+
2125
+ [[package]]
2126
+ name = "winapi-i686-pc-windows-gnu"
2127
+ version = "0.4.0"
2128
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2129
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
2130
+
2131
+ [[package]]
2132
+ name = "winapi-util"
2133
+ version = "0.1.5"
2134
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2135
+ checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
2136
+ dependencies = [
2137
+ "winapi",
2138
+ ]
2139
+
2140
+ [[package]]
2141
+ name = "winapi-x86_64-pc-windows-gnu"
2142
+ version = "0.4.0"
2143
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2144
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
2145
+
2146
+ [[package]]
2147
+ name = "windows"
2148
+ version = "0.48.0"
2149
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2150
+ checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
2151
+ dependencies = [
2152
+ "windows-targets 0.48.0",
2153
+ ]
2154
+
2155
+ [[package]]
2156
+ name = "windows-sys"
2157
+ version = "0.42.0"
2158
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2159
+ checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
2160
+ dependencies = [
2161
+ "windows_aarch64_gnullvm 0.42.2",
2162
+ "windows_aarch64_msvc 0.42.2",
2163
+ "windows_i686_gnu 0.42.2",
2164
+ "windows_i686_msvc 0.42.2",
2165
+ "windows_x86_64_gnu 0.42.2",
2166
+ "windows_x86_64_gnullvm 0.42.2",
2167
+ "windows_x86_64_msvc 0.42.2",
2168
+ ]
2169
+
2170
+ [[package]]
2171
+ name = "windows-sys"
2172
+ version = "0.45.0"
2173
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2174
+ checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
2175
+ dependencies = [
2176
+ "windows-targets 0.42.2",
2177
+ ]
2178
+
2179
+ [[package]]
2180
+ name = "windows-targets"
2181
+ version = "0.42.2"
2182
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2183
+ checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
2184
+ dependencies = [
2185
+ "windows_aarch64_gnullvm 0.42.2",
2186
+ "windows_aarch64_msvc 0.42.2",
2187
+ "windows_i686_gnu 0.42.2",
2188
+ "windows_i686_msvc 0.42.2",
2189
+ "windows_x86_64_gnu 0.42.2",
2190
+ "windows_x86_64_gnullvm 0.42.2",
2191
+ "windows_x86_64_msvc 0.42.2",
2192
+ ]
2193
+
2194
+ [[package]]
2195
+ name = "windows-targets"
2196
+ version = "0.48.0"
2197
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2198
+ checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
2199
+ dependencies = [
2200
+ "windows_aarch64_gnullvm 0.48.0",
2201
+ "windows_aarch64_msvc 0.48.0",
2202
+ "windows_i686_gnu 0.48.0",
2203
+ "windows_i686_msvc 0.48.0",
2204
+ "windows_x86_64_gnu 0.48.0",
2205
+ "windows_x86_64_gnullvm 0.48.0",
2206
+ "windows_x86_64_msvc 0.48.0",
2207
+ ]
2208
+
2209
+ [[package]]
2210
+ name = "windows_aarch64_gnullvm"
2211
+ version = "0.42.2"
2212
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2213
+ checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
2214
+
2215
+ [[package]]
2216
+ name = "windows_aarch64_gnullvm"
2217
+ version = "0.48.0"
2218
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2219
+ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
2220
+
2221
+ [[package]]
2222
+ name = "windows_aarch64_msvc"
2223
+ version = "0.42.2"
2224
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2225
+ checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
2226
+
2227
+ [[package]]
2228
+ name = "windows_aarch64_msvc"
2229
+ version = "0.48.0"
2230
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2231
+ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
2232
+
2233
+ [[package]]
2234
+ name = "windows_i686_gnu"
2235
+ version = "0.42.2"
2236
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2237
+ checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
2238
+
2239
+ [[package]]
2240
+ name = "windows_i686_gnu"
2241
+ version = "0.48.0"
2242
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2243
+ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
2244
+
2245
+ [[package]]
2246
+ name = "windows_i686_msvc"
2247
+ version = "0.42.2"
2248
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2249
+ checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
2250
+
2251
+ [[package]]
2252
+ name = "windows_i686_msvc"
2253
+ version = "0.48.0"
2254
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2255
+ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
2256
+
2257
+ [[package]]
2258
+ name = "windows_x86_64_gnu"
2259
+ version = "0.42.2"
2260
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2261
+ checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
2262
+
2263
+ [[package]]
2264
+ name = "windows_x86_64_gnu"
2265
+ version = "0.48.0"
2266
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2267
+ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
2268
+
2269
+ [[package]]
2270
+ name = "windows_x86_64_gnullvm"
2271
+ version = "0.42.2"
2272
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2273
+ checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
2274
+
2275
+ [[package]]
2276
+ name = "windows_x86_64_gnullvm"
2277
+ version = "0.48.0"
2278
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2279
+ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
2280
+
2281
+ [[package]]
2282
+ name = "windows_x86_64_msvc"
2283
+ version = "0.42.2"
2284
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2285
+ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
2286
+
2287
+ [[package]]
2288
+ name = "windows_x86_64_msvc"
2289
+ version = "0.48.0"
2290
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2291
+ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
2292
+
2293
+ [[package]]
2294
+ name = "winreg"
2295
+ version = "0.10.1"
2296
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2297
+ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
2298
+ dependencies = [
2299
+ "winapi",
2300
+ ]
2301
+
2302
+ [[package]]
2303
+ name = "zstd"
2304
+ version = "0.12.3+zstd.1.5.2"
2305
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2306
+ checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
2307
+ dependencies = [
2308
+ "zstd-safe",
2309
+ ]
2310
+
2311
+ [[package]]
2312
+ name = "zstd-safe"
2313
+ version = "6.0.4+zstd.1.5.4"
2314
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2315
+ checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
2316
+ dependencies = [
2317
+ "libc",
2318
+ "zstd-sys",
2319
+ ]
2320
+
2321
+ [[package]]
2322
+ name = "zstd-sys"
2323
+ version = "2.0.7+zstd.1.5.4"
2324
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2325
+ checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
2326
+ dependencies = [
2327
+ "cc",
2328
+ "libc",
2329
+ "pkg-config",
2330
+ ]
Cargo.toml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [package]
2
+ name = "motorhead"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Sergio Prada <metal@getmetal.io>"]
6
+
7
+
8
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9
+
10
+ [dependencies]
11
+ actix-web = "4.3"
12
+ async-openai = "0.11.0"
13
+ async-trait = "0.1.68"
14
+ byteorder = "1.4.3"
15
+ chrono = "0.4.24"
16
+ deadpool = "0.9.5"
17
+ env_logger = "0.10"
18
+ futures-util = { version = "0.3.17", default-features = false, features = ["std"] }
19
+ log = "0.4"
20
+ nanoid = "0.4.0"
21
+ redis = { version = "0.22", default-features = false, features = ["tokio-comp", "connection-manager"] }
22
+ serde = { version = "1", features = ["derive"] }
23
+ tiktoken-rs = "0.4.1"
24
+ tokio = { version = "1", features = ["full"] }
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM rust:1.68-slim-buster as build
2
+
3
+ RUN USER=root cargo new --bin motorhead
4
+ WORKDIR /motorhead
5
+
6
+ COPY ./Cargo.lock ./Cargo.lock
7
+ COPY ./Cargo.toml ./Cargo.toml
8
+
9
+ # had to add this for open-ssl
10
+ RUN apt-get update -y && \
11
+ apt-get install -y pkg-config make g++ libssl-dev ca-certificates && \
12
+ rustup target add x86_64-unknown-linux-gnu
13
+
14
+ # cache dependencies
15
+ RUN cargo build --release
16
+ RUN rm src/*.rs
17
+
18
+ # copy your source tree
19
+ COPY ./src ./src
20
+
21
+ # build for release
22
+ RUN rm ./target/release/deps/motorhead*
23
+ RUN cargo build --release
24
+
25
+ FROM debian:buster-slim
26
+
27
+ RUN apt-get update && apt install -y openssl ca-certificates
28
+
29
+ COPY --from=build /motorhead/target/release/motorhead .
30
+
31
+ CMD ["./motorhead"]
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 Metal Technologies Inc
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md CHANGED
@@ -1,10 +1,127 @@
1
- ---
2
- title: Motorhead
3
- emoji: 😻
4
- colorFrom: indigo
5
- colorTo: pink
6
- sdk: docker
7
- pinned: false
8
- ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1 align="center" >
2
+ 🧠 Motorhead
3
+ </h1>
4
+ <p align="center">
5
+ <a href="https://github.com/getmetal/motorhead/blob/main/LICENSE">
6
+ <img src="https://img.shields.io/github/license/getmetal/motorhead?style=flat&label=license&logo=github&color=4f46e5&logoColor=fff" alt="License" />
7
+ </a>
8
+ <a href="https://twitter.com/Metal_io">
9
+ <img src="https://img.shields.io/badge/metal-message?style=flat&logo=twitter&color=4f46e5&logoColor=#4f46e5" alt="Metal" style="margin-right:3px" />
10
+ </a>
11
+ <a href="https://discord.gg/GHY3Y8tU3J">
12
+ <img src="https://dcbadge.vercel.app/api/server/GHY3Y8tU3J?compact=true&style=flat" alt="License" />
13
+ </a>
14
+ </p>
15
+
16
+ Motorhead is a memory and information retrieval server for LLMs.
17
+
18
+ [![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/bmO_uf?referralCode=5NirXf)
19
+
20
+ ## Why use Motorhead?
21
+
22
+ When building chat applications using LLMs, memory handling is something that has to be built every time. Motorhead is a server to assist with that process. It provides 3 simple APIs:
23
+
24
+ - GET `/sessions/:id/memory` returns messages up to `MAX_WINDOW_SIZE`.
25
+ ```json
26
+ {
27
+ "messages": [
28
+ {
29
+ "role": "AI",
30
+ "content": "Electronic music and salsa are two very different genres of music, and the way people dance to them is also quite different."
31
+ },
32
+ {
33
+ "role": "Human",
34
+ "content": "how does it compare to salsa?"
35
+ },
36
+ {
37
+ "role": "AI",
38
+ "content": "Electronic music is a broad genre that encompasses many different styles, so there is no one \"right\" way to dance to it."
39
+ },
40
+ {
41
+ "role": "Human",
42
+ "content": "how do you dance electronic music?"
43
+ },
44
+ {
45
+ "role": "AI",
46
+ "content": "Colombia has a vibrant electronic music scene, and there are many talented DJs and producers who have gained international recognition."
47
+ },
48
+ {
49
+ "role": "Human",
50
+ "content": "What are some famous djs from Colombia?"
51
+ },
52
+ {
53
+ "role": "AI",
54
+ "content": "Baum opened its doors in 2014 and has quickly become one of the most popular clubs for electronic music in Bogotá."
55
+ }
56
+ ],
57
+ "context": "The conversation covers topics such as clubs for electronic music in Bogotá, popular tourist attractions in the city, and general information about Colombia. The AI provides information about popular electronic music clubs such as Baum and Video Club, as well as electronic music festivals that take place in Bogotá. The AI also recommends tourist attractions such as La Candelaria, Monserrate and the Salt Cathedral of Zipaquirá, and provides general information about Colombia's diverse culture, landscape and wildlife.",
58
+ "tokens": 744 // tokens used for incremental summarization
59
+ }
60
+ ```
61
+
62
+ - POST `/sessions/:id/memory` - Send an array of messages to Motorhead to store.
63
+
64
+ ```bash
65
+ curl --location 'localhost:8080/sessions/${SESSION_ID}/memory' \
66
+ --header 'Content-Type: application/json' \
67
+ --data '{
68
+ "messages": [{ "role": "Human", "content": "ping" }, { "role": "AI", "content": "pong" }]
69
+ }'
70
+ ```
71
+
72
+ Either an existing or new `SESSION_ID` can be used when storing messages, and the session is automatically created if it did not previously exist.
73
+
74
+ Optionally, `context` can be send in if it needs to get loaded from another datastore.
75
+
76
+ - DELETE `/sessions/:id/memory` - deletes the session's message list.
77
+
78
+ A max `window_size` is set for the LLM to keep track of the conversation. Once that max is hit, Motorhead will process (`window_size / 2` messages) and summarize them. Subsequent summaries, as the messages grow, are incremental.
79
+
80
+ - POST `/sessions/:id/retrieval` - searches by text query using VSS.
81
+
82
+ ```bash
83
+ curl --location 'localhost:8080/sessions/${SESSION_ID}/retrieval' \
84
+ --header 'Content-Type: application/json' \
85
+ --data '{
86
+ "text": "Generals gathered in their masses, just like witches in black masses"
87
+ }'
88
+
89
+ ```
90
+
91
+ Searches are segmented (filtered) by the session id provided automatically.
92
+
93
+ ## Config
94
+
95
+ - `MOTORHEAD_MAX_WINDOW_SIZE` (default:12) - Number of max messages returned by the server. When this number is reached, a job is triggered to halve it.
96
+ - `MOTORHEAD_LONG_TERM_MEMORY` (default:false) - Enables long term memory using Redisearch VSS.
97
+ - `MOTORHEAD_MODEL` (default:gpt-3.5-turbo) - Model used to run the incremental summarization. Use `gpt-3.5-turbo` or `gpt-4` - otherwise some weird things might happen.
98
+ - `PORT` (default:8000) - Motorhead Server Port
99
+ - `OPENAI_API_KEY`- [Your api key](https://platform.openai.com/account/api-keys) to connect to OpenAI. Required if not an Azure deploymnet or if `MOTORHEAD_LONG_TERM_MEMORY` is set to `true`.
100
+ - `REDIS_URL` (required)- URL used to connect to `redis`.
101
+
102
+ ### Azure deployment
103
+
104
+ *NOTE: `MOTORHEAD_LONG_TERM_MEMORY=true` won't work with Azure*. Additional Environment Variables are required for Azure deployments:
105
+
106
+ - `AZURE_DEPLOYMENT_ID`
107
+ - `AZURE_API_BASE`
108
+ - `AZURE_API_KEY`
109
+
110
+ ## How to run
111
+
112
+ With docker-compose:
113
+ ```bash
114
+ docker-compose build && docker-compose up
115
+ ```
116
+
117
+ Or you can use the image `docker pull ghcr.io/getmetal/motorhead:latest` directly:
118
+ ```bash
119
+ docker run --name motorhead -p 8080:8080 -e PORT=8080 -e REDIS_URL='redis://redis:6379' -d ghcr.io/getmetal/motorhead:latest
120
+ ```
121
+
122
+ ## Examples
123
+
124
+ - [Chat JS Example](examples/chat-js/)
125
+ - [Chat JS Vanilla Example](examples/chat-vanilla-js/)
126
+ - [Chat JS Vanilla Hosted Example](examples/chat-vanilla-js-hosted/)
127
+ - [Chat Python Example](examples/chat-py/)
docker-compose.yml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3'
2
+ services:
3
+ motorhead:
4
+ build: ./
5
+ ports:
6
+ - '8080:8080'
7
+ links:
8
+ - redis
9
+ environment:
10
+ PORT: 8080
11
+ MOTORHEAD_MAX_WINDOW_SIZE: 25
12
+ MOTORHEAD_LONG_TERM_MEMORY: 'true'
13
+ MOTORHEAD_MODEL: 'gpt-3.5-turbo'
14
+ REDIS_URL: 'redis://redis:6379'
15
+ env_file:
16
+ - .env
17
+
18
+ redis:
19
+ image: redis/redis-stack-server:latest
20
+ ports:
21
+ - '6379:6379'
src/healthcheck.rs ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use crate::models::HealthCheckResponse;
2
+ use actix_web::{get, web, Responder};
3
+ use std::time::{SystemTime, UNIX_EPOCH};
4
+
5
+ #[get("/")]
6
+ pub async fn get_health() -> actix_web::Result<impl Responder> {
7
+ let ms = SystemTime::now()
8
+ .duration_since(UNIX_EPOCH)
9
+ .unwrap()
10
+ .as_millis();
11
+
12
+ let res = HealthCheckResponse { now: ms };
13
+
14
+ Ok(web::Json(res))
15
+ }
src/long_term_memory.rs ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use crate::models::{parse_redisearch_response, AnyOpenAIClient, MemoryMessage, RedisearchResult};
2
+ use byteorder::{LittleEndian, WriteBytesExt};
3
+ use nanoid::nanoid;
4
+ use redis::Value;
5
+ use std::io::Cursor;
6
+
7
+ fn encode(fs: Vec<f32>) -> Vec<u8> {
8
+ let mut buf = Cursor::new(Vec::new());
9
+ for f in fs {
10
+ buf.write_f32::<LittleEndian>(f).unwrap();
11
+ }
12
+ buf.into_inner()
13
+ }
14
+
15
+ pub async fn index_messages(
16
+ messages: Vec<MemoryMessage>,
17
+ session_id: String,
18
+ openai_client: &AnyOpenAIClient,
19
+ mut redis_conn: redis::aio::ConnectionManager,
20
+ ) -> Result<(), Box<dyn std::error::Error>> {
21
+ let contents: Vec<String> = messages.iter().map(|msg| msg.content.clone()).collect();
22
+ let embeddings = openai_client.create_embedding(contents.clone()).await?;
23
+
24
+ // TODO add used tokens let tokens_used = response.usage.total_tokens;
25
+ for (index, embedding) in embeddings.iter().enumerate() {
26
+ let id = nanoid!();
27
+ let key = format!("motorhead:{}", id);
28
+ let vector = encode(embedding.to_vec());
29
+
30
+ redis::cmd("HSET")
31
+ .arg(key)
32
+ .arg("session")
33
+ .arg(&session_id)
34
+ .arg("vector")
35
+ .arg(vector)
36
+ .arg("content")
37
+ .arg(&contents[index])
38
+ .arg("role")
39
+ .arg(&messages[index].role)
40
+ .query_async::<_, ()>(&mut redis_conn)
41
+ .await?;
42
+ }
43
+
44
+ Ok(())
45
+ }
46
+
47
+ pub async fn search_messages(
48
+ query: String,
49
+ session_id: String,
50
+ openai_client: &AnyOpenAIClient,
51
+ mut redis_conn: redis::aio::ConnectionManager,
52
+ ) -> Result<Vec<RedisearchResult>, Box<dyn std::error::Error>> {
53
+ let response = openai_client.create_embedding(vec![query]).await?;
54
+ let embeddings = response[0].clone();
55
+ let vector = encode(embeddings);
56
+ let query = format!("@session:{}=>[KNN 10 @vector $V AS dist]", session_id);
57
+
58
+ let values: Vec<Value> = redis::cmd("FT.SEARCH")
59
+ .arg("motorhead")
60
+ .arg(query)
61
+ .arg("PARAMS")
62
+ .arg("2")
63
+ .arg("V")
64
+ .arg(vector)
65
+ .arg("RETURN")
66
+ .arg("3")
67
+ .arg("role")
68
+ .arg("content")
69
+ .arg("dist")
70
+ .arg("SORTBY")
71
+ .arg("dist")
72
+ .arg("DIALECT")
73
+ .arg("2")
74
+ .query_async(&mut redis_conn)
75
+ .await?;
76
+
77
+ let array_value = redis::Value::Bulk(values);
78
+ let results = parse_redisearch_response(&array_value);
79
+
80
+ Ok(results)
81
+ }
src/main.rs ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mod healthcheck;
2
+ mod long_term_memory;
3
+ mod memory;
4
+ mod models;
5
+ mod redis_utils;
6
+ mod reducer;
7
+ mod retrieval;
8
+
9
+ use actix_web::{error, middleware, web, App, HttpResponse, HttpServer};
10
+ use healthcheck::get_health;
11
+ use memory::{delete_memory, get_memory, get_sessions, post_memory};
12
+ use models::{AppState, OpenAIClientManager};
13
+ use redis_utils::ensure_redisearch_index;
14
+ use retrieval::run_retrieval;
15
+ use std::collections::HashMap;
16
+ use std::env;
17
+ use std::io;
18
+ use std::sync::Arc;
19
+ use tokio::sync::Mutex;
20
+
21
+ #[actix_web::main]
22
+ async fn main() -> io::Result<()> {
23
+ env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
24
+
25
+ log::info!("Starting Motorhead 🤘");
26
+
27
+ let manager = OpenAIClientManager {};
28
+ let max_size = 8;
29
+ let openai_pool = deadpool::managed::Pool::builder(manager)
30
+ .max_size(max_size)
31
+ .build()
32
+ .unwrap();
33
+
34
+ let redis_url = env::var("REDIS_URL").expect("$REDIS_URL is not set");
35
+ let redis = redis::Client::open(redis_url).unwrap();
36
+
37
+ let long_term_memory = env::var("MOTORHEAD_LONG_TERM_MEMORY")
38
+ .map(|value| value.to_lowercase() == "true")
39
+ .unwrap_or(false);
40
+
41
+ if long_term_memory {
42
+ // TODO: Make these configurable - for now just ADA support
43
+ let vector_dimensions = 1536;
44
+ let distance_metric = "COSINE";
45
+
46
+ ensure_redisearch_index(&redis, vector_dimensions, distance_metric).unwrap_or_else(|err| {
47
+ eprintln!("RediSearch index error: {}", err);
48
+ std::process::exit(1);
49
+ });
50
+ }
51
+
52
+ let port = env::var("PORT")
53
+ .ok()
54
+ .and_then(|s| s.parse::<u16>().ok())
55
+ .unwrap_or(8000);
56
+
57
+ let window_size = env::var("MOTORHEAD_MAX_WINDOW_SIZE")
58
+ .ok()
59
+ .and_then(|s| s.parse::<i64>().ok())
60
+ .unwrap_or(12);
61
+ let model = env::var("MOTORHEAD_MODEL").unwrap_or_else(|_| "gpt-3.5-turbo".to_string());
62
+
63
+ let session_cleanup = Arc::new(Mutex::new(HashMap::new()));
64
+ let session_state = Arc::new(AppState {
65
+ window_size,
66
+ session_cleanup,
67
+ openai_pool,
68
+ long_term_memory,
69
+ model,
70
+ });
71
+
72
+ async fn on_start_logger(port: u16) -> io::Result<()> {
73
+ println!();
74
+ println!("-----------------------------------");
75
+ println!("🧠 Motorhead running on port: {}", port);
76
+ println!("-----------------------------------");
77
+ println!();
78
+
79
+ Ok(())
80
+ }
81
+
82
+ let server = HttpServer::new(move || {
83
+ App::new()
84
+ .app_data(web::Data::new(redis.clone()))
85
+ .app_data(web::Data::new(session_state.clone()))
86
+ .wrap(middleware::Logger::default())
87
+ .service(get_health)
88
+ .service(get_memory)
89
+ .service(post_memory)
90
+ .service(delete_memory)
91
+ .service(get_sessions)
92
+ .service(run_retrieval)
93
+ .app_data(web::JsonConfig::default().error_handler(|err, _req| {
94
+ error::InternalError::from_response(
95
+ "",
96
+ HttpResponse::BadRequest()
97
+ .content_type("application/json")
98
+ .body(format!(r#"{{"error":"{}"}}"#, err)),
99
+ )
100
+ .into()
101
+ }))
102
+ })
103
+ .bind(("0.0.0.0", port))?
104
+ .run();
105
+
106
+ let server_future = server;
107
+ let logger_future = on_start_logger(port);
108
+
109
+ let (server_result, logger_result) = tokio::join!(server_future, logger_future);
110
+
111
+ // Handle the Result from server
112
+ if let Err(e) = server_result {
113
+ eprintln!("Server error: {}", e);
114
+ }
115
+
116
+ // Handle the Result from logger
117
+ if let Err(e) = logger_result {
118
+ eprintln!("Logger error: {}", e);
119
+ }
120
+
121
+ Ok(())
122
+ }
src/memory.rs ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use crate::long_term_memory::index_messages;
2
+ use crate::models::{
3
+ AckResponse, AppState, GetSessionsQuery, MemoryMessage, MemoryMessagesAndContext,
4
+ MemoryResponse, NamespaceQuery,
5
+ };
6
+ use crate::reducer::handle_compaction;
7
+ use actix_web::{delete, error, get, post, web, HttpResponse, Responder};
8
+ use std::ops::Deref;
9
+ use std::sync::Arc;
10
+
11
+ #[get("/sessions")]
12
+ pub async fn get_sessions(
13
+ web::Query(pagination): web::Query<GetSessionsQuery>,
14
+ _data: web::Data<Arc<AppState>>,
15
+ redis: web::Data<redis::Client>,
16
+ ) -> actix_web::Result<impl Responder> {
17
+ let GetSessionsQuery {
18
+ page,
19
+ size,
20
+ namespace,
21
+ } = pagination;
22
+
23
+ if page > 100 {
24
+ return Err(actix_web::error::ErrorBadRequest(
25
+ "Page size must not exceed 100",
26
+ ));
27
+ }
28
+
29
+ let start: isize = ((page - 1) * size) as isize; // 0-indexed
30
+ let end: isize = (page * size - 1) as isize; // inclusive
31
+
32
+ let mut conn = redis
33
+ .get_tokio_connection_manager()
34
+ .await
35
+ .map_err(error::ErrorInternalServerError)?;
36
+
37
+ let sessions_key = match &namespace {
38
+ Some(namespace) => format!("sessions:{}", namespace),
39
+ None => String::from("sessions"),
40
+ };
41
+
42
+ let session_ids: Vec<String> = redis::cmd("ZRANGE")
43
+ .arg(sessions_key)
44
+ .arg(start)
45
+ .arg(end)
46
+ .query_async(&mut conn)
47
+ .await
48
+ .map_err(error::ErrorInternalServerError)?;
49
+
50
+ Ok(HttpResponse::Ok()
51
+ .content_type("application/json")
52
+ .json(session_ids))
53
+ }
54
+
55
+ #[get("/sessions/{session_id}/memory")]
56
+ pub async fn get_memory(
57
+ session_id: web::Path<String>,
58
+ data: web::Data<Arc<AppState>>,
59
+ redis: web::Data<redis::Client>,
60
+ ) -> actix_web::Result<impl Responder> {
61
+ let mut conn = redis
62
+ .get_tokio_connection_manager()
63
+ .await
64
+ .map_err(error::ErrorInternalServerError)?;
65
+
66
+ let lrange_key = format!("session:{}", &*session_id);
67
+ let context_key = format!("context:{}", &*session_id);
68
+ let token_count_key = format!("tokens:{}", &*session_id);
69
+ let keys = vec![context_key, token_count_key];
70
+
71
+ let (messages, values): (Vec<String>, Vec<Option<String>>) = redis::pipe()
72
+ .cmd("LRANGE")
73
+ .arg(lrange_key)
74
+ .arg(0)
75
+ .arg(data.window_size as isize)
76
+ .cmd("MGET")
77
+ .arg(keys)
78
+ .query_async(&mut conn)
79
+ .await
80
+ .map_err(error::ErrorInternalServerError)?;
81
+
82
+ let context = values.get(0).cloned().flatten();
83
+ let tokens = values
84
+ .get(1)
85
+ .cloned()
86
+ .flatten()
87
+ .and_then(|tokens_string| tokens_string.parse::<i64>().ok())
88
+ .unwrap_or(0);
89
+
90
+ let messages: Vec<MemoryMessage> = messages
91
+ .into_iter()
92
+ .filter_map(|message| {
93
+ let mut parts = message.splitn(2, ": ");
94
+ match (parts.next(), parts.next()) {
95
+ (Some(role), Some(content)) => Some(MemoryMessage {
96
+ role: role.to_string(),
97
+ content: content.to_string(),
98
+ }),
99
+ _ => None,
100
+ }
101
+ })
102
+ .collect();
103
+
104
+ let response = MemoryResponse {
105
+ messages,
106
+ context,
107
+ tokens: Some(tokens),
108
+ };
109
+
110
+ Ok(HttpResponse::Ok()
111
+ .content_type("application/json")
112
+ .json(response))
113
+ }
114
+
115
+ #[post("/sessions/{session_id}/memory")]
116
+ pub async fn post_memory(
117
+ session_id: web::Path<String>,
118
+ web::Json(memory_messages): web::Json<MemoryMessagesAndContext>,
119
+ data: web::Data<Arc<AppState>>,
120
+ redis: web::Data<redis::Client>,
121
+ web::Query(namespace_query): web::Query<NamespaceQuery>,
122
+ ) -> actix_web::Result<impl Responder> {
123
+ let mut conn = redis
124
+ .get_tokio_connection_manager()
125
+ .await
126
+ .map_err(error::ErrorInternalServerError)?;
127
+
128
+ let memory_messages_clone: Vec<MemoryMessage> = memory_messages.messages.to_vec();
129
+
130
+ let messages: Vec<String> = memory_messages
131
+ .messages
132
+ .into_iter()
133
+ .map(|memory_message| format!("{}: {}", memory_message.role, memory_message.content))
134
+ .collect();
135
+
136
+ // If new context is passed in we overwrite the existing one
137
+ if let Some(context) = memory_messages.context {
138
+ redis::Cmd::set(format!("context:{}", &*session_id), context)
139
+ .query_async::<_, ()>(&mut conn)
140
+ .await
141
+ .map_err(error::ErrorInternalServerError)?;
142
+ }
143
+
144
+ let sessions_key = match namespace_query.namespace {
145
+ Some(namespace) => format!("sessions:{}", namespace),
146
+ None => String::from("sessions"),
147
+ };
148
+
149
+ // add to sorted set of sessions
150
+ redis::cmd("ZADD")
151
+ .arg(sessions_key)
152
+ .arg(chrono::Utc::now().timestamp())
153
+ .arg(&*session_id)
154
+ .query_async(&mut conn)
155
+ .await
156
+ .map_err(error::ErrorInternalServerError)?;
157
+
158
+ let res: i64 = redis::Cmd::lpush(format!("session:{}", &*session_id), messages.clone())
159
+ .query_async::<_, i64>(&mut conn)
160
+ .await
161
+ .map_err(error::ErrorInternalServerError)?;
162
+
163
+ if data.long_term_memory {
164
+ let session = session_id.clone();
165
+ let conn_clone = conn.clone();
166
+ let pool = data.openai_pool.clone();
167
+
168
+ tokio::spawn(async move {
169
+ let client_wrapper = pool.get().await.unwrap();
170
+ let client = client_wrapper.deref();
171
+ if let Err(e) = index_messages(memory_messages_clone, session, client, conn_clone).await
172
+ {
173
+ log::error!("Error in index_messages: {:?}", e);
174
+ }
175
+ });
176
+ }
177
+
178
+ if res > data.window_size {
179
+ let state = data.into_inner();
180
+ let mut session_cleanup = state.session_cleanup.lock().await;
181
+
182
+ if !session_cleanup.get(&*session_id).unwrap_or(&false) {
183
+ session_cleanup.insert((&*session_id.to_string()).into(), true);
184
+ let session_cleanup = Arc::clone(&state.session_cleanup);
185
+ let session_id = session_id.clone();
186
+ let window_size = state.window_size;
187
+ let model = state.model.to_string();
188
+ let pool = state.openai_pool.clone();
189
+
190
+ tokio::spawn(async move {
191
+ log::info!("running compact");
192
+ let client_wrapper = pool.get().await.unwrap();
193
+ let client = client_wrapper.deref();
194
+
195
+ let _compaction_result =
196
+ handle_compaction(session_id.to_string(), model, window_size, client, conn)
197
+ .await;
198
+
199
+ let mut lock = session_cleanup.lock().await;
200
+ lock.remove(&session_id);
201
+ });
202
+ }
203
+ }
204
+
205
+ let response = AckResponse { status: "Ok" };
206
+ Ok(HttpResponse::Ok()
207
+ .content_type("application/json")
208
+ .json(response))
209
+ }
210
+
211
+ #[delete("/sessions/{session_id}/memory")]
212
+ pub async fn delete_memory(
213
+ session_id: web::Path<String>,
214
+ redis: web::Data<redis::Client>,
215
+ web::Query(namespace_query): web::Query<NamespaceQuery>,
216
+ ) -> actix_web::Result<impl Responder> {
217
+ let mut conn = redis
218
+ .get_tokio_connection_manager()
219
+ .await
220
+ .map_err(error::ErrorInternalServerError)?;
221
+
222
+ let context_key = format!("context:{}", &*session_id);
223
+ let token_count_key = format!("tokens:{}", &*session_id);
224
+ let session_key = format!("session:{}", &*session_id);
225
+ let keys = vec![context_key, session_key, token_count_key];
226
+
227
+ let sessions_key = match namespace_query.namespace {
228
+ Some(namespace) => format!("sessions:{}", namespace),
229
+ None => String::from("sessions"),
230
+ };
231
+
232
+ redis::cmd("ZREM")
233
+ .arg(sessions_key)
234
+ .arg(&*session_id)
235
+ .query_async(&mut conn)
236
+ .await
237
+ .map_err(error::ErrorInternalServerError)?;
238
+
239
+ redis::Cmd::del(keys)
240
+ .query_async(&mut conn)
241
+ .await
242
+ .map_err(error::ErrorInternalServerError)?;
243
+
244
+ let response = AckResponse { status: "Ok" };
245
+ Ok(HttpResponse::Ok()
246
+ .content_type("application/json")
247
+ .json(response))
248
+ }
src/models.rs ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use async_openai::{
2
+ config::{AzureConfig, OpenAIConfig},
3
+ error::OpenAIError,
4
+ types::{
5
+ ChatCompletionRequestMessageArgs, CreateChatCompletionRequestArgs,
6
+ CreateChatCompletionResponse, CreateEmbeddingRequestArgs, Role,
7
+ },
8
+ Client,
9
+ };
10
+ use async_trait::async_trait;
11
+ use deadpool::managed::{Manager, RecycleResult};
12
+ use futures_util::future::try_join_all;
13
+ use redis::{FromRedisValue, RedisError, Value};
14
+ use serde::{Deserialize, Serialize};
15
+ use std::collections::HashMap;
16
+ use std::env;
17
+ use std::error::Error;
18
+ use std::sync::Arc;
19
+ use tokio::sync::Mutex;
20
+
21
+ pub struct OpenAIClientManager {}
22
+
23
+ #[async_trait]
24
+ impl Manager for OpenAIClientManager {
25
+ type Type = AnyOpenAIClient;
26
+ type Error = MotorheadError;
27
+
28
+ async fn create(&self) -> Result<AnyOpenAIClient, MotorheadError> {
29
+ let openai_client = match (
30
+ env::var("AZURE_API_KEY"),
31
+ env::var("AZURE_DEPLOYMENT_ID"),
32
+ env::var("AZURE_API_BASE"),
33
+ ) {
34
+ (Ok(azure_api_key), Ok(azure_deployment_id), Ok(azure_api_base)) => {
35
+ let config = AzureConfig::new()
36
+ .with_api_base(azure_api_base)
37
+ .with_api_key(azure_api_key)
38
+ .with_deployment_id(azure_deployment_id)
39
+ .with_api_version("2023-05-15");
40
+ AnyOpenAIClient::Azure(Client::with_config(config))
41
+ }
42
+ _ => AnyOpenAIClient::OpenAI(Client::new()),
43
+ };
44
+ Ok(openai_client)
45
+ }
46
+
47
+ async fn recycle(&self, _: &mut AnyOpenAIClient) -> RecycleResult<MotorheadError> {
48
+ Ok(())
49
+ }
50
+ }
51
+
52
+ pub enum AnyOpenAIClient {
53
+ Azure(Client<AzureConfig>),
54
+ OpenAI(Client<OpenAIConfig>),
55
+ }
56
+
57
+ impl AnyOpenAIClient {
58
+ pub async fn create_chat_completion(
59
+ &self,
60
+ model: &str,
61
+ progresive_prompt: &str,
62
+ ) -> Result<CreateChatCompletionResponse, OpenAIError> {
63
+ let request = CreateChatCompletionRequestArgs::default()
64
+ .max_tokens(512u16)
65
+ .model(model)
66
+ .messages([ChatCompletionRequestMessageArgs::default()
67
+ .role(Role::User)
68
+ .content(progresive_prompt)
69
+ .build()?])
70
+ .build()?;
71
+
72
+ match self {
73
+ AnyOpenAIClient::Azure(client) => client.chat().create(request).await,
74
+ AnyOpenAIClient::OpenAI(client) => client.chat().create(request).await,
75
+ }
76
+ }
77
+
78
+ pub async fn create_embedding(
79
+ &self,
80
+ query_vec: Vec<String>,
81
+ ) -> Result<Vec<Vec<f32>>, OpenAIError> {
82
+ match self {
83
+ AnyOpenAIClient::OpenAI(client) => {
84
+ let request = CreateEmbeddingRequestArgs::default()
85
+ .model("text-embedding-ada-002")
86
+ .input(query_vec)
87
+ .build()?;
88
+
89
+ let response = client.embeddings().create(request).await?;
90
+ let embeddings: Vec<_> = response
91
+ .data
92
+ .iter()
93
+ .map(|data| data.embedding.clone())
94
+ .collect();
95
+
96
+ Ok(embeddings)
97
+ }
98
+ AnyOpenAIClient::Azure(client) => {
99
+ let tasks: Vec<_> = query_vec
100
+ .into_iter()
101
+ .map(|query| async {
102
+ let request = CreateEmbeddingRequestArgs::default()
103
+ .model("text-embedding-ada-002")
104
+ .input(vec![query])
105
+ .build()?;
106
+
107
+ client.embeddings().create(request).await
108
+ })
109
+ .collect();
110
+
111
+ let responses: Result<Vec<_>, _> = try_join_all(tasks).await;
112
+
113
+ match responses {
114
+ Ok(successful_responses) => {
115
+ let embeddings: Vec<_> = successful_responses
116
+ .into_iter()
117
+ .flat_map(|response| response.data.into_iter())
118
+ .map(|data| data.embedding)
119
+ .collect();
120
+
121
+ Ok(embeddings)
122
+ }
123
+ Err(err) => Err(err),
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ pub struct AppState {
131
+ pub window_size: i64,
132
+ pub session_cleanup: Arc<Mutex<HashMap<String, bool>>>,
133
+ pub openai_pool: deadpool::managed::Pool<OpenAIClientManager>,
134
+ pub long_term_memory: bool,
135
+ pub model: String,
136
+ }
137
+
138
+ #[derive(Serialize, Deserialize)]
139
+ pub struct SearchPayload {
140
+ pub text: String,
141
+ }
142
+
143
+ #[derive(Serialize, Deserialize, Clone)]
144
+ pub struct MemoryMessage {
145
+ pub role: String,
146
+ pub content: String,
147
+ }
148
+
149
+ #[derive(Deserialize)]
150
+ pub struct MemoryMessagesAndContext {
151
+ pub messages: Vec<MemoryMessage>,
152
+ pub context: Option<String>,
153
+ }
154
+
155
+ #[derive(Serialize)]
156
+ pub struct MemoryResponse {
157
+ pub messages: Vec<MemoryMessage>,
158
+ pub context: Option<String>,
159
+ pub tokens: Option<i64>,
160
+ }
161
+
162
+ #[derive(Serialize)]
163
+ pub struct HealthCheckResponse {
164
+ pub now: u128,
165
+ }
166
+
167
+ #[derive(Serialize)]
168
+ pub struct AckResponse {
169
+ pub status: &'static str,
170
+ }
171
+
172
+ #[derive(Debug)]
173
+ pub enum MotorheadError {
174
+ RedisError(RedisError),
175
+ IncrementalSummarizationError(String),
176
+ }
177
+
178
+ impl std::fmt::Display for MotorheadError {
179
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
180
+ match self {
181
+ MotorheadError::RedisError(e) => write!(f, "Redis error: {}", e),
182
+ MotorheadError::IncrementalSummarizationError(e) => {
183
+ write!(f, "Incremental summarization error: {}", e)
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ impl From<Box<dyn Error + Send + Sync>> for MotorheadError {
190
+ fn from(error: Box<dyn Error + Send + Sync>) -> Self {
191
+ MotorheadError::IncrementalSummarizationError(error.to_string())
192
+ }
193
+ }
194
+
195
+ impl From<RedisError> for MotorheadError {
196
+ fn from(err: RedisError) -> Self {
197
+ MotorheadError::RedisError(err)
198
+ }
199
+ }
200
+
201
+ impl std::error::Error for MotorheadError {}
202
+
203
+ #[derive(Serialize, Deserialize, Debug)]
204
+ pub struct RedisearchResult {
205
+ pub role: String,
206
+ pub content: String,
207
+ pub dist: f64,
208
+ }
209
+
210
+ impl FromRedisValue for RedisearchResult {
211
+ fn from_redis_value(v: &Value) -> redis::RedisResult<Self> {
212
+ let values: Vec<String> = redis::from_redis_value(v)?;
213
+ let mut content = String::new();
214
+ let mut role = String::new();
215
+ let mut dist = 0.0;
216
+
217
+ for i in 0..values.len() {
218
+ match values[i].as_str() {
219
+ "content" => content = values[i + 1].clone(),
220
+ "role" => role = values[i + 1].clone(),
221
+ "dist" => dist = values[i + 1].parse::<f64>().unwrap_or(0.0),
222
+ _ => continue,
223
+ }
224
+ }
225
+
226
+ Ok(RedisearchResult {
227
+ role,
228
+ content,
229
+ dist,
230
+ })
231
+ }
232
+ }
233
+
234
+ pub fn parse_redisearch_response(response: &Value) -> Vec<RedisearchResult> {
235
+ match response {
236
+ Value::Bulk(array) => {
237
+ let mut results = Vec::new();
238
+ let n = array.len();
239
+
240
+ for item in array.iter().take(n).skip(1) {
241
+ if let Value::Bulk(ref bulk) = item {
242
+ if let Ok(result) =
243
+ RedisearchResult::from_redis_value(&Value::Bulk(bulk.clone()))
244
+ {
245
+ results.push(result);
246
+ }
247
+ }
248
+ }
249
+
250
+ results
251
+ }
252
+ _ => vec![],
253
+ }
254
+ }
255
+
256
+ #[derive(serde::Deserialize)]
257
+ pub struct NamespaceQuery {
258
+ pub namespace: Option<String>,
259
+ }
260
+
261
+ #[derive(serde::Deserialize)]
262
+ pub struct GetSessionsQuery {
263
+ #[serde(default = "default_page")]
264
+ pub page: usize,
265
+ #[serde(default = "default_size")]
266
+ pub size: usize,
267
+ pub namespace: Option<String>,
268
+ }
269
+
270
+ fn default_page() -> usize {
271
+ 1
272
+ }
273
+
274
+ fn default_size() -> usize {
275
+ 10
276
+ }
src/redis_utils.rs ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use redis::{self, RedisResult};
2
+
3
+ pub fn ensure_redisearch_index(
4
+ redis: &redis::Client,
5
+ vector_dimensions: usize,
6
+ distance_metric: &str,
7
+ ) -> RedisResult<()> {
8
+ let mut con = redis.get_connection()?;
9
+ let index_name = "motorhead";
10
+
11
+ let index_info: Result<redis::Value, _> = redis::cmd("FT.INFO").arg(index_name).query(&mut con);
12
+
13
+ if let Err(err) = index_info {
14
+ if err.to_string().contains("Unknown: Index name") {
15
+ redis::cmd("FT.CREATE")
16
+ .arg(index_name)
17
+ .arg("ON")
18
+ .arg("HASH")
19
+ .arg("PREFIX")
20
+ .arg("1")
21
+ .arg("motorhead:")
22
+ .arg("SCHEMA")
23
+ .arg("session")
24
+ .arg("TEXT")
25
+ .arg("content")
26
+ .arg("TEXT")
27
+ .arg("role")
28
+ .arg("TEXT")
29
+ .arg("vector")
30
+ .arg("VECTOR")
31
+ .arg("HNSW")
32
+ .arg("6")
33
+ .arg("TYPE")
34
+ .arg("FLOAT32")
35
+ .arg("DIM")
36
+ .arg(vector_dimensions.to_string())
37
+ .arg("DISTANCE_METRIC")
38
+ .arg(distance_metric)
39
+ .query(&mut con)?;
40
+ } else {
41
+ return Err(err);
42
+ }
43
+ }
44
+
45
+ Ok(())
46
+ }
src/reducer.rs ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use crate::models::{AnyOpenAIClient, MotorheadError};
2
+ use std::error::Error;
3
+ use tiktoken_rs::p50k_base;
4
+
5
+ pub async fn incremental_summarization(
6
+ model: String,
7
+ openai_client: &AnyOpenAIClient,
8
+ context: Option<String>,
9
+ mut messages: Vec<String>,
10
+ ) -> Result<(String, u32), Box<dyn Error + Send + Sync>> {
11
+ messages.reverse();
12
+ let messages_joined = messages.join("\n");
13
+ let prev_summary = context.as_deref().unwrap_or_default();
14
+ // Taken from langchain
15
+ let progresive_prompt = format!(
16
+ r#"
17
+ Progressively summarize the lines of conversation provided, adding onto the previous summary returning a new summary. If the lines are meaningless just return NONE
18
+
19
+ EXAMPLE
20
+ Current summary:
21
+ The human asks who is the lead singer of Motorhead. The AI responds Lemmy Kilmister.
22
+ New lines of conversation:
23
+ Human: What are the other members of Motorhead?
24
+ AI: The original members included Lemmy Kilmister (vocals, bass), Larry Wallis (guitar), and Lucas Fox (drums), with notable members throughout the years including \"Fast\" Eddie Clarke (guitar), Phil \"Philthy Animal\" Taylor (drums), and Mikkey Dee (drums).
25
+ New summary:
26
+ The human asks who is the lead singer and other members of Motorhead. The AI responds Lemmy Kilmister is the lead singer and other original members include Larry Wallis, and Lucas Fox, with notable past members including \"Fast\" Eddie Clarke, Phil \"Philthy Animal\" Taylor, and Mikkey Dee.
27
+ END OF EXAMPLE
28
+
29
+ Current summary:
30
+ {prev_summary}
31
+ New lines of conversation:
32
+ {messages_joined}
33
+ New summary:
34
+ "#
35
+ );
36
+
37
+ let response = openai_client
38
+ .create_chat_completion(&model, &progresive_prompt)
39
+ .await?;
40
+
41
+ let completion = response
42
+ .choices
43
+ .first()
44
+ .ok_or("No completion found")?
45
+ .message
46
+ .content
47
+ .clone();
48
+
49
+ let usage = response.usage.ok_or("No Usage found")?;
50
+ let tokens_used = usage.total_tokens;
51
+
52
+ Ok((completion, tokens_used))
53
+ }
54
+
55
+ pub async fn handle_compaction(
56
+ session_id: String,
57
+ model: String,
58
+ window_size: i64,
59
+ openai_client: &AnyOpenAIClient,
60
+ mut redis_conn: redis::aio::ConnectionManager,
61
+ ) -> Result<(), MotorheadError> {
62
+ let half = window_size / 2;
63
+ let session_key = format!("session:{}", &*session_id);
64
+ let context_key = format!("context:{}", &*session_id);
65
+ let (messages, mut context): (Vec<String>, Option<String>) = redis::pipe()
66
+ .cmd("LRANGE")
67
+ .arg(session_key.clone())
68
+ .arg(half)
69
+ .arg(window_size)
70
+ .cmd("GET")
71
+ .arg(context_key.clone())
72
+ .query_async(&mut redis_conn)
73
+ .await?;
74
+
75
+ let max_tokens = 4096usize;
76
+ let summary_max_tokens = 512usize;
77
+ let buffer_tokens = 230usize;
78
+ let max_message_tokens = max_tokens - summary_max_tokens - buffer_tokens;
79
+
80
+ let mut total_tokens = 0;
81
+ let mut temp_messages = Vec::new();
82
+ let mut total_tokens_temp = 0;
83
+
84
+ for message in messages {
85
+ let bpe = p50k_base().unwrap();
86
+ let message_tokens = bpe.encode_with_special_tokens(&message);
87
+ let message_tokens_used = message_tokens.len();
88
+
89
+ if total_tokens_temp + message_tokens_used <= max_message_tokens {
90
+ temp_messages.push(message);
91
+ total_tokens_temp += message_tokens_used;
92
+ } else {
93
+ let (summary, summary_tokens_used) = incremental_summarization(
94
+ model.to_string(),
95
+ openai_client,
96
+ context.clone(),
97
+ temp_messages,
98
+ )
99
+ .await?;
100
+
101
+ total_tokens += summary_tokens_used;
102
+
103
+ context = Some(summary);
104
+ temp_messages = vec![message];
105
+ total_tokens_temp = message_tokens_used;
106
+ }
107
+ }
108
+
109
+ if !temp_messages.is_empty() {
110
+ let (summary, summary_tokens_used) =
111
+ incremental_summarization(model, openai_client, context.clone(), temp_messages).await?;
112
+ total_tokens += summary_tokens_used;
113
+ context = Some(summary);
114
+ }
115
+
116
+ if let Some(new_context) = context {
117
+ let token_count_key = format!("tokens:{}", &*session_id);
118
+ let redis_pipe_response_result: Result<((), (), i64), redis::RedisError> = redis::pipe()
119
+ .cmd("LTRIM")
120
+ .arg(session_key)
121
+ .arg(0)
122
+ .arg(half)
123
+ .cmd("SET")
124
+ .arg(context_key)
125
+ .arg(new_context)
126
+ .cmd("INCRBY")
127
+ .arg(token_count_key)
128
+ .arg(total_tokens)
129
+ .query_async(&mut redis_conn)
130
+ .await;
131
+
132
+ match redis_pipe_response_result {
133
+ Ok(_) => Ok(()),
134
+ Err(e) => {
135
+ log::error!("Error executing the redis pipeline: {:?}", e);
136
+ Err(MotorheadError::RedisError(e))
137
+ }
138
+ }
139
+ } else {
140
+ log::error!("No context found after summarization");
141
+ Err(MotorheadError::IncrementalSummarizationError(
142
+ "No context found after summarization".to_string(),
143
+ ))
144
+ }
145
+ }
src/retrieval.rs ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use crate::long_term_memory::search_messages;
2
+ use crate::models::{AppState, SearchPayload};
3
+ use actix_web::{error, post, web, HttpResponse, Responder};
4
+ use std::ops::Deref;
5
+ use std::sync::Arc;
6
+
7
+ #[post("/sessions/{session_id}/retrieval")]
8
+ pub async fn run_retrieval(
9
+ session_id: web::Path<String>,
10
+ web::Json(payload): web::Json<SearchPayload>,
11
+ data: web::Data<Arc<AppState>>,
12
+ redis: web::Data<redis::Client>,
13
+ ) -> actix_web::Result<impl Responder> {
14
+ if !data.long_term_memory {
15
+ return Ok(HttpResponse::BadRequest().body("Long term memory is disabled"));
16
+ }
17
+
18
+ let conn = redis
19
+ .get_tokio_connection_manager()
20
+ .await
21
+ .map_err(error::ErrorInternalServerError)?;
22
+
23
+ let client_wrapper = data.openai_pool.get().await.unwrap();
24
+ let openai_client = client_wrapper.deref();
25
+
26
+ match search_messages(payload.text, session_id.clone(), openai_client, conn).await {
27
+ Ok(results) => Ok(HttpResponse::Ok().json(results)),
28
+ Err(e) => {
29
+ log::error!("Error Retrieval API: {:?}", e);
30
+ Ok(HttpResponse::InternalServerError().body("Internal server error"))
31
+ }
32
+ }
33
+ }