tool_tailor 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abc31d6d69830be0126f8b6f61aee408be9e17bdb91423b68e9166f30efaf21f
4
- data.tar.gz: 7eb42498a63836eeac46c6996d2e32f34303430b58dcdd36cb89d833cbadeaef
3
+ metadata.gz: 33d87f65353ea72f0715a86b7759529f68f6678eb6a24d47fac0547bade1b59e
4
+ data.tar.gz: 874c949f555e93aa445147d89981e1207e11fdc4520977a668e9724354ca7d95
5
5
  SHA512:
6
- metadata.gz: 04d10928c7453fbd20980d3c23a6bbbe8cf000baa25f2ffce903910b21607088762f300fde528ee4c7f0b8673ba58a65224926c261486ff033d87c5d25601468
7
- data.tar.gz: 779238cd2409d9d6c669cab52f0d286fc79cf3c9335082d88bf62d871f23ec6439fe479f465d25fab0bd13d2285e6522ee026ea9e5257b019cda483244c28664
6
+ metadata.gz: 4500dc6778e3bb5373a4630160b22a2ad7f0669ddb097d221eb93b3f1c27a93b48310ef4fcc434ec2c154ea004beb84d157bd1550d4ada0eb1e8fe7b8daa83da
7
+ data.tar.gz: 036f48ffa4b31354b24c85392cf52520215afcb02afac201289e19e650f4491be5fa0122aca606fc6d421d833ee2b8a64533b53a5936ea90608d2197caecd2b2
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+
9
+ gem "super_diff", "~> 0.9.0", :group => :test
data/Gemfile.lock CHANGED
@@ -1,13 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tool_tailor (0.1.2)
4
+ tool_tailor (0.1.3)
5
5
  yard (~> 0.9.36)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ attr_extras (7.1.0)
10
11
  diff-lcs (1.5.1)
12
+ optimist (3.1.0)
13
+ patience_diff (1.2.0)
14
+ optimist (~> 3.0)
11
15
  rake (12.3.3)
12
16
  rspec (3.13.0)
13
17
  rspec-core (~> 3.13.0)
@@ -22,6 +26,10 @@ GEM
22
26
  diff-lcs (>= 1.2.0, < 2.0)
23
27
  rspec-support (~> 3.13.0)
24
28
  rspec-support (3.13.1)
29
+ super_diff (0.9.0)
30
+ attr_extras (>= 6.2.4)
31
+ diff-lcs
32
+ patience_diff
25
33
  yard (0.9.36)
26
34
 
27
35
  PLATFORMS
@@ -30,6 +38,7 @@ PLATFORMS
30
38
  DEPENDENCIES
31
39
  rake (~> 12.0)
32
40
  rspec (~> 3.0)
41
+ super_diff (~> 0.9.0)
33
42
  tool_tailor!
34
43
 
35
44
  BUNDLED WITH
data/README.md CHANGED
@@ -26,12 +26,15 @@ class TestClass
26
26
  #
27
27
  # @param location [String] The city and state, e.g., San Francisco, CA.
28
28
  # @param unit [String] The unit of temperature, either 'celsius' or 'fahrenheit'.
29
- def get_current_weather(location, unit = 'celsius')
29
+ def get_current_weather(location:, unit: 'celsius')
30
30
  # Function implementation goes here
31
31
  end
32
32
  end
33
33
 
34
- # Unbound method
34
+ # Simple
35
+ ToolTailor.convert(TestClass.instance_method(:get_current_weather))
36
+
37
+ # Unbound method with to_json_schema
35
38
  TestClass.instance_method(:get_current_weather).to_json_schema # => {
36
39
  # "type" => "function",
37
40
  # "function" => {
@@ -57,7 +60,7 @@ TestClass.instance_method(:get_current_weather).to_json_schema # => {
57
60
  # }
58
61
  # }
59
62
 
60
- # Bound method
63
+ # Bound method with to_json_schema
61
64
  example_instance = TestClass.new
62
65
  example_instance.method(:get_current_weather).to_json_schema # => {
63
66
  # "type" => "function",
@@ -1,3 +1,3 @@
1
1
  module ToolTailor
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/tool_tailor.rb CHANGED
@@ -10,28 +10,53 @@ module ToolTailor
10
10
  # @param function [Method, UnboundMethod] The function to convert.
11
11
  # @return [String] The JSON schema representation of the function.
12
12
  # @raise [ArgumentError] If the provided object is not a Method or UnboundMethod.
13
+ #
14
+ # @example
15
+ # def example_method(param1, param2)
16
+ # # method implementation
17
+ # end
18
+ #
19
+ # ToolTailor.convert(method(:example_method))
13
20
  def self.convert(function)
14
21
  unless function.is_a?(Method) || function.is_a?(UnboundMethod)
15
22
  raise ArgumentError, "Unsupported object type: #{function.class}"
16
23
  end
17
24
 
25
+ # Ensure only named arguments are allowed
26
+ unless function.parameters.all? { |type, _| type == :keyreq || type == :key }
27
+ raise ArgumentError, "Only named arguments are supported"
28
+ end
29
+
18
30
  file_path, line_number = function.source_location
19
31
  YARD.parse(file_path)
20
32
 
21
33
  method_path = "#{function.owner}##{function.name}"
22
34
  yard_object = YARD::Registry.at(method_path)
23
- raise "Documentation for #{method_path} not found." if yard_object.nil?
24
35
 
25
- function_description = yard_object.docstring
26
-
27
- parameters = yard_object.tags("param").map do |tag|
36
+ # Extract parameters from the function definition
37
+ parameters = function.parameters.map do |_, name|
28
38
  {
29
- name: tag.name,
30
- type: type_mapping(tag.types.first),
31
- description: tag.text
39
+ name: name.to_s,
40
+ type: "string",
41
+ description: ""
32
42
  }
33
43
  end
34
44
 
45
+ function_description = ""
46
+
47
+ if yard_object
48
+ function_description = yard_object.docstring
49
+
50
+ yard_object.tags("param").each do |tag|
51
+ param_name = tag.name.chomp(':')
52
+ param = parameters.find { |p| p[:name] == param_name }
53
+ if param
54
+ param[:type] = type_mapping(tag.types.first)
55
+ param[:description] = tag.text
56
+ end
57
+ end
58
+ end
59
+
35
60
  {
36
61
  type: "function",
37
62
  function: {
@@ -48,7 +73,7 @@ module ToolTailor
48
73
  }
49
74
  ]
50
75
  end.to_h,
51
- required: parameters.map { |param| param[:name].to_s }
76
+ required: function.parameters.select { |type, _| type == :keyreq }.map { |_, name| name.to_s }
52
77
  }
53
78
  }
54
79
  }.to_json
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tool_tailor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kieran Klaassen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard