Class: TinyPair
- Inherits:
-
Object
- Object
- TinyPair
- Defined in:
- lib/tiny_pair.rb
Overview
if you can write the specification for some code, shouldn’t the computer be able to write the implementation?
get your Google Gemini API key ready, and then run the following code to see what happens:
tp = TinyPair.new
puts tp.implement(tests: TinyPair::TESTS)
Constant Summary collapse
- MODEL_INSTRUCTIONS =
"You will be given some minitest tests in Ruby, and I want you to return the matching Ruby implementation.\n\nYou should use the latest version of Ruby you know of, and try to keep the output code to an 80-column width\n\nDo not explain the code or any surrounding documentation: only provide the implementation code in plaintext and nothing else.\n"- TESTS =
"class TestCalc < Minitest::Test\n def test_add_two_and_two\n assert_equal 4, Calc.add(2, 2)\n end\n\n def test_add_two_and_seven\n assert_equal 9, Calc.add(2, 7)\n end\n\n def test_multi_three_and_five\n assert_equal 15, Calc.multi(3, 5)\n end\n\n def test_multi_six_and_nineteen\n assert_equal 114, Calc.multi(6, 19)\n end\nend\n"
Instance Method Summary collapse
-
#implement(tests:) ⇒ Object
tests: the raw text of a series of minitest tests.
-
#initialize(instructions: MODEL_INSTRUCTIONS) ⇒ TinyPair
constructor
A new instance of TinyPair.
Constructor Details
#initialize(instructions: MODEL_INSTRUCTIONS) ⇒ TinyPair
Returns a new instance of TinyPair.
40 41 42 43 44 45 46 |
# File 'lib/tiny_pair.rb', line 40 def initialize(instructions: MODEL_INSTRUCTIONS) @client = TinyGemini.new( model: 'gemini-1.5-flash', system_instruction: MODEL_INSTRUCTIONS, api_key: ENV['GEMINI_KEY'] ) end |
Instance Method Details
#implement(tests:) ⇒ Object
tests: the raw text of a series of minitest tests
49 50 51 52 53 54 |
# File 'lib/tiny_pair.rb', line 49 def implement(tests:) @client.prompt({ parts: { text: tests }, role: 'user' }) end |