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 +4 -4
- data/README.md +23 -0
- data/lib/llm/function.rb +12 -0
- data/lib/llm/message.rb +10 -0
- data/lib/llm/providers/openai/responses.rb +9 -3
- data/lib/llm/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41efcc6a142e5863b3b1d2ab1b1c8a452b5c8e8098bf48918c3bd5b16abfcdd2
|
4
|
+
data.tar.gz: d2bfdfd690070d6dbca8411874d2970e470b37ed67139976026120b2806e3421
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/) –
|
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/) –
|
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/) –
|
28
|
+
a blog post that implements image editing with Gemini
|
29
|
+
|
30
|
+
#### Ecosystem
|
31
|
+
|
32
|
+
* [llm-shell](https://github.com/llmrb/llm-shell) – is a developer-oriented console for Large Language Model communication
|
33
|
+
* [llm-spell](https://github.com/llmrb/llm-spell) – 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