clai 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +2 -3
- data/README.md +10 -10
- data/docs/chat.md +4 -2
- data/docs/intro.md +2 -2
- data/docs/personas.md +28 -15
- data/docs/session.md +10 -1
- data/docs/setup.md +3 -1
- data/lib/clai/cli.rb +12 -2
- data/lib/clai/commands/chat.rb +3 -2
- data/lib/clai/commands/session.rb +3 -2
- data/lib/clai/commands/setup.rb +7 -0
- data/lib/clai/config.rb +8 -3
- data/lib/clai/http_client.rb +4 -2
- data/lib/clai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a0492d4b34d7e6366d5a05b262333e11acee78b80fff34e5fa37c4eb1ce6dc
|
4
|
+
data.tar.gz: 51ca0c434ad228d034a7879d5ad6c05b7892912173e8ab3659539b52d00d2ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a817fb1aaa112664e6647d6480eb6eb42c837d48db311f92ff7dd34ea08c1b308cca77011117b46a4100386071f0ac59773ff515c34ebefcc895a4670e1e1fe9
|
7
|
+
data.tar.gz: e40075423db3770dfad17e272bd8cd403f5be4c50cabd8ec0b4f05efaec3049f0ac3461fbf4c43c48803546be7026470da8558940e0ab6521a4a450dacd29f36
|
data/CONTRIBUTING.md
CHANGED
@@ -3,15 +3,14 @@
|
|
3
3
|
The following topics are missing for a 1.0.0 release:
|
4
4
|
|
5
5
|
```
|
6
|
-
*
|
7
|
-
* Rewrite with tests as soon as the basic prototype is useful
|
6
|
+
* Rewrite/Refactor with tests as soon as the basic prototype is useful
|
8
7
|
* Add GitHub Actions for PRs
|
9
8
|
* Build a landing page
|
10
9
|
```
|
11
10
|
|
12
11
|
Please use `clai` and contribute here on GitHub. I'm open to all suggestions and improvements.
|
13
12
|
|
14
|
-
0.x.x versions don't need tests or extensive documentation. Adding a small description will help me understand your change though :)
|
13
|
+
PRs for the 0.x.x versions don't need tests or extensive documentation. Adding a small description will help me understand your change though :)
|
15
14
|
|
16
15
|
Please open a PR with a short description of your use-case and I will review and merge.
|
17
16
|
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ CLAI (CLI + AI = CLAI) allows you to interact with the OpenAI API in your termin
|
|
13
13
|
First, ensure that you have Ruby installed on your system. Then, you can install the gem by running:
|
14
14
|
|
15
15
|
```
|
16
|
-
|
16
|
+
gem install clai
|
17
17
|
```
|
18
18
|
|
19
19
|
## Configuration
|
@@ -21,7 +21,7 @@ $ gem install clai
|
|
21
21
|
Before using the CLI tool, you need to configure it with your OpenAI API key. You can obtain an API key from the OpenAI website. Once you have your API key, run the following command and provide your key when prompted:
|
22
22
|
|
23
23
|
```
|
24
|
-
|
24
|
+
clai setup
|
25
25
|
```
|
26
26
|
|
27
27
|
This will create a configuration file (`~/.config/clai/clai.yml`) on your system.
|
@@ -33,7 +33,7 @@ Read more about the setup command [here](docs/setup.md).
|
|
33
33
|
You can chat with ChatGPT with:
|
34
34
|
|
35
35
|
```
|
36
|
-
|
36
|
+
clai chat "Tell me a funny joke"
|
37
37
|
```
|
38
38
|
|
39
39
|
This will send the given prompt to the API and display the generated completion.
|
@@ -43,7 +43,7 @@ This will send the given prompt to the API and display the generated completion.
|
|
43
43
|
To view the available commands and options, you can use the `help` command:
|
44
44
|
|
45
45
|
```
|
46
|
-
|
46
|
+
clai help
|
47
47
|
```
|
48
48
|
|
49
49
|
This will display a list of supported commands and their descriptions.
|
@@ -53,7 +53,7 @@ This will display a list of supported commands and their descriptions.
|
|
53
53
|
You can start an interactive session with `clai session` command.
|
54
54
|
|
55
55
|
```
|
56
|
-
|
56
|
+
clai session
|
57
57
|
Your prompt: <Enter your prompt here><Enter>
|
58
58
|
```
|
59
59
|
|
@@ -63,18 +63,18 @@ This will start a REPL like process to interact with the OpenAI api.
|
|
63
63
|
|
64
64
|
Here are a few examples to get you started:
|
65
65
|
|
66
|
-
```
|
66
|
+
```
|
67
67
|
# Setup clai on your machine
|
68
|
-
|
68
|
+
clai setup
|
69
69
|
|
70
70
|
# Start an interactive chat session
|
71
|
-
|
71
|
+
clai session
|
72
72
|
|
73
73
|
# Get help about the available commands and options
|
74
|
-
|
74
|
+
clai help
|
75
75
|
|
76
76
|
# Send a single prompt
|
77
|
-
|
77
|
+
clai chat "Hello World"
|
78
78
|
```
|
79
79
|
|
80
80
|
## Contributing
|
data/docs/chat.md
CHANGED
data/docs/intro.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Introduction
|
2
2
|
|
3
3
|
You can think of `clai` as ChatGPT for the terminal.
|
4
|
-
It's very basic at the moment.
|
4
|
+
It's very basic at the moment. I'm currently trying to incorporate clai in my daily work, so I'm still experimenting with the API.
|
5
5
|
|
6
6
|
`clai` currently supports OpenAI and needs a paid API key to work.
|
7
7
|
|
8
8
|
My main use case currently is to have a terminal opened with a clai session and ask questions instead of googling.
|
9
9
|
|
10
|
-
0.x.0 will be unstable and untested, I'm currently aiming to release a tested 1.0.0 soon. Please see [here](https://github.com/codergeek121/clai/CONTRIBUTING.MD) on how to contribute at
|
10
|
+
0.x.0 will be unstable and untested, I'm currently aiming to release a tested 1.0.0 soon. Please see [here](https://github.com/codergeek121/clai/CONTRIBUTING.MD) on how to contribute at the current stage of the project.
|
data/docs/personas.md
CHANGED
@@ -1,23 +1,36 @@
|
|
1
1
|
# Personas
|
2
2
|
|
3
|
-
|
3
|
+
Clai allows you to configure different personas. Whenever you're calling clai, it's possible to pass a specified persona with `--persona`. This will pass system prompts to ChatGPT. It works similar to "Custom instructions" in ChatGPT.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
An example could look like this:
|
5
|
+
The base clai setup comes with the following default personas config:
|
8
6
|
|
9
7
|
```yaml
|
10
8
|
personas:
|
11
|
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
|
15
|
-
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
default:
|
10
|
+
- You are a helpful assistant
|
11
|
+
- You answers are formatted in markdown
|
12
|
+
ruby:
|
13
|
+
- You are a ruby programmer
|
14
|
+
- You do not comment your code
|
15
|
+
```
|
16
|
+
|
17
|
+
Compare the outputs when using different personas.
|
18
|
+
|
19
|
+
```
|
20
|
+
$ clai chat "Count to 10" --persona ruby
|
21
|
+
Sure, here's how you can count to 10 in Ruby:
|
22
|
+
|
23
|
+
(1..10).each do |num|
|
24
|
+
puts num
|
25
|
+
end
|
26
|
+
|
27
|
+
// Without a persona, fallbacks to the "default" persona
|
28
|
+
$ clai chat "Count to 10"
|
29
|
+
|
30
|
+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
31
|
+
|
32
|
+
// Start a ruby persona session
|
33
|
+
$ clai session --persona ruby
|
21
34
|
```
|
22
35
|
|
23
|
-
The default
|
36
|
+
The persona under the key `default:` is used whenever you're not specifying a explicit persona.
|
data/docs/session.md
CHANGED
data/docs/setup.md
CHANGED
data/lib/clai/cli.rb
CHANGED
@@ -2,24 +2,34 @@ module CLAI
|
|
2
2
|
class CLI < Thor
|
3
3
|
default_task :session
|
4
4
|
|
5
|
+
option :persona, type: :string
|
5
6
|
desc "session", "Start an interactive chat session"
|
6
7
|
long_desc <<~DESC
|
7
8
|
Starts a REPL like chat process
|
8
9
|
|
9
10
|
> $ clai session
|
11
|
+
|
12
|
+
Use a preconfigured persona with --persona
|
13
|
+
|
14
|
+
> $ clai chat "Count to 10" --persona ruby
|
10
15
|
DESC
|
11
16
|
def session
|
12
|
-
Commands::Session.new(config).start_session
|
17
|
+
Commands::Session.new(config).start_session(persona: options['persona'])
|
13
18
|
end
|
14
19
|
|
20
|
+
option :persona, type: :string
|
15
21
|
desc "chat", "Prompt on the terminal"
|
16
22
|
long_desc <<~DESC
|
17
23
|
Send a single prompt to AI
|
18
24
|
|
19
25
|
> $ clai chat "Tell me a short story!"
|
26
|
+
|
27
|
+
Use a preconfigured persona with --persona
|
28
|
+
|
29
|
+
> $ clai chat "Count to 10" --persona ruby
|
20
30
|
DESC
|
21
31
|
def chat(prompt)
|
22
|
-
Commands::Chat.new(config).chat(prompt)
|
32
|
+
Commands::Chat.new(config).chat(prompt, persona: options['persona'])
|
23
33
|
end
|
24
34
|
|
25
35
|
option :force, type: :boolean, default: false
|
data/lib/clai/commands/chat.rb
CHANGED
@@ -5,8 +5,9 @@ module CLAI
|
|
5
5
|
@config = config
|
6
6
|
end
|
7
7
|
|
8
|
-
def chat(prompt)
|
9
|
-
|
8
|
+
def chat(prompt, persona: 'default')
|
9
|
+
system_prompts = @config.personas.fetch(persona, [])
|
10
|
+
HTTPClient.new(@config).chat(prompt, system_prompts: system_prompts)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -5,12 +5,13 @@ module CLAI
|
|
5
5
|
@config = config
|
6
6
|
end
|
7
7
|
|
8
|
-
def start_session
|
8
|
+
def start_session(persona: 'default')
|
9
|
+
system_prompts = @config.personas.fetch(persona, [])
|
9
10
|
loop do
|
10
11
|
print S.(:prompt)
|
11
12
|
question = $stdin.gets
|
12
13
|
break unless question
|
13
|
-
HTTPClient.new(@config).chat(question.strip)
|
14
|
+
HTTPClient.new(@config).chat(question.strip, system_prompts: system_prompts)
|
14
15
|
puts
|
15
16
|
end
|
16
17
|
end
|
data/lib/clai/commands/setup.rb
CHANGED
@@ -42,6 +42,13 @@ module CLAI
|
|
42
42
|
# Read more about the clai.yml config file at https://github.com/codergeek121/clai/docs/setup.md
|
43
43
|
api_key: #{@api_key}
|
44
44
|
model: gpt-3.5-turbo
|
45
|
+
personas:
|
46
|
+
default:
|
47
|
+
- You are a helpful assistant
|
48
|
+
- You answers are formatted in markdown
|
49
|
+
ruby:
|
50
|
+
- You are a ruby programmer
|
51
|
+
- You do not comment your code
|
45
52
|
YML
|
46
53
|
end
|
47
54
|
end
|
data/lib/clai/config.rb
CHANGED
@@ -2,17 +2,22 @@ module CLAI
|
|
2
2
|
class Config
|
3
3
|
def self.parse
|
4
4
|
config = YAML.safe_load_file(CLAI.config_file_path)
|
5
|
-
new(
|
5
|
+
new(
|
6
|
+
api_key: config["api_key"],
|
7
|
+
model: config["model"],
|
8
|
+
personas: config["personas"]
|
9
|
+
)
|
6
10
|
rescue Errno::ENOENT
|
7
11
|
puts S.(:no_clai_yml)
|
8
12
|
exit(false)
|
9
13
|
end
|
10
14
|
|
11
|
-
attr_reader :api_key, :model
|
15
|
+
attr_reader :api_key, :model, :personas
|
12
16
|
|
13
|
-
def initialize(api_key:, model:)
|
17
|
+
def initialize(api_key:, model:, personas:)
|
14
18
|
@api_key = api_key
|
15
19
|
@model = model
|
20
|
+
@personas = personas
|
16
21
|
end
|
17
22
|
end
|
18
23
|
end
|
data/lib/clai/http_client.rb
CHANGED
@@ -4,14 +4,16 @@ module CLAI
|
|
4
4
|
@config = config
|
5
5
|
end
|
6
6
|
|
7
|
-
def chat(query)
|
7
|
+
def chat(query, system_prompts: [])
|
8
|
+
system_prompts = system_prompts.map { |prompt| { role: :system, content: prompt } }
|
8
9
|
puts
|
9
10
|
client
|
10
11
|
.post("https://api.openai.com/v1/chat/completions",
|
11
12
|
json: {
|
12
13
|
model: @config.model,
|
13
14
|
messages: [
|
14
|
-
|
15
|
+
*system_prompts,
|
16
|
+
{ "role": "user", "content": query },
|
15
17
|
],
|
16
18
|
stream: true
|
17
19
|
}
|
data/lib/clai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Niklas Häusele
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|