rubber-ducky 1.1.0__py3-none-any.whl → 1.1.1__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 CHANGED
@@ -1,57 +1,41 @@
1
1
  import argparse
2
+ import asyncio
2
3
  from typing import Optional
3
- from langchain.llms.ollama import Ollama
4
- from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
5
- from termcolor import colored
4
+ from ollama import AsyncClient
5
+
6
6
 
7
7
  class RubberDuck:
8
- """
9
- This class is a wrapper around the Ollama model.
10
- """
11
8
  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
9
  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
- """
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:
31
15
  if prompt is None:
32
- prompt = "review the code, find any issues if any, suggest cleanups if any:" + code
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
33
21
  else:
34
22
  prompt = prompt + code
35
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="codellama", prompt=context_prompt)
29
+ print(response['response'])
30
+ responses.append(response['response'])
31
+ if not chain:
32
+ break
33
+ prompt = input("\nAny questions? \n")
36
34
 
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
35
 
44
36
  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
37
  import os
38
+
55
39
  files = os.listdir(directory)
56
40
  code = ""
57
41
  for file in files:
@@ -59,38 +43,53 @@ def read_files_from_dir(directory: str) -> str:
59
43
  return code
60
44
 
61
45
 
62
- def ducky() -> None:
63
- """
64
- This function parses the command line arguments and calls the Ollama model.
65
- """
46
+ async def ducky() -> None:
66
47
  parser = argparse.ArgumentParser()
48
+ parser.add_argument("question", nargs="?", help="Direct question to ask", default=None)
67
49
  parser.add_argument("--prompt", "-p", help="Custom prompt to be used", default=None)
68
50
  parser.add_argument("--file", "-f", help="The file to be processed", default=None)
69
51
  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")
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
+ )
72
62
  args, _ = parser.parse_known_args()
73
63
 
74
64
  # My testing has shown that the codellama:7b-python is good for returning python code from the program.
75
65
  # My intention with this tool was to give more general feedback and have back a back and forth with the user.
76
66
  rubber_ducky = RubberDuck(model=args.model)
67
+
68
+ # Handle direct question from CLI
69
+ if args.question is not None:
70
+ await rubber_ducky.call_llama(prompt=args.question, chain=args.chain)
71
+ return
72
+
77
73
  if args.file is None and args.directory is None:
74
+ # Handle interactive mode (no file/directory specified)
75
+ await rubber_ducky.call_llama(prompt=args.prompt, chain=args.chain)
78
76
  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)
77
+ while True:
78
+ await rubber_ducky.call_llama(prompt=args.prompt, chain=args.chain)
79
+ return
85
80
 
81
+ # Handle file input
86
82
  if args.file is not None:
87
83
  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:
84
+ # Handle directory input
85
+ else:
91
86
  code = read_files_from_dir(args.directory)
92
- rubber_ducky.call_llama(code=code, prompt=args.prompt, chain=args.chain)
93
-
87
+
88
+ await rubber_ducky.call_llama(code=code, prompt=args.prompt, chain=args.chain)
89
+
90
+
91
+ def main():
92
+ asyncio.run(ducky())
94
93
 
95
94
  if __name__ == "__main__":
96
- ducky()
95
+ 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.1
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,8 @@
1
+ ducky/__init__.py,sha256=_7imP8Jc2SIapn4fzGkspmKvqxPTFDcDJWHZ_o_MnlE,24
2
+ ducky/ducky.py,sha256=NwOzoLMd7fzimq-4OkfEL6buACY2Y13cze2uLEerVBU,3540
3
+ rubber_ducky-1.1.1.dist-info/LICENSE,sha256=gQ1rCmw18NqTk5GxG96F6vgyN70e1c4kcKUtWDwdNaE,1069
4
+ rubber_ducky-1.1.1.dist-info/METADATA,sha256=uPUKC85hZxy2j2jVojKPzWH_rVYt1GAAB7Z1deWUFbk,1638
5
+ rubber_ducky-1.1.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
6
+ rubber_ducky-1.1.1.dist-info/entry_points.txt,sha256=LPndtj8UqEWtwYApv5LJJniH4FUrsriOqV2LA1X_UPQ,43
7
+ rubber_ducky-1.1.1.dist-info/top_level.txt,sha256=4Q75MONDNPpQ3o17bTu7RFuKwFhTIRzlXP3_LDWQQ30,6
8
+ rubber_ducky-1.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ducky = ducky.ducky:main
@@ -1,8 +0,0 @@
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,2 +0,0 @@
1
- [console_scripts]
2
- ducky = ducky:ducky