intelligence 0.5.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +555 -0
  3. data/intelligence.gemspec +1 -1
  4. data/lib/intelligence/adapter/base.rb +23 -3
  5. data/lib/intelligence/adapter/class_methods.rb +15 -0
  6. data/lib/intelligence/adapter/{construction_methods.rb → module_methods.rb} +8 -4
  7. data/lib/intelligence/adapter.rb +2 -2
  8. data/lib/intelligence/adapters/anthropic/adapter.rb +21 -30
  9. data/lib/intelligence/adapters/anthropic/chat_request_methods.rb +189 -0
  10. data/lib/intelligence/adapters/anthropic/{chat_methods.rb → chat_response_methods.rb} +8 -124
  11. data/lib/intelligence/adapters/cerebras.rb +17 -17
  12. data/lib/intelligence/adapters/generic/adapter.rb +1 -12
  13. data/lib/intelligence/adapters/generic/chat_methods.rb +42 -11
  14. data/lib/intelligence/adapters/generic.rb +1 -1
  15. data/lib/intelligence/adapters/google/adapter.rb +33 -35
  16. data/lib/intelligence/adapters/google/chat_request_methods.rb +233 -0
  17. data/lib/intelligence/adapters/google/{chat_methods.rb → chat_response_methods.rb} +52 -162
  18. data/lib/intelligence/adapters/groq.rb +46 -28
  19. data/lib/intelligence/adapters/hyperbolic.rb +13 -13
  20. data/lib/intelligence/adapters/legacy/adapter.rb +0 -2
  21. data/lib/intelligence/adapters/legacy/chat_methods.rb +22 -6
  22. data/lib/intelligence/adapters/mistral.rb +57 -0
  23. data/lib/intelligence/adapters/open_ai/adapter.rb +38 -45
  24. data/lib/intelligence/adapters/open_ai/chat_request_methods.rb +186 -0
  25. data/lib/intelligence/adapters/open_ai/{chat_methods.rb → chat_response_methods.rb} +60 -131
  26. data/lib/intelligence/adapters/open_ai.rb +1 -1
  27. data/lib/intelligence/adapters/open_router.rb +62 -0
  28. data/lib/intelligence/adapters/samba_nova.rb +13 -13
  29. data/lib/intelligence/adapters/together_ai.rb +21 -19
  30. data/lib/intelligence/chat_request.rb +57 -7
  31. data/lib/intelligence/chat_result.rb +4 -0
  32. data/lib/intelligence/chat_result_choice.rb +4 -2
  33. data/lib/intelligence/conversation.rb +38 -9
  34. data/lib/intelligence/message.rb +103 -20
  35. data/lib/intelligence/message_content/base.rb +3 -0
  36. data/lib/intelligence/message_content/binary.rb +6 -0
  37. data/lib/intelligence/message_content/file.rb +35 -0
  38. data/lib/intelligence/message_content/text.rb +5 -0
  39. data/lib/intelligence/message_content/tool_call.rb +12 -1
  40. data/lib/intelligence/message_content/tool_result.rb +15 -3
  41. data/lib/intelligence/message_content.rb +12 -3
  42. data/lib/intelligence/tool.rb +139 -0
  43. data/lib/intelligence/version.rb +1 -1
  44. data/lib/intelligence.rb +6 -4
  45. metadata +18 -9
