debgpt 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
debgpt-0.5.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mo Zhou <lumin@debian.org>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
debgpt-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,467 @@
1
+ Metadata-Version: 2.1
2
+ Name: debgpt
3
+ Version: 0.5.0
4
+ Summary: DebGPT -- Chatting LLM with Debian-Specific Knowledge
5
+ Author-email: Mo Zhou <lumin@debian.org>
6
+ License: MIT License
7
+ Project-URL: Homepage, https://salsa.debian.org/deeplearning-team/debgpt
8
+ Project-URL: Issues, https://salsa.debian.org/deeplearning-team/debgpt/-/issues
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: rich
13
+ Requires-Dist: prompt_toolkit
14
+ Requires-Dist: openai
15
+ Requires-Dist: requests
16
+ Requires-Dist: bs4
17
+ Requires-Dist: tomli
18
+
19
+ % DebGPT(1) | Chatting LLM with Debian-Specific Knowledge
20
+ % Copyright (C) 2024 Mo Zhou <lumin@debian.org>; MIT License.
21
+
22
+ NAME
23
+ ====
24
+
25
+ DebGPT - Chatting LLM with Debian-Specific Knowledge
26
+
27
+ > "AI" = "Artificial Idiot"
28
+
29
+
30
+ SYNOPSIS
31
+ ========
32
+
33
+ `debgpt [-h] [--quit] [--multiline] [--hide_first] [--verbose] [--output OUTPUT] [--version] [--debgpt_home DEBGPT_HOME]
34
+ [--frontend {dryrun,zmq,openai}] [--temperature TEMPERATURE] [--top_p TOP_P] [--openai_base_url OPENAI_BASE_URL]
35
+ [--openai_api_key OPENAI_API_KEY] [--openai_model OPENAI_MODEL] [--zmq_backend ZMQ_BACKEND] [--bts BTS] [--bts_raw] [--cmd CMD]
36
+ [--buildd BUILDD] [--file FILE] [--policy POLICY] [--devref DEVREF] [--tldr TLDR] [--ask ASK]
37
+ [SUBCOMMAND] ...`
38
+
39
+ DESCRIPTION
40
+ ===========
41
+
42
+ *This tool is currently experimental.*
43
+
44
+ Large language models (LLMs) are newly emerged tools, which are capable of
45
+ handling tasks that traditional software could never achieve, such as writing
46
+ code based on the specification provided by the user. With this tool, we
47
+ attempt to experiment and explore the possibility of leveraging LLMs to aid
48
+ Debian development, in any extent.
49
+
50
+ Essentially, the idea of this tool is to gather some pieces of
51
+ Debian-specific knowledge, combine them together in a prompt, and then send
52
+ them all to the LLM. This tool provides convenient functionality for
53
+ automatically retrieving information from BTS, buildd, Debian Policy, system
54
+ manual pages, tldr manuals, Debian Developer References, etc. It also provides
55
+ convenient wrappers for external tools such as git, where debgpt can
56
+ automatically generate the git commit message and commit the changes for you.
57
+
58
+ This tool supports multiple frontends, including OpenAI and ZMQ.
59
+ The ZMQ frontend/backend are provided in this tool to make it self-contained.
60
+
61
+
62
+ OPTIONS
63
+ =======
64
+
65
+ `-h, --help`
66
+ : show this help message and exit
67
+
68
+ `--cmd CMD`
69
+ : add the command line output to the prompt
70
+
71
+ `--monochrome <true|false>`
72
+ : disable colorized output during the conversation
73
+
74
+ TODO: add all cmd options here.
75
+
76
+ FRONTENDS
77
+ =========
78
+
79
+ The tool currently have three frontend implementations: `dryrun`, `openai`, and `zmq`.
80
+ They are specified through the `-F | --frontend` argument.
81
+
82
+ * `openai`: Connects with a OpenAI API-compatible
83
+ server. For instance, by specifying `--openai_base_url`, you can switch to
84
+ a different service provider than the default OpenAI API server.
85
+
86
+ * `llamafile`: Connects with a llamafile (single-file LLM distribution).
87
+ See https://github.com/Mozilla-Ocho/llamafile for more information.
88
+ This frontend is implemented in the OpenAI-API compatible way.
89
+ Setting up `--llamafile_base_url` to point to the llamafile service you want
90
+ to use should be enough.
91
+
92
+ * `ollama`: Connects with ollama service instance.
93
+ See https://github.com/ollama/ollama for more information.
94
+ We currently implement this frontend in the OpenAI-API compatible way.
95
+ Make sure to specify `--ollama_model` to the one being served by the ollama
96
+ service you point to with `--ollama_base_url`.
97
+
98
+ * `vllm`: Connects with a vllm service instance.
99
+ See https://docs.vllm.ai/en/latest/ for more information.
100
+ This is a OpenAI-API compatible self-hosted service.
101
+
102
+ * `zmq`: Connects with the built-in ZMQ backend.
103
+ The ZMQ backend is provided for self-hosted LLM inference server. This
104
+ implementation is very light weight, and not compatible with the OpenAI API.
105
+ To use this frontend, you may need to set up a corresponding ZMQ backend.
106
+
107
+ * `dryrun`: Fake frontend that does nothing.
108
+ Instead, we will simply print the generated initial prompt to the screen,
109
+ so the user can can copy it, and paste into web-based LLMs, including but
110
+ not limited to ChatGPT (OpenAI), Claude (Anthropic), Bard (google),
111
+ Gemini (google), HuggingChat (HuggingFace), Perplexity AI, etc.
112
+ This frontend does not need to connect with any backend.
113
+
114
+ **DISCLAIMER:** Unless you connect to a self-hosted LLM Inference backend, we
115
+ are uncertain how the third-party API servers will handle the data you created.
116
+ Please refer their corresponding user agreements before adopting one of them.
117
+ Be aware of such risks, and refrain from sending confidential information such
118
+ like paid API keys to LLM.
119
+
120
+
121
+ CONFIGURATION
122
+ =============
123
+
124
+ By default, the configuration file is placed at `$HOME/.debgpt/config.toml`.
125
+ Use `debgpt genconfig` or `debgpt config.toml` to generate a config template.
126
+ This configuration file should not be installed system-wide because users
127
+ may need to fill in secrets like paid API keys.
128
+
129
+
130
+ PROMPT ENGINEERING
131
+ ==================
132
+
133
+ When you chat with LLM, note that the way you ask a question significant
134
+ impacts the quality of the results you will get. make sure to provide as much
135
+ information as possible. The following are some references on this topic:
136
+
137
+ 1. OpenAI's Guide https://platform.openai.com/docs/guides/prompt-engineering
138
+ 2. Chain-of-Thought (CoT): https://arxiv.org/pdf/2205.11916.pdf
139
+
140
+ EXAMPLES
141
+ ========
142
+
143
+ The following examples are roughly organized in the order of complexity of command line.
144
+
145
+ #### Ex1. General Chat
146
+
147
+ When no arguments are given, `debgpt` degenerates into a general terminal
148
+ chatting client with LLM backends. Use `debgpt -h` to see detailed usage.
149
+
150
+ ```
151
+ debgpt
152
+ ```
153
+
154
+ If you want to quit (`-Q`) after receiving the first response from LLM regarding the question (`-A`):
155
+
156
+ ```
157
+ debgpt -Q -A "who are you?"
158
+ ```
159
+
160
+ After each session, the chatting history will be saved in `~/.debgpt` as a
161
+ json file in a unique name. You can use `debgpt replay <file_name>` to replay the history.
162
+
163
+ During the interactive session, you can use `/save path.txt` to save the last
164
+ LLM response to the specified file. You can also use `/reset` to clear the
165
+ context.
166
+
167
+ #### Ex2. BTS / Buildd Query
168
+
169
+ Ask LLM to summarize the BTS page for `src:pytorch`.
170
+
171
+ ```
172
+ debgpt -HQ --bts src:pytorch -A :summary_table
173
+ debgpt -HQ --bts 1056388 -A :summary
174
+ ```
175
+
176
+ Lookup the build status for package `glibc` and summarize as a table.
177
+
178
+ ```
179
+ debgpt -HQ --buildd glibc -A :summary_table
180
+ ```
181
+
182
+ When the argument to `-A/--ask` is a tag starting with a colon sign `:`, such
183
+ as `:summary`, it will be automatically replaced into a default question
184
+ template. Use `debgpt -A :` to lookup available templates.
185
+
186
+ The `-H` argument will skip printing the first prompt generated by `debgpt`,
187
+ because it is typically very lengthy, and people may not want to read it.
188
+
189
+ #### Ex3. Debian Policy and Developer References
190
+
191
+ Load a section of debian policy document, such as section "4.6", and ask a question
192
+
193
+ ```
194
+ debgpt -H --policy 7.2 -A "what is the difference between Depends: and Pre-Depends: ?"
195
+ debgpt -H --devref 5.5 -A :summary
196
+ ```
197
+
198
+ #### Ex4. Man and TLDR Manuals
199
+
200
+ Load the debhelper manpage and ask it to extract a part of it.
201
+
202
+ ```
203
+ debgpt -HQ --man debhelper-compat-upgrade-checklist -A "what's the change between compat 13 and compat 14?"
204
+ debgpt -HQ --tldr curl --cmd 'curl -h' -A "download https://localhost/bigfile.iso to /tmp/workspace, in silent mode"
205
+ ```
206
+
207
+ #### Ex5. Composition of Various Information Sources
208
+
209
+ We can add code file and Debian Policy simultaneously. The combination
210
+ is actually very flexible, and you can put anything in the prompt.
211
+ In the following example, we put the `debian/control` file from the
212
+ PyTorch package, as well as the Debian Policy section 7.4, and asks the LLM
213
+ to explain some details:
214
+
215
+ ```
216
+ debgpt -H -f pytorch/debian/control --policy 7.4 -A "Explain what Conflicts+Replaces means in pytorch/debian/control based on the provided policy document"
217
+ ```
218
+
219
+ Similarly, we can also let LLM read the Policy section 4.9.1, and ask it to
220
+ write some code:
221
+
222
+ ```
223
+ debgpt -H -f pytorch/debian/rules --policy 4.9.1 -A "Implement the support for the 'nocheck' tag based on the example provided in the policy document."
224
+ ```
225
+
226
+ #### Ex6. External Command line
227
+
228
+ Being able to pipe the inputs and outputs among different programs is one of
229
+ the reasons why I love the UNIX philosophy.
230
+
231
+ For example, we can let debgpt read the command line outputs of `apt`, and
232
+ summarize the upgradable packages for us:
233
+
234
+ ```
235
+ debgpt -HQ --cmd 'apt list --upgradable' -A 'Briefly summarize the upgradable packages. You can categorize these packages.' -F openai --openai_model 'gpt-3.5-turbo-16k'
236
+ ```
237
+
238
+ And we can also ask LLM to automatically generate a git commit message for you
239
+ based on the currently staged changes:
240
+
241
+ ```
242
+ debgpt -HQ --cmd 'git diff --staged' -A 'Briefly describe the change as a git commit message.'
243
+ ```
244
+
245
+ This looks interesting, right? In the next example, we have something even
246
+ more convenient!
247
+
248
+ #### Ex7. Git Wrapper
249
+
250
+ Let LLM automatically generate the git commit message, and call git to commit it:
251
+
252
+ ```
253
+ debgpt git commit
254
+ ```
255
+
256
+ #### Ex7. Fortune
257
+
258
+ Let LLM tell you a fortune:
259
+
260
+ ```
261
+ debgpt -T 1.0 fortune :joke
262
+ debgpt -T 1.0 fortune :math
263
+ ```
264
+
265
+ Use `debgpt fortune :` to lookup available tags. Or you can just specify the
266
+ type of fortune you want:
267
+
268
+ ```
269
+ debgpt -T 1.0 fortune 'tell me something very funny about linux'
270
+ ```
271
+
272
+ We need to raise the temperature (`-T`) to `1.0` because otherwise it leads
273
+ to less randomness, and LLM will tend to say the same thing every time.
274
+
275
+ #### Ex8. File-Specific Questions
276
+
277
+ Let LLM explain the code `debgpt/llm.py`:
278
+
279
+ ```
280
+ debgpt -H -f debgpt/llm.py -A :explain
281
+ ```
282
+
283
+ Let LLM explain the purpose of the contents in a file:
284
+
285
+ ```
286
+ debgpt -H -f pyproject.toml -A :what
287
+ ```
288
+
289
+ You can also specify the line range in a special grammar for `-f/--file`:
290
+
291
+ ```
292
+ debgpt -H -f pyproject.toml:3-10 -A :what # select the [3,10) lines
293
+ debgpt -H -f pyproject.toml:-10 -A :what # select from beginning to 10th (excluding 10th)
294
+ debgpt -H -f pyproject.toml:3- -A :what # select from 3th line (including) to end of file
295
+ ```
296
+
297
+ Mimicking `licensecheck`:
298
+
299
+ ```
300
+ debgpt -H -f debgpt/llm.py -A :licensecheck
301
+ ```
302
+
303
+ #### Ex9. Read Arbitrary HTML
304
+
305
+ Make the mailing list long story short:
306
+
307
+ ```
308
+ debgpt -H --html 'https://lists.debian.org/debian-project/2023/12/msg00029.html' -A :summary
309
+ ```
310
+
311
+ Explain the differences among voting options:
312
+
313
+ ```
314
+ debgpt -H --html 'https://www.debian.org/vote/2022/vote_003' -A :diff --openai_model gpt-3.5-turbo-16k
315
+ ```
316
+
317
+ In this example, we had to switch to a model supporting a long context (the
318
+ HTML page has roughly 5k tokens).
319
+
320
+ #### Ex99. You Name It
321
+
322
+ The usage of LLM is limited by our imaginations. I am glad to hear from you if
323
+ you have more good ideas on how we can make LLMs useful for Debian development:
324
+ https://salsa.debian.org/deeplearning-team/debgpt/-/issues
325
+
326
+
327
+ BACKENDS
328
+ ========
329
+
330
+ ## Available Backend Implementations
331
+
332
+ This tool provides one backend implementation: `zmq`.
333
+
334
+ * `zmq`: Only needed when you choose the ZMQ front end for
335
+ self-hosted LLM inference server.
336
+
337
+ If you plan to use the `openai` or `dryrun` frontends, there is no specific
338
+ hardware requirement. If you would like to self-host the LLM inference backend
339
+ (ZMQ backend), powerful hardware is required.
340
+
341
+ ## LLM Selections
342
+
343
+ The concrete hardware requirement depends on the
344
+ LLM you would like to use. A variety of open-access LLMs can be found here
345
+ > `https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard`
346
+ Generally, when trying to do prompt engineering only, the "instruction-tuned"
347
+ LLMs and "RL-tuned" (RL is reinforcement learning) LLMs are recommended.
348
+
349
+ The pretrained (raw) LLMs are not quite useful in this case, as they have not
350
+ yet gone through instruction tuning, nor reinforcement learning tuning
351
+ procedure. These pretrained LLMs will more likely generate garbage and not
352
+ follow your instructions, or simply repeat your instruction. We will only
353
+ revisit the pretrained LLMs when we plan to start collecting data and fine-tune
354
+ (e.g., LoRA) a model in the far future.
355
+
356
+ The following is a list of supported LLMs for self-hosting (this list will
357
+ be updated when there are new state-of-the-art open-access LLMs available):
358
+
359
+ * Mistral7B (`Mistral-7B-Instruct-v0.2`) (default)
360
+ : This model requires roughly 15GB of disks space to download.
361
+
362
+ * Mixtral8x7B (`Mixtral-8x7B-Instruct-v0.1`)
363
+ : This model is larger yet more powerful than the default LLM. In exchange, it
364
+ poses even higher hardware requirements. It takes roughly 60~100GB disk space
365
+ (I forgot this number. Will check later).
366
+
367
+ Different LLMs will pose different hardware requirements. Please see the
368
+ "Hardware Requirements" subsection below.
369
+
370
+ ## Hardware Requirements
371
+
372
+ By default, we recommend doing LLM inference in `fp16` precision. If the VRAM
373
+ (such as CUDA memory) is limited, you may also switch to even lower preicisions
374
+ such as `8bit` and `4bit`. For pure CPU inference, we only support `fp32`
375
+ precision now.
376
+
377
+ Note, Multi-GPU inference is supported by the underlying transformers library.
378
+ If you have multiple GPUs, this memory requirement is roughly divided by your number of GPUs.
379
+
380
+ Hardware requirements for the `Mistral7B` LLM:
381
+
382
+ * `Mistral7B` + `fp16` (cuda): 24GB+ VRAM preferred, but needs a 48GB GPU to run all the demos (some of them have a context as long as 8k). Example: Nvidia RTX A5000, Nvidia RTX 4090.
383
+ * `Mistral7B` + `8bit` (cuda): 12GB+ VRAM at minimum, but 24GB+ preferred so you can run all demos.
384
+ * `Mistral7B` + `4bit` (cuda): 6GB+ VRAM at minimum but 12GB+ preferred so you can run all demos. Example: Nvidia RTX 4070 (mobile) 8GB.
385
+ * `Mistral7B` + `fp32` (cpu): Requires 64GB+ of RAM, but a CPU is 100~400 times slower than a GPU for this workload and thus not recommended.
386
+
387
+ Hardware requirement for the `Mixtral8x7B` LLM:
388
+
389
+ * `Mixtral8x7B` + `fp16` (cuda): 90GB+ VRAM.
390
+ * `Mixtral8x7B` + `8bit` (cuda): 45GB+ VRAM.
391
+ * `Mixtral8x7B` + `4bit` (cuda): 23GB+ VRAM, but in order to make it work with long context such as 8k tokens, you still need 2x 48GB GPUs in 4bit precision.
392
+
393
+ See https://huggingface.co/blog/mixtral for more.
394
+
395
+ ## Usage of the ZMQ Backend
396
+
397
+ If you want to run the default LLM with different precisions:
398
+
399
+ ```
400
+ debgpt backend --max_new_tokens=1024 --device cuda --precision fp16
401
+ debgpt backend --max_new_tokens=1024 --device cuda --precision bf16
402
+ debgpt backend --max_new_tokens=1024 --device cuda --precision 8bit
403
+ debgpt backend --max_new_tokens=1024 --device cuda --precision 4bit
404
+ ```
405
+
406
+ The only supported precision on CPU is fp32 (for now).
407
+ If you want to fall back to CPU computation (very slow):
408
+
409
+ ```
410
+ debgpt backend --max_new_tokens=1024 --device cpu --precision fp32
411
+ ```
412
+
413
+ If you want to run a different LLM, such as `Mixtral8x7B` than the default `Mistral7B`:
414
+
415
+ ```
416
+ debgpt backend --max_new_tokens=1024 --device cuda --precision 4bit --llm Mixtral8x7B
417
+ ```
418
+
419
+ The argument `--max_new_tokens` does not matter much and you can adjust it (it
420
+ is the maximum length of each llm reply). You can adjust it as wish.
421
+
422
+
423
+ SETUP AND INSTALL
424
+ =================
425
+
426
+ FIXME: add optional (backend) dependencies in `pyproject.toml`
427
+
428
+ This tool can be installed from source via the command "`pip3 install .`".
429
+ By default, it will only pull the dependencies needed to run the OpenAI
430
+ and the ZMQ frontends. The dependencies of the ZMQ backend (i.e., self-hosted
431
+ LLM inference) needs to be satisfied manually for now, using tools like
432
+ pip, venv, conda, mamba, etc.
433
+
434
+ The additional dependencies needed to run the LLM backend are: numpy,
435
+ pytorch, pyzmq, scipy, accelerate, bitsandbytes, tokenizers, transformers.
436
+
437
+ The additional dependencies needed to run the tests are: pytest.
438
+
439
+ TODO
440
+ ====
441
+
442
+ The following is the current **TODO List**.Some ideas might be a little bit far away.
443
+
444
+ 1. add perplexity API https://www.perplexity.ai
445
+ 1. https://github.com/openai/chatgpt-retrieval-plugin
446
+ 1. implement `--archwiki` `--gentoowiki` `--debianwiki` `--fedorawiki` `--wikipedia` (although the LLM have already read the wikipedia dump many times)
447
+ 1. analyze sbuild buildlog
448
+ 1. analyze udd, ddpo, contributors, nm
449
+ 1. organize argparse with argument groups
450
+ 1. How can LLM help CPython transition? failing tests, API changes, etc.
451
+ 1. What else can we do about the Debian patching workflow? adding patch description?
452
+ 1. find upstream bug that matches debian bug (bug triage)
453
+ 1. connect with debian codesearch API https://codesearch.debian.net/faq
454
+ 1. Let LLM imitate [Janitor](https://wiki.debian.org/Janitor), and possibly do some more complicated things
455
+ 1. Extend Lintian with LLM for complicated checks?
456
+ 1. Let LLM do mentoring (lists.debian.org/debian-mentors) e.g., reviewing a .dsc package. This is very difficult given limited context length. Maybe LLMs are not yet smart enough to do this.
457
+ 1. Apart from the `str` type, the frontend supports other return types like `List` or `Dict` (for advanced usage such as in-context learning) are possible (see `debgpt/frontend.py :: ZMQFrontend.query`, but those are not explored yet.
458
+ 1. The current implementation stays at prompt-engineering an existing Chatting LLM with debian-specific documents, like debian-policy, debian developer references, and some man pages. In the future, we may want to explore how we can use larger datasets like Salsa dump, Debian mailing list dump, etc. LoRA or RAG or any new methods are to be investegated with the datasets. Also see follow-ups at https://lists.debian.org/debian-project/2023/12/msg00028.html
459
+ 1. Should we really train or fine-tune a model? How do we organize the data for RLHF or instruction tuning?
460
+ 1. There are other possible backends like https://github.com/ggerganov/llama.cpp
461
+ which allows inference on CPUs (even laptops).
462
+ transformers itself also supports 8bit and 4bit inference with bitsandbytes.
463
+
464
+ LICENSE
465
+ =======
466
+
467
+ Copyright (C) 2024 Mo Zhou <lumin@debian.org>; MIT/Expat License