clai 0.1.0__tar.gz → 0.3.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.

Potentially problematic release.


This version of clai might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: clai
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Command Line AI- this tool lets you call ChatGPT from a CLI
5
5
  License: Proprietary
6
6
  Author: apockill
@@ -11,16 +11,21 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.8
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
+ Requires-Dist: PyAutoGUI (>=0.9.53,<0.10.0)
15
+ Requires-Dist: PyWinCtl (>=0.0.43,<0.0.44)
14
16
  Requires-Dist: openai (>=0.27.0,<0.28.0)
17
+ Requires-Dist: pytesseract (>=0.3.10,<0.4.0)
15
18
  Description-Content-Type: text/markdown
16
19
 
17
20
  # clai
18
21
  Command Line AI- this tool lets you call ChatGPT from a CLI.
19
22
 
20
23
  I'm designing this to be used in conjunction with a fork of [shin][shin], which will allow you
21
- to call `clai` from any textbox in your computer. Finally, chatGPT everywhere!
24
+ to call `clai` from any textbox in your computer. Finally, ChatGPT everywhere!
25
+
26
+ The long-term vision for this project is to add support for extracting context. For example, it would
27
+ read the current text on a window and be able to add to it, or answer questions about it.
22
28
 
23
- [shin]: https://github.com/apockill/shin
24
29
  _________________
25
30
 
