tiny_pair 1.0.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/lib/tiny_pair.rb +49 -18
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2977ae760f8e81ef8aa7dda582cd99efeb159f58183c704fbe3b68e6f6f0eb98
|
4
|
+
data.tar.gz: 870bd35db707a58b45aa6ac7031d6361bf01f0e5f58a223ddf9f87e3f729ced7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 282da0f95ba8017b5e65e6d09207b400be09111788a09038ad9d04646d594b4060bf83633b2dafea77878d780033527ec1046479c90dbce78524c204aabcc106
|
7
|
+
data.tar.gz: 8d77e1d6fb175755307d4386cc55ea84072d3ad860ddabc46acb7859d1f60c5430e8fd36f0db8f2fe06888c87b65fed19965e7c791e0d58a9d451d215550a875
|
data/lib/tiny_pair.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'gemini-ai'
|
2
2
|
|
3
3
|
# if you can write the specification for some code, shouldn't the computer be
|
4
4
|
# able to write the implementation?
|
@@ -6,18 +6,22 @@ require 'tiny_gemini'
|
|
6
6
|
# get your Google Gemini API key ready, and then run the following code to see
|
7
7
|
# what happens:
|
8
8
|
#
|
9
|
-
# tp = TinyPair.new
|
10
|
-
# puts tp.
|
9
|
+
# tp = TinyPair.new(instructions: TinyPair::TEST_MODEL_INSTRUCTIONS)
|
10
|
+
# puts tp.prompt(TinyPair::TEST_TEXT)
|
11
|
+
#
|
12
|
+
# override model instructions if you like:
|
13
|
+
# tp = TinyPair.new(instructions: <your custom instructions>)
|
14
|
+
#
|
11
15
|
class TinyPair
|
12
|
-
|
16
|
+
TEST_MODEL_INSTRUCTIONS = <<~INSTR
|
13
17
|
You will be given some minitest tests in Ruby, and I want you to return the matching Ruby implementation.
|
14
18
|
|
15
|
-
You should use the latest version of Ruby you know of, and try to keep the output code to an 80-column width
|
19
|
+
You should use the latest version of Ruby you know of, and try to keep the output code to an 80-column width.
|
16
20
|
|
17
|
-
|
21
|
+
Only reply with a code snippet; no documentation, and no explanation.
|
18
22
|
INSTR
|
19
23
|
|
20
|
-
|
24
|
+
TEST_TEXT = <<~TEST_TEXT
|
21
25
|
class TestCalc < Minitest::Test
|
22
26
|
def test_add_two_and_two
|
23
27
|
assert_equal 4, Calc.add(2, 2)
|
@@ -37,19 +41,46 @@ class TinyPair
|
|
37
41
|
end
|
38
42
|
TEST_TEXT
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
attr_reader :msgs
|
45
|
+
|
46
|
+
def initialize(api_key: ENV['TINY_PAIR_GEMINI_API_KEY'], model: ENV['TINY_PAIR_GEMINI_MODEL'], instructions: nil)
|
47
|
+
@gemini = Gemini.new(
|
48
|
+
credentials: {
|
49
|
+
service: 'generative-language-api',
|
50
|
+
api_key: api_key,
|
51
|
+
},
|
52
|
+
options: { model: model, server_sent_events: false }
|
45
53
|
)
|
54
|
+
|
55
|
+
@msgs = []
|
56
|
+
|
57
|
+
instructions&.strip!
|
58
|
+
@msgs << {
|
59
|
+
role: 'user',
|
60
|
+
parts: [{ text: instructions.strip }]
|
61
|
+
} if instructions && !instructions.empty?
|
46
62
|
end
|
47
63
|
|
48
|
-
#
|
49
|
-
def
|
50
|
-
@
|
51
|
-
parts
|
52
|
-
|
53
|
-
|
64
|
+
# starts or continues a conversation with the msg
|
65
|
+
def prompt(msg)
|
66
|
+
if @msgs.length == 1
|
67
|
+
@msgs.last[:parts] << { text: msg }
|
68
|
+
else
|
69
|
+
@msgs << { role: 'user', parts: [{ text: msg }] }
|
70
|
+
end
|
71
|
+
|
72
|
+
request_body = { contents: @msgs }
|
73
|
+
response = @gemini.generate_content(request_body)
|
74
|
+
candidate = response['candidates']&.first
|
75
|
+
model_content = candidate&.dig('content')
|
76
|
+
|
77
|
+
if model_content
|
78
|
+
@msgs << model_content
|
79
|
+
model_content.dig('parts', 0, 'text') || ""
|
80
|
+
else
|
81
|
+
error_message = "Failed to get a valid response from the API. Response: #{response.to_json}"
|
82
|
+
@msgs.pop
|
83
|
+
raise error_message
|
84
|
+
end
|
54
85
|
end
|
55
86
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_pair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: gemini-ai
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description: a tiny
|
27
|
+
description: a tiny pair programming gem that uses an LLM
|
28
28
|
email: jefflunt@gmail.com
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -50,8 +50,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
rubygems_version: 3.
|
53
|
+
rubygems_version: 3.5.23
|
54
54
|
signing_key:
|
55
55
|
specification_version: 4
|
56
|
-
summary: a tiny
|
56
|
+
summary: a tiny pair programming gem that uses an LLM
|
57
57
|
test_files: []
|