llm.rb 0.14.0 → 0.14.2

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: 587a0b7425102e44f79107bd5f0471ba2cb8f88d95fe28af5e1d334093a539e3
4
- data.tar.gz: 73242cb4daa8890a1f16d578c0e6ff50d54651162d11132ce06d9fb571fec062
3
+ metadata.gz: 41efcc6a142e5863b3b1d2ab1b1c8a452b5c8e8098bf48918c3bd5b16abfcdd2
4
+ data.tar.gz: d2bfdfd690070d6dbca8411874d2970e470b37ed67139976026120b2806e3421
5
5
  SHA512:
6
- metadata.gz: 1f62948774f2cc389ec8b1d53886785667c95d4bd98d3f648307c07342b004c080feb40ae8baa9bda0cb6cf0d3cbeec33f084e9cd5a0a22622a07519a772c0b4
7
- data.tar.gz: 92ce35a290004371ed6ac8ef11d4a41344d85170f398d69ebf2d5251a1a73fc9db79e3065ab5e8d32945070854362f415276a00ac56a4d4e916cd5752f12b5d4
6
+ metadata.gz: 7a10131e21e424e4620b155ef4e8fd23617aecc5ee9141e6a6f0e09b99b042286992f6b27299502f0d7664a92c62e520bf99a7f8aa0836ba0973292c74ab5d80
7
+ data.tar.gz: 57e5110fc829a790ae064c5a52b2ae856fd5566b5256444148008dd9f3dc170b3cbf57fda0c09f7ecc5630215c0c7e236375d063943d9b791a034359569c7ecb
data/README.md CHANGED
@@ -9,6 +9,29 @@ The library provides a common, uniform interface for all the providers and
9
9
  features it supports, in addition to provider-specific features as well. Keep
10
10
  reading to find out more.
11
11
 
12
+ ## Quick start
13
+
14
+ #### Demo
15
+
16
+ <details>
17
+ <summary>Play</summary>
18
+ <img src="share/llm-shell/examples/demo.gif/">
19
+ </details>
20
+
21
+ #### Guides
22
+
23
+ * [An introduction to RAG](https://0x1eef.github.io/posts/an-introduction-to-rag-with-llm.rb/) &ndash;
24
+ a blog post that implements the RAG pattern
25
+ * [How to estimate the age of a person in a photo](https://0x1eef.github.io/posts/age-estimation-with-llm.rb/) &ndash;
26
+ a blog post that implements an age estimation tool
27
+ * [How to edit an image with Gemini](https://0x1eef.github.io/posts/how-to-edit-images-with-gemini/) &ndash;
28
+ a blog post that implements image editing with Gemini
29
+
30
+ #### Ecosystem
31
+
32
+ * [llm-shell](https://github.com/llmrb/llm-shell) &ndash; is a developer-oriented console for Large Language Model communication
33
+ * [llm-spell](https://github.com/llmrb/llm-spell) &ndash; is a utility that can correct spelling mistakes with a Large Language Model
34
+
12
35
  ## Features
13
36
 
14
37
  #### General
data/lib/llm/function.rb CHANGED
@@ -140,6 +140,18 @@ class LLM::Function
140
140
  {name: @name, description: @description, parameters: @params}.compact
141
141
  when "LLM::Anthropic"
142
142
  {name: @name, description: @description, input_schema: @params}.compact
143
+ else
144
+ format_openai(provider)
145
+ end
146
+ end
147
+
148
+ def format_openai(provider)
149
+ case provider.class.to_s
150
+ when "LLM::OpenAI::Responses"
151
+ {
152
+ type: "function", name: @name, description: @description,
153
+ parameters: @params.to_h.merge(additionalProperties: false), strict: true
154
+ }.compact
143
155
  else
144
156
  {
145
157
  type: "function", name: @name,
data/lib/llm/message.rb CHANGED
@@ -117,6 +117,16 @@ module LLM
117
117
  [*content].grep(LLM::Function::Return).any?
118
118
  end
119
119
 
120
+ ##
121
+ # @note
122
+ # This method returns a response for assistant messages,
123
+ # and it returns nil for non-assistant messages
124
+ # @return [LLM::Response, nil]
125
+ # Returns the response associated with the message, or nil
126
+ def response
127
+ extra[:response]
128
+ end
129
+
120
130
  ##
121
131
  # Returns a string representation of the message
122
132
  # @return [String]
@@ -75,10 +75,16 @@ class LLM::OpenAI
75
75
 
76
76
  private
77
77
 
78
- [:headers, :execute,
79
- :set_body_stream, :format_schema,
80
- :format_tools].each do |m|
78
+ [:headers, :execute, :set_body_stream].each do |m|
81
79
  define_method(m) { |*args, **kwargs, &b| @provider.send(m, *args, **kwargs, &b) }
82
80
  end
81
+
82
+ def format_schema(params)
83
+ return {} unless params && params[:schema]
84
+ schema = params.delete(:schema)
85
+ schema = schema.to_h.merge(additionalProperties: false)
86
+ name = "JSONSchema"
87
+ {text: {format: {type: "json_schema", name:, schema:}}}
88
+ end
83
89
  end
84
90
  end
data/lib/llm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLM
4
- VERSION = "0.14.0"
4
+ VERSION = "0.14.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llm.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antar Azri