26
31
  [![PyPI version](https://badge.fury.io/py/clai.svg)](http://badge.fury.io/py/clai)
@@ -35,17 +40,30 @@ _________________
35
40
  _________________
36
41
 
37
42
  ## Installation
43
+
38
44
  1. The recommended installation method is to use `pipx`, via
39
- ```
45
+ ```bash
40
46
  pipx install clai
41
47
  ```
42
-
48
+ Optionally, install `tesseract` so that `clai` can read the screen context and send that along with requests:
49
+ ```bash
50
+ sudo apt install tesseract-ocr scrot
51
+ ```
43
52
  1. Then go to [OpenAI] and create an API Key. Once it's generated, add the following to
44
- your `.bashrc`:
53
+ your `~/.profile`:
45
54
  ```bash
46
55
  export OPENAI_API_TOKEN=<paste here>
47
56
  ```
48
57
 
58
+ 1. The best way to use this tool is in conjunction with the tool [shin][shin], which allows you
59
+ to run arbitrary bash commands in any textbox in a linux computer, using ibus. To use
60
+ that, install 'shin' via the fork above, then configure
61
+ it in your `~/.profile` to call `clai` by default:
62
+ ```bash
63
+ export SHIN_DEFAULT_COMMAND="clai"
64
+ ```
65
+ 1. Log out then log back in for the changes to take effect!
66
+
49
67
  [OpenAI]: https://platform.openai.com/account/api-keys
50
68
 
51
69
  ## Usage
@@ -54,6 +72,7 @@ Invoke the assistant with the format `clai <your prompt>`. For example:
54
72
  clai Write an email saying I'll be late to work because I'm working on commandline AIs
55
73
  ```
56
74
 
75
+
57
76
  ## Development
58
77
 
59
78
  ### Installing python dependencies
@@ -76,5 +95,5 @@ bash .github/format.sh
76
95
  bash .github/check_lint.sh
77
96
  ```
78
97
 
79
- # TODO: remove references to tests?
98
+ [shin]: https://github.com/apockill/shin
80
99
 
@@ -2,9 +2,11 @@
2
2
  Command Line AI- this tool lets you call ChatGPT from a CLI.
3
3
 
4
4
  I'm designing this to be used in conjunction with a fork of [shin][shin], which will allow you
5
- to call `clai` from any textbox in your computer. Finally, chatGPT everywhere!
5
+ to call `clai` from any textbox in your computer. Finally, ChatGPT everywhere!
6
+
7
+ The long-term vision for this project is to add support for extracting context. For example, it would
8
+ read the current text on a window and be able to add to it, or answer questions about it.
6
9
 
7
- [shin]: https://github.com/apockill/shin
8
10
  _________________
9
11
 
10
12
  [![PyPI version](https://badge.fury.io/py/clai.svg)](http://badge.fury.io/py/clai)
@@ -19,17 +21,30 @@ _________________
19
21
  _________________
20
22
 
21
23
  ## Installation
24
+
22
25
  1. The recommended installation method is to use `pipx`, via
23
- ```
26
+ ```bash
24
27
  pipx install clai
25
28
  ```
26
-
29
+ Optionally, install `tesseract` so that `clai` can read the screen context and send that along with requests:
30
+ ```bash
31
+ sudo apt install tesseract-ocr scrot
32
+ ```
27
33
  1. Then go to [OpenAI] and create an API Key. Once it's generated, add the following to
28
- your `.bashrc`:
34
+ your `~/.profile`:
29
35
  ```bash
30
36
  export OPENAI_API_TOKEN=<paste here>
31
37
  ```
32
38
 
39
+ 1. The best way to use this tool is in conjunction with the tool [shin][shin], which allows you
40
+ to run arbitrary bash commands in any textbox in a linux computer, using ibus. To use
41
+ that, install 'shin' via the fork above, then configure
42
+ it in your `~/.profile` to call `clai` by default:
43
+ ```bash
44
+ export SHIN_DEFAULT_COMMAND="clai"
45
+ ```
46
+ 1. Log out then log back in for the changes to take effect!
47
+
33
48
  [OpenAI]: https://platform.openai.com/account/api-keys
34
49
 
35
50
  ## Usage
@@ -38,6 +53,7 @@ Invoke the assistant with the format `clai <your prompt>`. For example:
38
53
  clai Write an email saying I'll be late to work because I'm working on commandline AIs
39
54
  ```
40
55
 
56
+
41
57
  ## Development
42
58
 
43
59
  ### Installing python dependencies
@@ -60,4 +76,4 @@ bash .github/format.sh
60
76
  bash .github/check_lint.sh
61
77
  ```
62
78
 
63
- # TODO: remove references to tests?
79
+ [shin]: https://github.com/apockill/shin
@@ -3,4 +3,4 @@
3
3
  Command Line AI- this tool lets you call ChatGPT from a CLI
4
4
  """
5
5
  __version__ = "0.1.0"
6
- from .invoke import invoke
6
+ from .main import main
@@ -0,0 +1,161 @@
1
+ from dataclasses import dataclass
2
+ from typing import Literal, Union
3
+
4
+ from clai.ocr_drivers import WindowContext
5
+
6
+ USER_PROMPT_FORMAT = """
7
+ User Prompt:
8
+ ```
9
+ {user_prompt}
10
+ ```
11
+ """
12
+ OCR_EXTRACTION_FORMAT = """
13
+ Active Window Title: {active_window_title}
14
+
15
+ Active Window OCR Extracted Text (RAW):
16
+ ------ OCR DATA START ------
17
+ ```
18
+ {ocr_text}
19
+ ```
20
+ ------ OCR DATA END ------
21
+
22
+ {user_prompt}
23
+
24
+ Please answer "User Prompt" using the raw OCR text as context to the message.
25
+ """
26
+
27
+
28
+ @dataclass
29
+ class Prompt:
30
+ context: WindowContext
31
+ prompt: str
32
+
33
+ def __str__(self) -> str:
34
+ """Serialize the Prompt with differing formats, depending on whether window
35
+ content was available
36
+
37
+ :return: The window context and prompt in a standardized format
38
+ """
39
+ """."""
40
+ user_prompt = USER_PROMPT_FORMAT.format(user_prompt=self.prompt.strip())
41
+ if self.context.clean_screen_text and self.context.active_window_name:
42
+ return OCR_EXTRACTION_FORMAT.format(
43
+ active_window_title=self.context.active_window_name.strip(),
44
+ ocr_text=self.context.clean_screen_text.strip(),
45
+ user_prompt=user_prompt.strip(),
46
+ )
47
+ return user_prompt.strip()
48
+
49
+
50
+ @dataclass
51
+ class Message:
52
+ role: Literal["system", "user", "assistant"]
53
+ content: Union[Prompt, str]
54
+
55
+ def to_api(self) -> dict[str, str]:
56
+ """To OpenAPI format"""
57
+ if isinstance(self.content, str) and self.role == "user":
58
+ raise RuntimeError("The user message must be of type Prompt!")
59
+
60
+ return {"role": self.role, "content": str(self.content)}
61
+
62
+
63
+ _DEFAULT_ASSISTANT_ROLE = """
64
+ You are an assistant that is capable of being called anywhere on a desktop computer. You
65
+ may be called within the context of an email, a URL box, commandline, a text editor, or
66
+ even word documents!
67
+
68
+ Your role is to answer the users request as shortly and succinctly as possible. You
69
+ will follow the following rules:
70
+
71
+ When asked to write long-form text content:
72
+ 1) Never ask for more information. If something is to be guessed, write it in template
73
+ format. For example, if asked to write an email use <Insert time here> when writing
74
+ the portion of an email that specifies something that was not included in the users
75
+ question.
76
+ 2) Only assume the content is long form if the user mentions email, or 'long message'.
77
+
78
+ When asked to write a command, code, formulas, or any one-line response task:
79
+ 1) NEVER WRITE EXPLANATIONS! Only include the command/code/etc, ready to be run
80
+ 2) NEVER WRITE USAGE INSTRUCTIONS! Do not explain how to use the command/code/formulas.
81
+ 3) NEVER WRITE NOTES ABOUT THE IMPLEMENTATION!
82
+ Do not explain what it does or it's limitations.
83
+ 4) Remember, the text that you write will immediately be run, do not include code blocks
84
+ 5) If there is something that requires user input, such as a cell in a sheet or a
85
+ variable from the user, write it inside of brackets, like this: <INPUT DESCRIBER>,
86
+ where the insides of the bracket have an example of what is needed to be filled in.
87
+ 6) Assume a linux desktop environment in a bash shell. Use freely available unix tools.
88
+
89
+ You will receive OCR context and window title names, for some prompts. They are very
90
+ noisy, use best-effort when reading them.
91
+ """
92
+ _EXAMPLE_EMAIL = """
93
+ Dear <Recipient's Name>,
94
+
95
+ I hope this email finds you well. I am writing to request a meeting with you on <Date and Time>, and I would appreciate it if you could confirm your availability at your earliest convenience.
96
+
97
+ The purpose of this meeting is to discuss <Purpose of the Meeting> with you. Specifically, I would like to <Agenda Item 1>, <Agenda Item 2>, and <Agenda Item 3>. The meeting will last approximately <Meeting Duration> and will take place at <Meeting Location>.
98
+
99
+ Please let me know if this date and time work for you. If not, please suggest an alternative time that is convenient for you. Additionally, if there are any documents or information you would like me to review before the meeting, please let me know, and I will make sure to review them.
100
+
101
+ I look forward to hearing from you soon.
102
+
103
+ Best regards,
104
+
105
+ <Your Name>
106
+ """ # noqa: E501
107
+ _EXAMPLE_REGEX = '=IFERROR(REGEXEXTRACT(<INPUT CELL HERE>, "[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}");"")' # noqa
108
+ _EXAMPLE_PYTHON = """
109
+ def fibonacci(n: int) -> Generator[int, None, None]:
110
+ a, b = 0, 1
111
+ for _ in range(n):
112
+ yield a
113
+ a, b = b, a + b
114
+ """
115
+ _EXAMPLE_GOOGLE_SHEETS = '=IFERROR(REGEXEXTRACT(<INPUT CELL HERE>, "[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}");"")' # noqa
116
+ _EXAMPLE_BASH_COMMAND = "grep -rnw . -e 'bruh'"
117
+
118
+ MESSAGE_CONTEXT: list[Message] = [
119
+ Message(role="system", content=_DEFAULT_ASSISTANT_ROLE),
120
+ Message(
121
+ role="user",
122
+ content=Prompt(
123
+ WindowContext(),
124
+ prompt="commandline search for files with the name 'bruh' in them",
125
+ ),
126
+ ),
127
+ Message(role="assistant", content=_EXAMPLE_BASH_COMMAND),
128
+ Message(
129
+ role="user",
130
+ content=Prompt(
131
+ context=WindowContext(), prompt="email set up a meeting next week"
132
+ ),
133
+ ),
134
+ Message(role="assistant", content=_EXAMPLE_EMAIL),
135
+ Message(
136
+ role="user",
137
+ content=Prompt(
138
+ context=WindowContext(),
139
+ prompt="google sheets formula extracts an email from string of text",
140
+ ),
141
+ ),
142
+ Message(role="assistant", content=_EXAMPLE_GOOGLE_SHEETS),
143
+ Message(
144
+ role="user",
145
+ content=Prompt(
146
+ context=WindowContext(),
147
+ prompt="google sheets formula extracts an email from string of text",
148
+ ),
149
+ ),
150
+ Message(role="assistant", content=_EXAMPLE_REGEX),
151
+ Message(
152
+ role="user",
153
+ content=Prompt(
154
+ context=WindowContext(),
155
+ prompt="python fibonacci function in form of a generator",
156
+ ),
157
+ ),
158
+ Message(role="assistant", content=_EXAMPLE_PYTHON),
159
+ ]
160
+
161
+ __all__ = ["MESSAGE_CONTEXT", "Message", "Prompt"]
@@ -0,0 +1,22 @@
1
+ from argparse import ArgumentParser
2
+
3
+ from .api import initialize_api
4
+ from .message_creation import create_message_context
5
+
6
+
7
+ def main() -> None:
8
+ parser = ArgumentParser("CLAI- your own command line AI!")
9
+ parser.add_argument("prompt", type=str, nargs="+")
10
+ parser.add_argument("-m", "--model", default="gpt-3.5-turbo")
11
+ args = parser.parse_args()
12
+
13
+ openai = initialize_api()
14
+
15
+ prompt = " ".join(args.prompt)
16
+ response = openai.ChatCompletion.create(
17
+ model=args.model,
18
+ messages=create_message_context(prompt),
19
+ )
20
+
21
+ best_response = response["choices"][0]["message"]["content"]
22
+ print(best_response)
@@ -0,0 +1,20 @@
1
+ from .behavior_context import MESSAGE_CONTEXT, Message, Prompt
2
+ from .ocr_drivers import get_driver
3
+
4
+
5
+ def create_message_context(prompt: str) -> list[dict[str, str]]:
6
+ """An important part of a ChatBot is the prior context. Here, we carefully
7
+ construct the context for the messages we are sending.
8
+
9
+ This function returns an OpenAI-API ready message with the prompt included.
10
+ :param prompt: The prompt for the chatbot
11
+ :return: The API-ready message
12
+ """
13
+ driver = get_driver()
14
+ window_context = driver.extract_context()
15
+ new_context = MESSAGE_CONTEXT[:]
16
+ new_context.append(
17
+ Message(role="user", content=Prompt(context=window_context, prompt=prompt))
18
+ )
19
+ api_format = [m.to_api() for m in new_context]
20
+ return api_format
@@ -0,0 +1,7 @@
1
+ from .base_driver import BaseOCRDriver, WindowContext
2
+ from .linux_driver import LinuxOCRDriver
3
+
4
+
5
+ def get_driver() -> BaseOCRDriver:
6
+ """In the future, we can return other OS compatible OCR solutions here"""
7
+ return LinuxOCRDriver()
@@ -0,0 +1,39 @@
1
+ from abc import ABC, abstractmethod
2
+ from dataclasses import dataclass
3
+ from typing import Optional
4
+
5
+ _MIN_CHARACTERS_PER_LINE = 10
6
+
7
+
8
+ @dataclass
9
+ class WindowContext:
10
+ raw_screen_text: Optional[str] = None
11
+ """If the driver supports it, the text extracted from the active window will be
12
+ filled here."""
13
+
14
+ active_window_name: Optional[str] = None
15
+ """If the driver supports it, the current active window name will be filled here."""
16
+
17
+ @property
18
+ def clean_screen_text(self) -> Optional[str]:
19
+ if not self.raw_screen_text:
20
+ return None
21
+
22
+ lines: list[str] = self.raw_screen_text.split("\n")
23
+ clean_lines = []
24
+ for line in lines:
25
+ line = line.strip()
26
+ if len(line) > _MIN_CHARACTERS_PER_LINE:
27
+ clean_lines.append(line)
28
+
29
+ clean_text = "\n".join(clean_lines)
30
+ return clean_text
31
+
32
+
33
+ class BaseOCRDriver(ABC):
34
+ """This base class can be used to standardize the interface for future OS's"""
35
+
36
+ @abstractmethod
37
+ def extract_context(self) -> WindowContext:
38
+ """A method to extract the current useful context from the in-focus window"""
39
+ pass
@@ -0,0 +1,35 @@
1
+ from typing import cast
2
+
3
+ import pyautogui
4
+ import pytesseract
5
+ import pywinctl
6
+ from PIL.Image import Image
7
+
8
+ from .base_driver import BaseOCRDriver, WindowContext
9
+
10
+
11
+ class LinuxOCRDriver(BaseOCRDriver):
12
+ def extract_context(self) -> WindowContext:
13
+ screenshot = self._extract_active_window_screenshot()
14
+
15
+ # Perform OCR and clean up the text
16
+ raw_ocr_text = pytesseract.image_to_string(screenshot)
17
+
18
+ return WindowContext(
19
+ raw_screen_text=raw_ocr_text,
20
+ active_window_name=cast(str, pywinctl.getActiveWindowTitle()),
21
+ )
22
+
23
+ def _extract_active_window_screenshot(self) -> Image:
24
+ # Get the active window object
25
+ active_window = pywinctl.getActiveWindow() # type: ignore
26
+ region = (
27
+ active_window.left,
28
+ active_window.top,
29
+ active_window.width,
30
+ active_window.height,
31
+ )
32
+
33
+ # Take a screenshot of the active window
34
+ screenshot = pyautogui.screenshot(region=region)
35
+ return screenshot
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "clai"
3
- version = "0.1.0"
3
+ version = "0.3.0"
4
4
  description = "Command Line AI- this tool lets you call ChatGPT from a CLI"
