rubber-ducky 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
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.
- ducky/ducky.py +72 -18
- rubber_ducky-1.1.0.dist-info/METADATA +59 -0
- rubber_ducky-1.1.0.dist-info/RECORD +8 -0
- rubber_ducky-1.0.0.dist-info/METADATA +0 -31
- rubber_ducky-1.0.0.dist-info/RECORD +0 -8
- {rubber_ducky-1.0.0.dist-info → rubber_ducky-1.1.0.dist-info}/LICENSE +0 -0
- {rubber_ducky-1.0.0.dist-info → rubber_ducky-1.1.0.dist-info}/WHEEL +0 -0
- {rubber_ducky-1.0.0.dist-info → rubber_ducky-1.1.0.dist-info}/entry_points.txt +0 -0
- {rubber_ducky-1.0.0.dist-info → rubber_ducky-1.1.0.dist-info}/top_level.txt +0 -0
ducky/ducky.py
CHANGED
|
@@ -2,41 +2,95 @@ import argparse
|
|
|
2
2
|
from typing import Optional
|
|
3
3
|
from langchain.llms.ollama import Ollama
|
|
4
4
|
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
|
5
|
+
from termcolor import colored
|
|
5
6
|
|
|
7
|
+
class RubberDuck:
|
|
8
|
+
"""
|
|
9
|
+
This class is a wrapper around the Ollama model.
|
|
10
|
+
"""
|
|
11
|
+
def __init__(self, model: str = "codellama") -> None:
|
|
12
|
+
"""
|
|
13
|
+
This function initializes the RubberDuck class.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
model (str, optional): The model to be used. Defaults to "codellama".
|
|
17
|
+
"""
|
|
18
|
+
self.system_prompt = """You are a pair progamming tool to help developers debug, think through design, and write code.
|
|
19
|
+
Help the user think through their approach and provide feedback on the code."""
|
|
20
|
+
self.llm = Ollama(model=model, callbacks=[StreamingStdOutCallbackHandler()], system=self.system_prompt)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def call_llama(self, code: str = "", prompt: Optional[str] = None, chain: bool = False) -> None:
|
|
24
|
+
"""
|
|
25
|
+
This function calls the Ollama model to provide feedback on the given code.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
code (str): The code to be reviewed.
|
|
29
|
+
prompt (Optional[str]): Custom prompt to be used. Defaults to None.
|
|
30
|
+
"""
|
|
31
|
+
if prompt is None:
|
|
32
|
+
prompt = "review the code, find any issues if any, suggest cleanups if any:" + code
|
|
33
|
+
else:
|
|
34
|
+
prompt = prompt + code
|
|
6
35
|
|
|
7
|
-
|
|
36
|
+
|
|
37
|
+
self.llm(prompt)
|
|
38
|
+
if chain:
|
|
39
|
+
while(True):
|
|
40
|
+
prompt = input(colored("\n What's on your mind? \n ", 'green'))
|
|
41
|
+
self.llm(prompt)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def read_files_from_dir(directory: str) -> str:
|
|
8
45
|
"""
|
|
9
|
-
This function
|
|
46
|
+
This function reads all the files from a directory and returns the concatenated string.
|
|
10
47
|
|
|
11
48
|
Args:
|
|
12
|
-
|
|
13
|
-
prompt (Optional[str], optional): Custom prompt to be used. Defaults to None.
|
|
14
|
-
"""
|
|
15
|
-
if prompt is None:
|
|
16
|
-
prompt = "review the code, find any issues if any, suggest cleanups if any:" + code
|
|
17
|
-
else:
|
|
18
|
-
prompt = prompt + code
|
|
19
|
-
system_prompt = """You are a pair progamming tool to help developers debug, think through design, and write code. Help the user rubber duck by providing feedback on the code."""
|
|
49
|
+
directory (str): The directory to be processed.
|
|
20
50
|
|
|
21
|
-
|
|
22
|
-
|
|
51
|
+
Returns:
|
|
52
|
+
str: The concatenated string of all the files.
|
|
53
|
+
"""
|
|
54
|
+
import os
|
|
55
|
+
files = os.listdir(directory)
|
|
56
|
+
code = ""
|
|
57
|
+
for file in files:
|
|
58
|
+
code += open(directory + "/" + file).read()
|
|
59
|
+
return code
|
|
23
60
|
|
|
24
|
-
# TODO: add chaining if it makes sense
|
|
25
|
-
llm(prompt)
|
|
26
61
|
|
|
27
62
|
def ducky() -> None:
|
|
28
63
|
"""
|
|
29
64
|
This function parses the command line arguments and calls the Ollama model.
|
|
30
65
|
"""
|
|
31
66
|
parser = argparse.ArgumentParser()
|
|
32
|
-
parser.add_argument("--prompt", help="Custom prompt to be used", default=None)
|
|
33
|
-
parser.add_argument("--file", help="The file to be processed", default=None)
|
|
34
|
-
parser.add_argument("--directory", help="The directory to be processed", default=None)
|
|
67
|
+
parser.add_argument("--prompt", "-p", help="Custom prompt to be used", default=None)
|
|
68
|
+
parser.add_argument("--file", "-f", help="The file to be processed", default=None)
|
|
69
|
+
parser.add_argument("--directory", "-d", help="The directory to be processed", default=None)
|
|
70
|
+
parser.add_argument("--chain", "-c", help="Chain the output of the previous command to the next command", action="store_true", default=False)
|
|
71
|
+
parser.add_argument("--model", "-m", help="The model to be used", default="codellama")
|
|
35
72
|
args, _ = parser.parse_known_args()
|
|
36
73
|
|
|
74
|
+
# My testing has shown that the codellama:7b-python is good for returning python code from the program.
|
|
75
|
+
# My intention with this tool was to give more general feedback and have back a back and forth with the user.
|
|
76
|
+
rubber_ducky = RubberDuck(model=args.model)
|
|
77
|
+
if args.file is None and args.directory is None:
|
|
78
|
+
if args.chain:
|
|
79
|
+
while(True):
|
|
80
|
+
prompt = input(colored("\n What's on your mind? \n ", 'green'))
|
|
81
|
+
rubber_ducky.call_llama(prompt=prompt, chain=args.chain)
|
|
82
|
+
else:
|
|
83
|
+
prompt = input(colored("\n What's on your mind? \n ", 'green'))
|
|
84
|
+
rubber_ducky.call_llama(prompt=prompt, chain=args.chain)
|
|
85
|
+
|
|
37
86
|
if args.file is not None:
|
|
38
87
|
code = open(args.file).read()
|
|
39
|
-
call_llama(code=code, prompt=args.prompt)
|
|
88
|
+
rubber_ducky.call_llama(code=code, prompt=args.prompt, chain=args.chain)
|
|
89
|
+
|
|
90
|
+
elif args.directory is not None:
|
|
91
|
+
code = read_files_from_dir(args.directory)
|
|
92
|
+
rubber_ducky.call_llama(code=code, prompt=args.prompt, chain=args.chain)
|
|
93
|
+
|
|
40
94
|
|
|
41
95
|
if __name__ == "__main__":
|
|
42
96
|
ducky()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: rubber-ducky
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: AI Companion for Pair Programming
|
|
5
|
+
Home-page: https://github.com/ParthSareen/ducky
|
|
6
|
+
Author: Parth Sareen
|
|
7
|
+
Author-email: psareen@uwaterloo.ca
|
|
8
|
+
License: MIT
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: langchain
|
|
12
|
+
Requires-Dist: termcolor
|
|
13
|
+
|
|
14
|
+
# rubber ducky
|
|
15
|
+
|
|
16
|
+
## tl;dr
|
|
17
|
+
- `pip install rubber-ducky`
|
|
18
|
+
- Install ollama
|
|
19
|
+
- `ollama run codellama` (first time and then you can just have application in background)
|
|
20
|
+
- There are probably other dependencies which I forgot to put in setup.py sorry in advance.
|
|
21
|
+
- Run with `ducky -f <file path>`
|
|
22
|
+
|
|
23
|
+
## Why did I make this
|
|
24
|
+
|
|
25
|
+
I wrote ducky because I annoy engineers too much and I needed to talk someone through my code quickly and validate my approach. Maybe this is why I'm not a senior engineer.
|
|
26
|
+
|
|
27
|
+
Since I can't dump all my code to GPT and make it tell me I know how to code, I decided to build something for quick iteration. All. Local. I also didn't want to get fired by leaking all our data. Not again.
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
Bless the folks at Ollama cause they have been carrying my recent projects.
|
|
31
|
+
|
|
32
|
+
This project is currently only supported on Mac and Linux cause Ollama is a dependency.
|
|
33
|
+
You will need Ollama installed on your machine. The model I use for this project is `codellama`.
|
|
34
|
+
|
|
35
|
+
For the first installation you can run `ollama run codellama` and it should pull the necessary binaries for you. Ollama is also great because it'll spin up a server which can run in the background and can even do automatic model switching as long as you have it installed.
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
Install through [pypi](https://pypi.org/project/rubber-ducky/):
|
|
40
|
+
|
|
41
|
+
`pip install rubber-ducky` .
|
|
42
|
+
|
|
43
|
+
### Simple run
|
|
44
|
+
`ducky`
|
|
45
|
+
|
|
46
|
+
### To use additional options:
|
|
47
|
+
|
|
48
|
+
`ducky --file <path> --prompt <prompt> --directory <directory> --chain --model <model>`
|
|
49
|
+
|
|
50
|
+
Where:
|
|
51
|
+
- `--prompt` or `-p`: Custom prompt to be used
|
|
52
|
+
- `--file` or `-f`: The file to be processed
|
|
53
|
+
- `--directory` or `-d`: The directory to be processed
|
|
54
|
+
- `--chain` or `-c`: Chain the output of the previous command to the next command
|
|
55
|
+
- `--model` or `-m`: The model to be used (default is "codellama")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Example output
|
|
59
|
+

|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ducky/__init__.py,sha256=_7imP8Jc2SIapn4fzGkspmKvqxPTFDcDJWHZ_o_MnlE,24
|
|
2
|
+
ducky/ducky.py,sha256=LxL4jpd9oj77D5vh6s9h37zHw_AsK0TZ8BsEEfdUkew,3776
|
|
3
|
+
rubber_ducky-1.1.0.dist-info/LICENSE,sha256=gQ1rCmw18NqTk5GxG96F6vgyN70e1c4kcKUtWDwdNaE,1069
|
|
4
|
+
rubber_ducky-1.1.0.dist-info/METADATA,sha256=zkZiaZ7Qg9OI0iDIRoPUZhOQcqtmdr3eY_KEf9LJIbU,2187
|
|
5
|
+
rubber_ducky-1.1.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
6
|
+
rubber_ducky-1.1.0.dist-info/entry_points.txt,sha256=Dpnmsfu54R9NqaSw8HZVsI52ICS3grSuSV_YwZa_x2Y,38
|
|
7
|
+
rubber_ducky-1.1.0.dist-info/top_level.txt,sha256=4Q75MONDNPpQ3o17bTu7RFuKwFhTIRzlXP3_LDWQQ30,6
|
|
8
|
+
rubber_ducky-1.1.0.dist-info/RECORD,,
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: rubber-ducky
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: AI Companion for Pair Programming
|
|
5
|
-
Home-page: https://github.com/ParthSareen/ducky
|
|
6
|
-
Author: Parth Sareen
|
|
7
|
-
Author-email: psareen@uwaterloo.ca
|
|
8
|
-
License: MIT
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: transformers
|
|
12
|
-
|
|
13
|
-
# ducky
|
|
14
|
-
|
|
15
|
-
Ducky Project
|
|
16
|
-
Overview
|
|
17
|
-
Ducky is a Python project that uses the ChatOllama language model from the langchain_core package. It's designed to generate responses based on a given prompt.
|
|
18
|
-
Installation
|
|
19
|
-
To install the necessary dependencies, you'll need to create a virtual environment and install the packages listed in the requirements.txt file.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
``` python
|
|
23
|
-
python3 -m venv venv
|
|
24
|
-
source venv/bin/activate
|
|
25
|
-
pip install -r requirements.txt
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Usage
|
|
29
|
-
To use Ducky, you'll need to run the ducky.py script with a prompt as an argument. The script will pass the prompt to the ChatOllama instance and print the generated response.
|
|
30
|
-
|
|
31
|
-
`python ducky.py --prompt "Your prompt here"`
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
ducky/__init__.py,sha256=_7imP8Jc2SIapn4fzGkspmKvqxPTFDcDJWHZ_o_MnlE,24
|
|
2
|
-
ducky/ducky.py,sha256=TCAQTgcEP8uexD1wQyBqBpYK8jqu_ZSVl3vf5duSJYw,1644
|
|
3
|
-
rubber_ducky-1.0.0.dist-info/LICENSE,sha256=gQ1rCmw18NqTk5GxG96F6vgyN70e1c4kcKUtWDwdNaE,1069
|
|
4
|
-
rubber_ducky-1.0.0.dist-info/METADATA,sha256=WdNENSlfA_b8YIEKAHu3-G0NljHE36BVUF76hi3sRfE,982
|
|
5
|
-
rubber_ducky-1.0.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
6
|
-
rubber_ducky-1.0.0.dist-info/entry_points.txt,sha256=Dpnmsfu54R9NqaSw8HZVsI52ICS3grSuSV_YwZa_x2Y,38
|
|
7
|
-
rubber_ducky-1.0.0.dist-info/top_level.txt,sha256=4Q75MONDNPpQ3o17bTu7RFuKwFhTIRzlXP3_LDWQQ30,6
|
|
8
|
-
rubber_ducky-1.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|