matheus 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/Rakefile +39 -0
- data/exe/date-of-last +1 -1
- data/exe/q +7 -0
- data/lib/matheus/date_of_last.rb +7 -7
- data/lib/matheus/puts.rb +3 -2
- data/lib/matheus/q.rb +42 -0
- data/lib/matheus/version.rb +1 -1
- data/lib/matheus.rb +3 -0
- metadata +50 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08561d64b6400b698a4a1e0392db8b6e334f16fcdc82eddc77b94f3c119fccaf'
|
4
|
+
data.tar.gz: ed62993f879971fa1ba7c9f6da817fe2f69f229c4ad29c9d9520e3f9f0cd30e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa24b6dc461527791a9960c7bd374635cf511cce3f51c9c6d4ac7b83f5abac79faf8b0c5f74b479660a53e7546ee9cf72b71c1976845d85f2ae3be1028559dd
|
7
|
+
data.tar.gz: f1fa29a3e1caad57abcd2498d607367f2c70132ef8c34e083ddd020775182c29e07565c54996a1f1f46d696834c66c95c444adfb64575f1e64cfd51bcf421cf0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0]
|
4
|
+
|
5
|
+
_Released 2024-08-26_
|
6
|
+
|
7
|
+
- Add `q` command to ask an question to an LLM
|
8
|
+
|
9
|
+
```sh
|
10
|
+
$ q "What is the capital of France?"
|
11
|
+
The capital of France is **Paris**
|
12
|
+
```
|
13
|
+
|
14
|
+
- Automatically generate executables for the commands when the gem builds.
|
15
|
+
|
16
|
+
## [0.1.0]
|
17
|
+
|
18
|
+
_Released 2024-02-19_
|
4
19
|
|
5
20
|
- Initial release. It includes the commands:
|
6
21
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,46 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rspec/core/rake_task"
|
5
|
+
require "active_support"
|
6
|
+
require "active_support/core_ext"
|
5
7
|
|
6
8
|
RSpec::Core::RakeTask.new(:spec)
|
7
9
|
|
8
10
|
task default: :spec
|
11
|
+
|
12
|
+
desc "Generate executables for command classes"
|
13
|
+
task :generate_executables do
|
14
|
+
require "fileutils"
|
15
|
+
|
16
|
+
# Load the gem's library files
|
17
|
+
$LOAD_PATH.unshift("#{__dir__}/lib")
|
18
|
+
|
19
|
+
require "matheus"
|
20
|
+
|
21
|
+
Zeitwerk::Loader.eager_load_all
|
22
|
+
|
23
|
+
exe_dir = File.expand_path("#{__dir__}/exe")
|
24
|
+
|
25
|
+
Matheus::Command.descendants.each do |command_class|
|
26
|
+
script_path = File.join(exe_dir, command_class.name.demodulize.underscore.dasherize)
|
27
|
+
next if File.exist?(script_path)
|
28
|
+
|
29
|
+
script_content = <<~SCRIPT
|
30
|
+
#!/usr/bin/env ruby
|
31
|
+
|
32
|
+
$LOAD_PATH.unshift("\#{__dir__}/../lib")
|
33
|
+
|
34
|
+
require "matheus"
|
35
|
+
|
36
|
+
Matheus::#{command_class.name.demodulize}.call ARGV
|
37
|
+
SCRIPT
|
38
|
+
|
39
|
+
File.write(script_path, script_content)
|
40
|
+
FileUtils.chmod("+x", script_path)
|
41
|
+
|
42
|
+
puts "Generated executable: #{script_path}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Ensure the generate_executables task runs before the build task
|
47
|
+
task build: :generate_executables
|
data/exe/date-of-last
CHANGED
data/exe/q
ADDED
data/lib/matheus/date_of_last.rb
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
require "date"
|
4
4
|
|
5
5
|
module Matheus
|
6
|
+
# Usage:
|
7
|
+
# $ date-of-last monday
|
8
|
+
# 2022-01-24
|
6
9
|
class DateOfLast < Command
|
7
|
-
def call(
|
8
|
-
day_name =
|
10
|
+
def call(args)
|
11
|
+
day_name = args[0].to_s
|
9
12
|
|
10
|
-
target_wday = wday_for(day_name) or return Failure("invalid day name: #{day_name}")
|
11
|
-
date = Date.today
|
12
|
-
one_day_ago = (date - 1)
|
13
|
-
one_week_ago = date - 7
|
14
|
-
date = one_day_ago.downto(one_week_ago).find { _1.wday == target_wday }
|
13
|
+
target_wday = wday_for(day_name) or return Failure("invalid day name: #{day_name.inspect}")
|
14
|
+
date = Enumerator.produce(Date.today - 1, &:prev_day).find { _1.wday == target_wday }
|
15
15
|
|
16
16
|
puts date
|
17
17
|
end
|
data/lib/matheus/puts.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "date"
|
4
|
-
require "active_support"
|
5
|
-
require "active_support/core_ext"
|
6
4
|
|
7
5
|
module Matheus
|
6
|
+
# Usage:
|
7
|
+
# $ puts "Date.today"
|
8
|
+
# 2024-08-26
|
8
9
|
class Puts < Command
|
9
10
|
def call(argv)
|
10
11
|
puts eval(argv.join(" ")) # standard:disable Security/Eval
|
data/lib/matheus/q.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "openai"
|
2
|
+
require "tty-markdown"
|
3
|
+
|
4
|
+
module Matheus
|
5
|
+
# Usage:
|
6
|
+
# $ q "What is the capital of France?"
|
7
|
+
# The capital of France is Paris.
|
8
|
+
class Q < Command
|
9
|
+
BASE_PROMPT = "Answer this question in a short and concise way. You can use markdown in the response: "
|
10
|
+
|
11
|
+
def call(question)
|
12
|
+
ask_llm(question).then { print_markdown _1 }
|
13
|
+
rescue => e
|
14
|
+
Failure(e.message)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ask_llm(question)
|
20
|
+
raise "Question can't be blank." if question.blank?
|
21
|
+
|
22
|
+
response = client.chat(
|
23
|
+
parameters: {
|
24
|
+
model: "gpt-4o-mini", # using gpt-4o model
|
25
|
+
messages: [{role: "user", content: "#{BASE_PROMPT}#{question}"}]
|
26
|
+
}
|
27
|
+
)
|
28
|
+
|
29
|
+
raise response["error"]["message"] if response.has_key?("error")
|
30
|
+
|
31
|
+
response.dig("choices", 0, "message", "content")
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_markdown(text)
|
35
|
+
puts TTY::Markdown.parse(text)
|
36
|
+
end
|
37
|
+
|
38
|
+
def client
|
39
|
+
OpenAI::Client.new(access_token: ENV.fetch("OPENAI_API_KEY"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/matheus/version.rb
CHANGED
data/lib/matheus.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: matheus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matheus Richard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -16,16 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.6.
|
19
|
+
version: 2.6.17
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.6.
|
26
|
+
version: 2.6.17
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-openai
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
@@ -38,12 +52,41 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 7.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-markdown
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.2
|
41
83
|
description: A bunch of CLI tools I made for my own use.
|
42
84
|
email:
|
43
85
|
- matheusrichardt@gmail.com
|
44
86
|
executables:
|
45
87
|
- date-of-last
|
46
88
|
- puts
|
89
|
+
- q
|
47
90
|
extensions: []
|
48
91
|
extra_rdoc_files: []
|
49
92
|
files:
|
@@ -55,10 +98,12 @@ files:
|
|
55
98
|
- Rakefile
|
56
99
|
- exe/date-of-last
|
57
100
|
- exe/puts
|
101
|
+
- exe/q
|
58
102
|
- lib/matheus.rb
|
59
103
|
- lib/matheus/command.rb
|
60
104
|
- lib/matheus/date_of_last.rb
|
61
105
|
- lib/matheus/puts.rb
|
106
|
+
- lib/matheus/q.rb
|
62
107
|
- lib/matheus/result.rb
|
63
108
|
- lib/matheus/string_format.rb
|
64
109
|
- lib/matheus/version.rb
|
@@ -84,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
129
|
- !ruby/object:Gem::Version
|
85
130
|
version: '0'
|
86
131
|
requirements: []
|
87
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.5.6
|
88
133
|
signing_key:
|
89
134
|
specification_version: 4
|
90
135
|
summary: A bunch of CLI tools I made for my own use.
|