simple-openai-client 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple-openai-client.rb +7 -2
- data/simple-openai-client.gemspec +2 -2
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89976a4d61c06b3abb6f14fd7d67a69fd72ffeb236d588c236af5a6a335e01a4
|
4
|
+
data.tar.gz: 0eb2a967251c702cab294b9ffa221bd4dce2314b4241ec780b37eff9a1096d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a5c07a411f8cfba69407516d4c7944fa0d325ed7445463aed26c7a39770aab1c4eea970d494db36d6f821c3a0ffd3a6b64f5efc0f9903f5cc82bcc8208f3ff
|
7
|
+
data.tar.gz: 6bbb06f477bce4be636074c32e958c0bee87b2b988d24f7ffed5240ca20f9b5badeada0fbf812e0916895850eab4dfa9adefa7eee0990b732385595b9f09305d
|
data/lib/simple-openai-client.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
require 'net/http'
|
6
6
|
require 'uri'
|
7
7
|
require 'json'
|
8
|
+
require 'colorize'
|
8
9
|
|
9
10
|
class OpenAIClient
|
10
11
|
attr_accessor :api_key, :model, :messages, :functions, :callbacks, :version
|
@@ -52,7 +53,7 @@ class OpenAIClient
|
|
52
53
|
|
53
54
|
# Ask something to GPT.
|
54
55
|
# Return the response.
|
55
|
-
def ask(s, context: [])
|
56
|
+
def ask(s, context: [], function_to_call: nil)
|
56
57
|
# Use v1 chat completions endpoint (with functions support)
|
57
58
|
uri = URI("https://api.openai.com/v1/chat/completions")
|
58
59
|
|
@@ -69,7 +70,11 @@ class OpenAIClient
|
|
69
70
|
# If you want the model to call a function explicitly, you can add: "function_call" => "auto"
|
70
71
|
}
|
71
72
|
|
72
|
-
|
73
|
+
if self.functions.size > 0
|
74
|
+
request_body["functions"] = self.functions
|
75
|
+
# Important: enable function-calling
|
76
|
+
request_body["function_call"] = {"name" => function_to_call} if function_to_call
|
77
|
+
end
|
73
78
|
|
74
79
|
http = Net::HTTP.new(uri.host, uri.port)
|
75
80
|
http.use_ssl = true
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'simple-openai-client'
|
3
|
-
s.version = '1.0.
|
4
|
-
s.date = '2025-01-
|
3
|
+
s.version = '1.0.5'
|
4
|
+
s.date = '2025-01-18'
|
5
5
|
s.summary = "Very simple Ruby library for operating OpenAI API for building Agents."
|
6
6
|
s.description = "Very simple Ruby library for operating OpenAI API for building Agents."
|
7
7
|
s.authors = ["Leandro Daniel Sardi"]
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-openai-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-18 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: uri
|
@@ -142,7 +141,6 @@ homepage: https://github.com/leandrosardi/simple-openai-client
|
|
142
141
|
licenses:
|
143
142
|
- MIT
|
144
143
|
metadata: {}
|
145
|
-
post_install_message:
|
146
144
|
rdoc_options: []
|
147
145
|
require_paths:
|
148
146
|
- lib
|
@@ -157,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
155
|
- !ruby/object:Gem::Version
|
158
156
|
version: '0'
|
159
157
|
requirements: []
|
160
|
-
rubygems_version: 3.3
|
161
|
-
signing_key:
|
158
|
+
rubygems_version: 3.6.3
|
162
159
|
specification_version: 4
|
163
160
|
summary: Very simple Ruby library for operating OpenAI API for building Agents.
|
164
161
|
test_files: []
|