5
5
  authors = ["apockill <apocthiel@gmail.com>"]
6
6
  license = "Proprietary"
@@ -9,6 +9,9 @@ readme = "README.md"
9
9
  [tool.poetry.dependencies]
10
10
  python = "^3.8"
11
11
  openai = "^0.27.0"
12
+ pytesseract = "^0.3.10"
13
+ PyAutoGUI = "^0.9.53"
14
+ PyWinCtl = "^0.0.43"
12
15
 
13
16
  [tool.poetry.dev-dependencies]
14
17
  darglint = "^1.8.1"
@@ -25,8 +28,8 @@ portray = "^1.7"
25
28
  cruft = "^2.10"
26
29
 
27
30
  [tool.poetry.scripts]
28
- clai = "clai:invoke"
29
- ai = "clai:invoke"
31
+ clai = "clai:main"
32
+ ai = "clai:main"
30
33
 
31
34
  [build-system]
32
35
  requires = ["poetry>=0.12"]
clai-0.3.0/setup.py ADDED
@@ -0,0 +1,37 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ packages = \
5
+ ['clai', 'clai.ocr_drivers']
6
+
7
+ package_data = \
8
+ {'': ['*']}
9
+
10
+ install_requires = \
11
+ ['PyAutoGUI>=0.9.53,<0.10.0',
12
+ 'PyWinCtl>=0.0.43,<0.0.44',
13
+ 'openai>=0.27.0,<0.28.0',
14
+ 'pytesseract>=0.3.10,<0.4.0']
15
+
16
+ entry_points = \
17
+ {'console_scripts': ['ai = clai:main', 'clai = clai:main']}
18
+
19
+ setup_kwargs = {
20
+ 'name': 'clai',
21
+ 'version': '0.3.0',
22
+ 'description': 'Command Line AI- this tool lets you call ChatGPT from a CLI',
23
+ 'long_description': '# clai\nCommand Line AI- this tool lets you call ChatGPT from a CLI. \n\nI\'m designing this to be used in conjunction with a fork of [shin][shin], which will allow you\nto call `clai` from any textbox in your computer. Finally, ChatGPT everywhere!\n\nThe long-term vision for this project is to add support for extracting context. For example, it would\nread the current text on a window and be able to add to it, or answer questions about it.\n\n_________________\n\n[![PyPI version](https://badge.fury.io/py/clai.svg)](http://badge.fury.io/py/clai)\n[![Test Status](https://github.com/apockill/clai/workflows/Test/badge.svg?branch=main)](https://github.com/apockill/clai/actions?query=workflow%3ATest)\n[![Lint Status](https://github.com/apockill/clai/workflows/Lint/badge.svg?branch=main)](https://github.com/apockill/clai/actions?query=workflow%3ALint)\n[![codecov](https://codecov.io/gh/apockill/clai/branch/main/graph/badge.svg)](https://codecov.io/gh/apockill/clai)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://timothycrosley.github.io/isort/)\n_________________\n\n[Read Latest Documentation](https://apockill.github.io/clai/) - [Browse GitHub Code Repository](https://github.com/apockill/clai/)\n_________________\n\n## Installation\n\n1. The recommended installation method is to use `pipx`, via\n ```bash\n pipx install clai\n ```\n Optionally, install `tesseract` so that `clai` can read the screen context and send that along with requests:\n ```bash\n sudo apt install tesseract-ocr scrot\n ```\n1. Then go to [OpenAI] and create an API Key. Once it\'s generated, add the following to \n your `~/.profile`:\n ```bash\n export OPENAI_API_TOKEN=<paste here>\n ```\n\n1. The best way to use this tool is in conjunction with the tool [shin][shin], which allows you\n to run arbitrary bash commands in any textbox in a linux computer, using ibus. To use \n that, install \'shin\' via the fork above, then configure\n it in your `~/.profile` to call `clai` by default:\n ```bash\n export SHIN_DEFAULT_COMMAND="clai"\n ```\n1. Log out then log back in for the changes to take effect!\n\n[OpenAI]: https://platform.openai.com/account/api-keys\n\n## Usage\nInvoke the assistant with the format `clai <your prompt>`. For example:\n```\nclai Write an email saying I\'ll be late to work because I\'m working on commandline AIs\n```\n\n\n## Development\n\n### Installing python dependencies\n```shell\npoetry install\n```\n\n### Running Tests\n```shell\npytest .\n```\n\n### Formatting Code\n```shell\nbash .github/format.sh\n```\n\n### Linting\n```shell\nbash .github/check_lint.sh\n```\n\n[shin]: https://github.com/apockill/shin\n',
24
+ 'author': 'apockill',
25
+ 'author_email': 'apocthiel@gmail.com',
26
+ 'maintainer': 'None',
27
+ 'maintainer_email': 'None',
28
+ 'url': 'None',
29
+ 'packages': packages,
30
+ 'package_data': package_data,
31
+ 'install_requires': install_requires,
32
+ 'entry_points': entry_points,
33
+ 'python_requires': '>=3.8,<4.0',
34
+ }
35
+
36
+
37
+ setup(**setup_kwargs)
clai-0.1.0/clai/invoke.py DELETED
@@ -1,103 +0,0 @@
1
- from argparse import ArgumentParser
2
-
3
- from .api import initialize_api
4
-
5
- DEFAULT_ASSISTANT_ROLE = """
6
- You are an assistant that is capable of being called anywhere on a desktop computer. You
7
- may be called within the context of an email, a URL box, commandline, a text editor, or
8
- even word documents!
9
-
10
- Your role is to answer the users request as shortly and succinctly as possible. You
11
- will follow the following rules:
12
-
13
- When asked to write a command:
14
- 1) Assume a linux desktop environment in a bash shell
15
- 2) Feel free to use commonly installed unix tools
16
-
17
- When asked to write a command, code, formulas, or any one-line response task:
18
- 1) NEVER WRITE EXPLANATIONS. Only include the command/code/etc, ready to be run
19
- 2) NEVER WRITE USAGE INSTRUCTIONS.
20
- 3) Remember, the text that you write will immediately be run, do not include code blocks
21
- 4) If there is something that requires user input, such as a cell in a sheet or a
22
- variable from the user, write it inside of brackets, like this: <INPUT DESCRIBER>,
23
- where the insides of the bracket have an example of what is needed to be filled in.
24
-
25
- When asked to write long-form text content:
26
- 1) Never ask for more information. If something is to be guessed, write it in template
27
- format. For example, if asked to write an email use <Insert time here> when writing
28
- the portion of an email that specifies something that was not included in the users
29
- question.
30
- 2) Only assume the content is long form if the user mentions email, or 'long message'.
31
- """
32
-
33
- EXAMPLE_EMAIL = """
34
- Dear <Recipient's Name>,
35
-
36
- I hope this email finds you well. I am writing to request a meeting with you on <Date and Time>, and I would appreciate it if you could confirm your availability at your earliest convenience.
37
-
38
- The purpose of this meeting is to discuss <Purpose of the Meeting> with you. Specifically, I would like to <Agenda Item 1>, <Agenda Item 2>, and <Agenda Item 3>. The meeting will last approximately <Meeting Duration> and will take place at <Meeting Location>.
39
-
40
- Please let me know if this date and time work for you. If not, please suggest an alternative time that is convenient for you. Additionally, if there are any documents or information you would like me to review before the meeting, please let me know, and I will make sure to review them.
41
-
42
- I look forward to hearing from you soon.
43
-
44
- Best regards,
45
-
46
- <Your Name>
47
- """ # noqa: E501
48
-
49
- EXAMPLE_REGEX = '=IFERROR(REGEXEXTRACT(<INPUT CELL HERE>, "[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,4}");"")' # noqa
50
-
51
- EXAMPLE_PYTHON = """
52
- def fibonacci(n: int) -> Generator[int, None, None]:
53
- a, b = 0, 1
54
- for _ in range(n):
55
- yield a
56
- a, b = b, a + b
57
- """
58
- CONTEXT = [
59
- {"role": "system", "content": DEFAULT_ASSISTANT_ROLE},
60
- {
61
- "role": "user",
62
- "content": "commandline search for files with the name 'bruh' in them",
63
- },
64
- {"role": "assistant", "content": "grep -rnw . -e 'bruh'"},
65
- {
66
- "role": "user",
67
- "content": "email set up a meeting next week",
68
- },
69
- {"role": "assistant", "content": EXAMPLE_EMAIL},
70
- {
71
- "role": "user",
72
- "content": "google sheets formula extracts an email from string of text",
73
- },
74
- {
75
- "role": "assistant",
76
- "content": EXAMPLE_REGEX,
77
- },
78
- {
79
- "role": "user",
80
- "content": "python fibonacci function in form of a generator",
81
- },
82
- {
83
- "role": "assistant",
84
- "content": EXAMPLE_PYTHON,
85
- },
86
- ]
87
-
88
-
89
- def invoke() -> None:
90
- parser = ArgumentParser("CLAI- your own command line AI!")
91
- parser.add_argument("prompt", type=str, nargs="+")
92
- parser.add_argument("-e", "--engine", default="")
93
- args = parser.parse_args()
94
-
95
- openai = initialize_api()
96
-
97
- prompt = " ".join(args.prompt)
98
- response = openai.ChatCompletion.create(
99
- model="gpt-3.5-turbo", messages=[*CONTEXT, {"role": "user", "content": prompt}]
100
- )
101
-
102
- best_response = response["choices"][0]["message"]["content"]
103
- print(best_response.strip())
clai-0.1.0/setup.py DELETED
@@ -1,34 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['clai']
6
-
7
- package_data = \
8
- {'': ['*']}
9
-
10
- install_requires = \
11
- ['openai>=0.27.0,<0.28.0']
12
-
13
- entry_points = \
14
- {'console_scripts': ['ai = clai:invoke', 'clai = clai:invoke']}
15
-
16
- setup_kwargs = {
17
- 'name': 'clai',
18
- 'version': '0.1.0',
19
- 'description': 'Command Line AI- this tool lets you call ChatGPT from a CLI',
20
- 'long_description': "# clai\nCommand Line AI- this tool lets you call ChatGPT from a CLI. \n\nI'm designing this to be used in conjunction with a fork of [shin][shin], which will allow you\nto call `clai` from any textbox in your computer. Finally, chatGPT everywhere!\n\n[shin]: https://github.com/apockill/shin\n_________________\n\n[![PyPI version](https://badge.fury.io/py/clai.svg)](http://badge.fury.io/py/clai)\n[![Test Status](https://github.com/apockill/clai/workflows/Test/badge.svg?branch=main)](https://github.com/apockill/clai/actions?query=workflow%3ATest)\n[![Lint Status](https://github.com/apockill/clai/workflows/Lint/badge.svg?branch=main)](https://github.com/apockill/clai/actions?query=workflow%3ALint)\n[![codecov](https://codecov.io/gh/apockill/clai/branch/main/graph/badge.svg)](https://codecov.io/gh/apockill/clai)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://timothycrosley.github.io/isort/)\n_________________\n\n[Read Latest Documentation](https://apockill.github.io/clai/) - [Browse GitHub Code Repository](https://github.com/apockill/clai/)\n_________________\n\n## Installation\n1. The recommended installation method is to use `pipx`, via\n ```\n pipx install clai\n ```\n\n1. Then go to [OpenAI] and create an API Key. Once it's generated, add the following to \n your `.bashrc`:\n ```bash\n export OPENAI_API_TOKEN=<paste here>\n ```\n\n[OpenAI]: https://platform.openai.com/account/api-keys\n\n## Usage\nInvoke the assistant with the format `clai <your prompt>`. For example:\n```\nclai Write an email saying I'll be late to work because I'm working on commandline AIs\n```\n\n## Development\n\n### Installing python dependencies\n```shell\npoetry install\n```\n\n### Running Tests\n```shell\npytest .\n```\n\n### Formatting Code\n```shell\nbash .github/format.sh\n```\n\n### Linting\n```shell\nbash .github/check_lint.sh\n```\n\n# TODO: remove references to tests?\n",
21
- 'author': 'apockill',
22
- 'author_email': 'apocthiel@gmail.com',
23
- 'maintainer': 'None',
24
- 'maintainer_email': 'None',
25
- 'url': 'None',
26
- 'packages': packages,
27
- 'package_data': package_data,
28
- 'install_requires': install_requires,
29
- 'entry_points': entry_points,
30
- 'python_requires': '>=3.8,<4.0',
31
- }
32
-
33
-
34
- setup(**setup_kwargs)
File without changes