@@ -0,0 +1,139 @@
1
+ module Intelligence
2
+ ##
3
+ # The +Tool+ class instance encpasulates a definition of a tool that may be executed by a
4
+ # model. The properies of a tool include a unique name, a comprehensive description of what
5
+ # the tool does and a set of properies that describe the arguments the tool accepts, each
6
+ # with its own type and validation rules.
7
+ #
8
+ # A +Tool+ instance does not implement the tool, only the defintion of the tool, which is
9
+ # presented to the model to allow it to make a tool call.
10
+ #
11
+ # == Configuration
12
+ #
13
+ # A tool MUST include the +name+ and +description+ and may include any number of
14
+ # +arguments+ as well as a +required+ attribute with a list of the required arguments.
15
+ # Each argument must include a +name+ and may include +description+, +type+, a list of
16
+ # acceptable values through +enum+ and a +minimum+ and +maximum+ for numerical
17
+ # arguments.
18
+ #
19
+ # === Tool Attributes
20
+ #
21
+ # - +name+: A +String+ representing the unique name of the tool. *required*
22
+ # - +description+: A +String+ describing it's purpose and functionality. *required*
23
+ #
24
+ # === Argument Attributes
25
+ #
26
+ # An argument is defined through the +argument+ block. The block MUST include the +name+,
27
+ # while all other attributes, including the +description+ and +type+ are all optional.
28
+ #
29
+ # - +type+:
30
+ # A +String+ indicating the data type of the property. Accepted values include +string+,
31
+ # +number+, +integer+, +array+, +boolean+, +object+.
32
+ # - +name+: A +String+ representing the name of the property. *required*
33
+ # - +description+: A +String+ that describes the property and its purpose. *required*
34
+ # - +minimum+: An +Integer+ or +Float+ specifying the minimum value for numerical properties.
35
+ # - +maximum+: An +Integer+ or +Float+ specifying the maximum value for numerical properties.
36
+ # - +enum+:
37
+ # An +Array+ of acceptable values for the property. Note that ( as per the JSON schema
38
+ # specification ) an enum could be composed of mixed types but this is discouraged.
39
+ # - +required:
40
+ # A boolean ( +TrueClass+, +FalseClass+ ) that specifying if the argument is required.
41
+ #
42
+ # === Examples
43
+ #
44
+ # weather_tool = Tool.build! do
45
+ # name :get_weather_by_locality
46
+ # description \
47
+ # "The get_weather_by_locality tool will return the current weather in a given locality " \
48
+ # "( city, state or province, and country )."
49
+ # argument name: 'city', type: 'string', required: true do
50
+ # description "The city or town for which the current weather should be returned."
51
+ # end
52
+ # argument name: 'state', type: 'string' do
53
+ # description \
54
+ # "The state or province for which the current weather should be returned. If this is " \
55
+ # "not provided the largest or most prominent city with the given name, in the given " \
56
+ # "country, will be assumed."
57
+ # end
58
+ # argument name: 'country', type: 'string', required: true do
59
+ # description "The city or town for which the current weather should be returned."
60
+ # end
61
+ # end
62
+ #
63
+ # web_browser_tool = Tool.build!
64
+ # name :get_web_page
65
+ # description "The get_web_page tool will return the content of a web page, given a page url."
66
+ # argument name: :url, type: 'string', required: true do
67
+ # description \
68
+ # "The url of the page including the scheme.\n"
69
+ # "Examples:\n"
70
+ # " https://example.com\n"
71
+ # " https://www.iana.org/help/example-domains\n"
72
+ # end
73
+ # argument name: :format do
74
+ # description \
75
+ # "The format of the returned content. By default you will receive 'markdown'. You " \
76
+ # "should specify 'html' only if it is specifically required to fullfill the user " \
77
+ # "request."
78
+ # enum [ 'html', 'markdown' ]
79
+ # end
80
+ # argument name: :content do
81
+ # description \
82
+ # "The content of the page to be returned. By default you will receive only the 'main' " \
83
+ # "content, excluding header, footer, menu, advertising and other miscelanous elements. " \
84
+ # "You should request 'full' only if absolutely neccessry to fullfill the user request. " \
85
+ # enum [ 'main', 'full' ]
86
+ # end
87
+ # argument name: :include_tags do
88
+ # description "If content is set to html some tags will."
89
+ # end
90
+ # end
91
+ #
92
+ class Tool
93
+ include DynamicSchema::Definable
94
+ include DynamicSchema::Buildable
95
+
96
+ ARGUMENT_TYPES = [ 'string', 'number', 'integer', 'array', 'boolean', 'object' ]
97
+
98
+ ARGUMENT_SCHEMA = proc do
99
+ type String, in: ARGUMENT_TYPES
100
+ name String, required: true
101
+ description String, required: true
102
+ required [ TrueClass, FalseClass ]
103
+ # note that an enum does not require a type as it implicitly restricts the argument
104
+ # to specific values
105
+ enum array: true
106
+ # for arguments of type number and integer
107
+ minimum [ Integer, Float ]
108
+ maximum [ Integer, Float ]
109
+ # for arguments of type array
110
+ maximum_items Integer, as: :maxItems
111
+ minimum_items Integer, as: :minItems
112
+ unique_items [ TrueClass, FalseClass ]
113
+ items do
114
+ type in: ARGUMENT_TYPES
115
+ property array: true, as: :properties, &ARGUMENT_SCHEMA
116
+ end
117
+ # for arguments of type object
118
+ property array: true, as: :properties, &ARGUMENT_SCHEMA
119
+ end
120
+
121
+ schema do
122
+ name String, required: true
123
+ description String, required: true
124
+ argument array: true, as: :properties do
125
+ self.instance_eval( &ARGUMENT_SCHEMA )
126
+ end
127
+ end
128
+
129
+ def initialize( attributes = nil )
130
+ @properies = attributes
131
+ end
132
+
133
+ def to_h
134
+ @properies.to_h
135
+ end
136
+
137
+ end
138
+ end
139
+
@@ -1,3 +1,3 @@
1
1
  module Intelligence
