rubber-ducky 1.1.0__tar.gz → 1.1.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rubber-ducky
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: AI Companion for Pair Programming
5
5
  Home-page: https://github.com/ParthSareen/ducky
6
6
  Author: Parth Sareen
@@ -8,31 +8,24 @@ Author-email: psareen@uwaterloo.ca
8
8
  License: MIT
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: langchain
12
- Requires-Dist: termcolor
11
+ Requires-Dist: ollama
13
12
 
14
13
  # rubber ducky
15
14
 
16
15
  ## tl;dr
17
16
  - `pip install rubber-ducky`
18
17
  - Install ollama
19
- - `ollama run codellama` (first time and then you can just have application in background)
18
+ - `ollama pull codellama` (first time and then you can just have application in background)
20
19
  - 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.
20
+ - Run with `ducky <path>` or `ducky <question>`
28
21
 
29
22
  ## Dependencies
30
- Bless the folks at Ollama cause they have been carrying my recent projects.
31
23
 
32
- This project is currently only supported on Mac and Linux cause Ollama is a dependency.
33
24
  You will need Ollama installed on your machine. The model I use for this project is `codellama`.
34
25
 
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.
26
+ For the first installation you can run `ollama pull codellama` and it should pull the necessary binaries for you.
27
+
28
+ 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
29
 
37
30
  ## Usage
38
31
 
@@ -43,8 +36,16 @@ Install through [pypi](https://pypi.org/project/rubber-ducky/):
43
36
  ### Simple run
44
37
  `ducky`
45
38
 
46
- ### To use additional options:
39
+ or
40
+
41
+ `ducky <question>`
42
+
43
+ or
44
+
45
+ `ducky -f <path>`
46
+
47
47
 
48
+ ### All options
48
49
  `ducky --file <path> --prompt <prompt> --directory <directory> --chain --model <model>`
49
50
 
50
51
  Where:
@@ -0,0 +1,48 @@
1
+ # rubber ducky
2
+
3
+ ## tl;dr
4
+ - `pip install rubber-ducky`
5
+ - Install ollama
6
+ - `ollama pull codellama` (first time and then you can just have application in background)
7
+ - There are probably other dependencies which I forgot to put in setup.py sorry in advance.
8
+ - Run with `ducky <path>` or `ducky <question>`
9
+
10
+ ## Dependencies
11
+
12
+ You will need Ollama installed on your machine. The model I use for this project is `codellama`.
13
+
14
+ For the first installation you can run `ollama pull codellama` and it should pull the necessary binaries for you.
15
+
16
+ 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.
17
+
18
+ ## Usage
19
+
20
+ Install through [pypi](https://pypi.org/project/rubber-ducky/):
21
+
22
+ `pip install rubber-ducky` .
23
+
24
+ ### Simple run
25
+ `ducky`
26
+
27
+ or
28
+
29
+ `ducky <question>`
30
+
31
+ or
32
+
33
+ `ducky -f <path>`
34
+
35
+
36
+ ### All options
37
+ `ducky --file <path> --prompt <prompt> --directory <directory> --chain --model <model>`
38
+
39
+ Where:
40
+ - `--prompt` or `-p`: Custom prompt to be used
41
+ - `--file` or `-f`: The file to be processed
42
+ - `--directory` or `-d`: The directory to be processed
43
+ - `--chain` or `-c`: Chain the output of the previous command to the next command
44
+ - `--model` or `-m`: The model to be used (default is "codellama")
45
+
46
+
47
+ ## Example output
48
+ ![Screenshot of ducky](image.png)
@@ -0,0 +1,96 @@
1
+ import argparse
2
+ import asyncio
3
+ from typing import Optional
4
+ from ollama import AsyncClient
5
+
6
+
7
+ class RubberDuck:
8
+ def __init__(self, model: str = "codellama") -> None:
9
+ self.system_prompt = """You are a pair progamming tool to help developers debug, think through design, and write code.
10
+ Help the user think through their approach and provide feedback on the code. Think step by step and ask clarifying questions if needed."""
11
+ self.client = AsyncClient()
12
+ self.model = model
13
+
14
+ async def call_llama(self, code: str = "", prompt: Optional[str] = None, chain: bool = False) -> None:
15
+ if prompt is None:
16
+ user_prompt = input("\nEnter your prompt (or press Enter for default review): ")
17
+ if not user_prompt:
18
+ prompt = "review the code, find any issues if any, suggest cleanups if any:" + code
19
+ else:
20
+ prompt = user_prompt + code
21
+ else:
22
+ prompt = prompt + code
23
+
24
+ responses = []
25
+ while True:
26
+ # Include previous responses in the prompt for context
27
+ context_prompt = "\n".join(responses) + "\n" + prompt
28
+ response = await self.client.generate(model=self.model, prompt=context_prompt)
29
+ print(response['response'])
30
+ responses.append(response['response'])
31
+ if not chain:
32
+ break
33
+ prompt = input("\nAny questions? \n")
34
+
35
+
36
+ def read_files_from_dir(directory: str) -> str:
37
+ import os
38
+
39
+ files = os.listdir(directory)
40
+ code = ""
41
+ for file in files:
42
+ code += open(directory + "/" + file).read()
43
+ return code
44
+
45
+
46
+ async def ducky() -> None:
47
+ parser = argparse.ArgumentParser()
48
+ parser.add_argument("question", nargs="*", help="Direct question to ask", default=None)
49
+ parser.add_argument("--prompt", "-p", help="Custom prompt to be used", default=None)
50
+ parser.add_argument("--file", "-f", help="The file to be processed", default=None)
51
+ parser.add_argument("--directory", "-d", help="The directory to be processed", default=None)
52
+ parser.add_argument(
53
+ "--chain",
54
+ "-c",
55
+ help="Chain the output of the previous command to the next command",
56
+ action="store_true",
57
+ default=False,
58
+ )
59
+ parser.add_argument(
60
+ "--model", "-m", help="The model to be used", default="codellama"
61
+ )
62
+ args, _ = parser.parse_known_args()
63
+
64
+ # My testing has shown that the codellama:7b-python is good for returning python code from the program.
65
+ # My intention with this tool was to give more general feedback and have back a back and forth with the user.
66
+ rubber_ducky = RubberDuck(model=args.model)
67
+
68
+ # Handle direct question from CLI
69
+ if args.question is not None:
70
+ question = " ".join(args.question)
71
+ await rubber_ducky.call_llama(prompt=question, chain=args.chain)
72
+ return
73
+
74
+ if args.file is None and args.directory is None:
75
+ # Handle interactive mode (no file/directory specified)
76
+ await rubber_ducky.call_llama(prompt=args.prompt, chain=args.chain)
77
+ if args.chain:
78
+ while True:
79
+ await rubber_ducky.call_llama(prompt=args.prompt, chain=args.chain)
80
+ return
81
+
82
+ # Handle file input
83
+ if args.file is not None:
84
+ code = open(args.file).read()
85
+ # Handle directory input
86
+ else:
87
+ code = read_files_from_dir(args.directory)
88
+
89
+ await rubber_ducky.call_llama(code=code, prompt=args.prompt, chain=args.chain)
90
+
91
+
92
+ def main():
93
+ asyncio.run(ducky())
94
+
95
+ if __name__ == "__main__":
96
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rubber-ducky
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: AI Companion for Pair Programming
5
5
  Home-page: https://github.com/ParthSareen/ducky
6
6
  Author: Parth Sareen
@@ -8,31 +8,24 @@ Author-email: psareen@uwaterloo.ca
8
8
  License: MIT
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
- Requires-Dist: langchain
12
- Requires-Dist: termcolor
11
+ Requires-Dist: ollama
13
12
 
14
13
  # rubber ducky
15
14
 
16
15
  ## tl;dr
17
16
  - `pip install rubber-ducky`
18
17
  - Install ollama
19
- - `ollama run codellama` (first time and then you can just have application in background)
18
+ - `ollama pull codellama` (first time and then you can just have application in background)
20
19
  - 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.
20
+ - Run with `ducky <path>` or `ducky <question>`
28
21
 
29
22
  ## Dependencies
30
- Bless the folks at Ollama cause they have been carrying my recent projects.
31
23
 
32
- This project is currently only supported on Mac and Linux cause Ollama is a dependency.
33
24
  You will need Ollama installed on your machine. The model I use for this project is `codellama`.
34
25
 
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.
26
+ For the first installation you can run `ollama pull codellama` and it should pull the necessary binaries for you.
27
+
28
+ 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
29
 
37
30
  ## Usage
38
31
 
@@ -43,8 +36,16 @@ Install through [pypi](https://pypi.org/project/rubber-ducky/):
43
36
  ### Simple run
44
37
  `ducky`
45
38
 
46
- ### To use additional options:
39
+ or
40
+
41
+ `ducky <question>`
42
+
43
+ or
44
+
45
+ `ducky -f <path>`
46
+
47
47
 
48
+ ### All options
48
49
  `ducky --file <path> --prompt <prompt> --directory <directory> --chain --model <model>`
49
50
 
50
51
  Where:
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ducky = ducky.ducky:main
@@ -5,7 +5,7 @@ with open('README.md', 'r', encoding='utf-8') as f:
5
5
 
6
6
  setup(
7
7
  name='rubber-ducky',
8
- version='1.1.0',
8
+ version='1.1.2',
9
9
  description='AI Companion for Pair Programming',
10
10
  long_description=long_description,
11
11
  long_description_content_type='text/markdown',
@@ -15,12 +15,11 @@ setup(
15
15
  license='MIT',
16
16
  packages=find_packages(),
17
17
  install_requires=[
18
- 'langchain',
19
- 'termcolor'
18
+ 'ollama',
20
19
  ],
21
20
  entry_points={
22
21
  'console_scripts': [
23
- 'ducky=ducky:ducky',
22
+ 'ducky=ducky.ducky:main',
24
23
  ],
25
24
  },
26
25
  )
@@ -1,46 +0,0 @@
1
- # rubber ducky
2
-
3
- ## tl;dr
4
- - `pip install rubber-ducky`
5
- - Install ollama
6
- - `ollama run codellama` (first time and then you can just have application in background)
7
- - There are probably other dependencies which I forgot to put in setup.py sorry in advance.
8
- - Run with `ducky -f <file path>`
9
-
10
- ## Why did I make this
11
-
12
- 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.
13
-
14
- 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.
15
-
16
- ## Dependencies
17
- Bless the folks at Ollama cause they have been carrying my recent projects.
18
-
19
- This project is currently only supported on Mac and Linux cause Ollama is a dependency.
20
- You will need Ollama installed on your machine. The model I use for this project is `codellama`.
21
-
22
- 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.
23
-
24
- ## Usage
25
-
26
- Install through [pypi](https://pypi.org/project/rubber-ducky/):
27
-
28
- `pip install rubber-ducky` .
29
-
30
- ### Simple run
31
- `ducky`
32
-
33
- ### To use additional options:
34
-
35
- `ducky --file <path> --prompt <prompt> --directory <directory> --chain --model <model>`
36
-
37
- Where:
38
- - `--prompt` or `-p`: Custom prompt to be used
39
- - `--file` or `-f`: The file to be processed
40
- - `--directory` or `-d`: The directory to be processed
41
- - `--chain` or `-c`: Chain the output of the previous command to the next command
42
- - `--model` or `-m`: The model to be used (default is "codellama")
43
-
44
-
45
- ## Example output
46
- ![Screenshot of ducky](image.png)
@@ -1,96 +0,0 @@
1
- import argparse
2
- from typing import Optional
3
- from langchain.llms.ollama import Ollama
4
- from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
5
- from termcolor import colored
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
35
-
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:
45
- """
46
- This function reads all the files from a directory and returns the concatenated string.
47
-
48
- Args:
49
- directory (str): The directory to be processed.
50
-
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
60
-
61
-
62
- def ducky() -> None:
63
- """
64
- This function parses the command line arguments and calls the Ollama model.
65
- """
66
- parser = argparse.ArgumentParser()
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")
72
- args, _ = parser.parse_known_args()
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
-
86
- if args.file is not None:
87
- code = open(args.file).read()
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
-
94
-
95
- if __name__ == "__main__":
96
- ducky()
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- ducky = ducky:ducky
@@ -1,2 +0,0 @@
1
- langchain
2
- termcolor
File without changes
File without changes