2
- VERSION = "0.5.0"
2
+ VERSION = "0.7.1"
3
3
  end
data/lib/intelligence.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'json'
2
+ require 'base64'
2
3
 
3
4
  require 'faraday'
4
- require 'adaptive_configuration'
5
+ require 'dynamic_schema'
5
6
  require 'mime-types'
6
7
 
7
8
  require 'intelligence/version'
@@ -11,14 +12,15 @@ require 'intelligence/adapter_error'
11
12
  require 'intelligence/unsupported_content_error'
12
13
 
13
14
  require 'intelligence/error_result'
15
+ require 'intelligence/chat_error_result'
14
16
 
15
- require 'intelligence/conversation'
16
- require 'intelligence/message'
17
+ require 'intelligence/tool'
17
18
  require 'intelligence/message_content'
19
+ require 'intelligence/message'
20
+ require 'intelligence/conversation'
18
21
  require 'intelligence/adapter'
19
22
  require 'intelligence/chat_request'
20
23
  require 'intelligence/chat_result'
21
24
  require 'intelligence/chat_result_choice'
22
25
  require 'intelligence/chat_metrics'
23
- require 'intelligence/chat_error_result'
24
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intelligence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristoph Cichocki-Romanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-08 00:00:00.000000000 Z
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: adaptiveconfiguration
28
+ name: dynamicschema
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0.beta01
33
+ version: 1.0.0.beta03
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0.beta01
40
+ version: 1.0.0.beta03
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mime-types
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,29 +108,36 @@ extensions: []
108
108
  extra_rdoc_files: []
109
109
  files:
110
110
  - LICENSE
111
+ - README.md
111
112
  - intelligence.gemspec
112
113
  - lib/intelligence.rb
113
114
  - lib/intelligence/adapter.rb
114
115
  - lib/intelligence/adapter/base.rb
115
- - lib/intelligence/adapter/construction_methods.rb
116
+ - lib/intelligence/adapter/class_methods.rb
117
+ - lib/intelligence/adapter/module_methods.rb
116
118
  - lib/intelligence/adapter_error.rb
117
119
  - lib/intelligence/adapters/anthropic.rb
118
120
  - lib/intelligence/adapters/anthropic/adapter.rb
119
- - lib/intelligence/adapters/anthropic/chat_methods.rb
121
+ - lib/intelligence/adapters/anthropic/chat_request_methods.rb
122
+ - lib/intelligence/adapters/anthropic/chat_response_methods.rb
120
123
  - lib/intelligence/adapters/cerebras.rb
121
124
  - lib/intelligence/adapters/generic.rb
122
125
  - lib/intelligence/adapters/generic/adapter.rb
123
126
  - lib/intelligence/adapters/generic/chat_methods.rb
124
127
  - lib/intelligence/adapters/google.rb
125
128
  - lib/intelligence/adapters/google/adapter.rb
126
- - lib/intelligence/adapters/google/chat_methods.rb
129
+ - lib/intelligence/adapters/google/chat_request_methods.rb
130
+ - lib/intelligence/adapters/google/chat_response_methods.rb
127
131
  - lib/intelligence/adapters/groq.rb
128
132
  - lib/intelligence/adapters/hyperbolic.rb
129
133
  - lib/intelligence/adapters/legacy/adapter.rb
130
134
  - lib/intelligence/adapters/legacy/chat_methods.rb
135
+ - lib/intelligence/adapters/mistral.rb
131
136
  - lib/intelligence/adapters/open_ai.rb
132
137
  - lib/intelligence/adapters/open_ai/adapter.rb
133
- - lib/intelligence/adapters/open_ai/chat_methods.rb
138
+ - lib/intelligence/adapters/open_ai/chat_request_methods.rb
139
+ - lib/intelligence/adapters/open_ai/chat_response_methods.rb
140
+ - lib/intelligence/adapters/open_router.rb
134
141
  - lib/intelligence/adapters/samba_nova.rb
135
142
  - lib/intelligence/adapters/together_ai.rb
136
143
  - lib/intelligence/chat_error_result.rb
@@ -146,9 +153,11 @@ files:
146
153
  - lib/intelligence/message_content.rb
147
154
  - lib/intelligence/message_content/base.rb
148
155
  - lib/intelligence/message_content/binary.rb
156
+ - lib/intelligence/message_content/file.rb
149
157
  - lib/intelligence/message_content/text.rb
150
158
  - lib/intelligence/message_content/tool_call.rb
151
159
  - lib/intelligence/message_content/tool_result.rb
160
+ - lib/intelligence/tool.rb
152
161
  - lib/intelligence/unsupported_content_error.rb
153
162
  - lib/intelligence/version.rb
154
163
  homepage: https://github.com/EndlessInternational/intelligence