elelem-openai 0.3.0 → 0.4.0
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/.agents/backlog/001-readme-and-gem-metadata.md +86 -0
- data/.github/workflows/release.yml +2 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +20 -0
- data/lib/elelem/openai/provider.rb +16 -42
- data/lib/elelem/openai/version.rb +1 -1
- data/lib/elelem/openai.rb +1 -1
- data/spec/elelem/openai/provider_spec.rb +50 -2
- data/spec/elelem/openai/round_trip_spec.rb +3 -7
- metadata +9 -23
- data/spec/elelem/openai/http_adapter_spec.rb +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c4b0c206227c277a16be4e7844d33904b52cd8a757d628b0ce459d1f8126174
|
|
4
|
+
data.tar.gz: ca4edfcaa0e9e0e053b55a3bd6dffe4f5a095bb2c2107d301e03abc42b24571e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abc80c1b189c8fa86a4822c9f8c3f29d939fd72811fd4be07e9079414b8960ad226051d3ea7eb563bc807cac295f6afbaea76c3a05dbe67483eab1ae1ee563fc
|
|
7
|
+
data.tar.gz: 3acd01b5151829c3e240da5b8d339013aea9c7a6821df0ea3580b87bd98b7038986c258cea0316c37c012620aa7738ce97a62770da18bfb0695fe67426884a2b
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
As a `person who wants to use OpenAI or a compatible server from
|
|
2
|
+
elelem`, I `want a README and clear RubyGems links for elelem-openai`,
|
|
3
|
+
so that `I can point it at my server without reading the code and find
|
|
4
|
+
the docs and backlog from the gem page`.
|
|
5
|
+
|
|
6
|
+
# SYNOPSIS
|
|
7
|
+
|
|
8
|
+
Add a README, and point the gem's RubyGems links at elelem.sh and this
|
|
9
|
+
repository's backlog.
|
|
10
|
+
|
|
11
|
+
# DESCRIPTION
|
|
12
|
+
|
|
13
|
+
Two small changes that both shape what a newcomer sees first.
|
|
14
|
+
|
|
15
|
+
## README
|
|
16
|
+
|
|
17
|
+
The repository has no README. It should cover:
|
|
18
|
+
|
|
19
|
+
* Install, and selecting the provider: `-p openai` and `--model NAME`.
|
|
20
|
+
* `OPENAI_API_KEY`, `OPENAI_MODEL` (default `gpt-4o`) and
|
|
21
|
+
`OPENAI_BASE_URL` (default `https://api.openai.com/v1`).
|
|
22
|
+
* Compatible servers: with `OPENAI_BASE_URL` set, no key is required,
|
|
23
|
+
so a local Chat Completions server works; an example.
|
|
24
|
+
* That a set but empty variable counts as unset.
|
|
25
|
+
* A link to https://elelem.sh/plugins/openai/ for the full guide.
|
|
26
|
+
|
|
27
|
+
The elelem.sh plugin page can be the source for the text. Show commands
|
|
28
|
+
without a leading `$`, so they can be pasted.
|
|
29
|
+
|
|
30
|
+
## Gem metadata
|
|
31
|
+
|
|
32
|
+
RubyGems shows `homepage_uri` and the other `metadata` links on every
|
|
33
|
+
gem page. Today `elelem-openai.gemspec` sets `spec.homepage`
|
|
34
|
+
to the site root (https://elelem.sh) and sets only `homepage_uri`,
|
|
35
|
+
`source_code_uri`, `allowed_push_host` and
|
|
36
|
+
`rubygems_mfa_required`.
|
|
37
|
+
There is no documentation, bug tracker or changelog link.
|
|
38
|
+
|
|
39
|
+
Proposed change:
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
spec.homepage = "https://elelem.sh/plugins/openai/"
|
|
43
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
44
|
+
spec.metadata["source_code_uri"] = "https://github.com/elelem-sh/openai"
|
|
45
|
+
spec.metadata["documentation_uri"] = spec.homepage
|
|
46
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/elelem-sh/openai/tree/main/.agents/backlog"
|
|
47
|
+
spec.metadata["changelog_uri"] = "https://github.com/elelem-sh/openai/blob/main/CHANGELOG.md"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The original proposal pointed `bug_tracker_uri` at GitHub Issues on
|
|
51
|
+
elelem-sh/elelem.sh, filtered by label. That no longer fits: the
|
|
52
|
+
project is moving its backlog out of GitHub Issues and into
|
|
53
|
+
`.agents/backlog` story files in each repository, so the bug tracker
|
|
54
|
+
link points at this repository's backlog directory instead.
|
|
55
|
+
|
|
56
|
+
/man/openai/ redirects to /plugins/openai/ on elelem.sh, so a
|
|
57
|
+
separate documentation_uri adds nothing. Point both at the plugin page.
|
|
58
|
+
CHANGELOG.md exists on main, so the changelog link works today.
|
|
59
|
+
|
|
60
|
+
Keep `allowed_push_host` and `rubygems_mfa_required` as they are.
|
|
61
|
+
RubyGems only shows the new links after the next release.
|
|
62
|
+
|
|
63
|
+
# SEE ALSO
|
|
64
|
+
|
|
65
|
+
* [ ] lib/elelem/openai.rb:11-27 - provider block and environment
|
|
66
|
+
* [ ] exe/elelem-openai
|
|
67
|
+
* [ ] elelem-openai.gemspec:13 - spec.homepage and metadata
|
|
68
|
+
* [ ] https://elelem.sh/plugins/openai/ - source for README text
|
|
69
|
+
* [ ] Formerly elelem-sh/elelem.sh#23
|
|
70
|
+
* [ ] Formerly elelem-sh/elelem.sh#41
|
|
71
|
+
|
|
72
|
+
# Tasks
|
|
73
|
+
|
|
74
|
+
* [ ] TBD (filled in design mode)
|
|
75
|
+
|
|
76
|
+
# Acceptance Criteria
|
|
77
|
+
|
|
78
|
+
* [ ] README.md exists and covers the points above
|
|
79
|
+
* [ ] Defaults in the README match the code
|
|
80
|
+
* [ ] Commands in the README have no leading `$`
|
|
81
|
+
* [ ] `spec.homepage` and `homepage_uri` are https://elelem.sh/plugins/openai/
|
|
82
|
+
* [ ] `bug_tracker_uri` points at this repository's `.agents/backlog`,
|
|
83
|
+
not at GitHub Issues
|
|
84
|
+
* [ ] `changelog_uri` and `source_code_uri` point at this repository
|
|
85
|
+
* [ ] `gem build` succeeds and `gem spec` on the built gem shows every
|
|
86
|
+
link
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.0](https://github.com/elelem-sh/openai/compare/v0.3.1...v0.4.0) (2026-11-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* stream over a kept-alive connection that retries busy servers ([6463020](https://github.com/elelem-sh/openai/commit/6463020dc62edab070b1aa753b7ff278f3504162))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* say when a content filter stops a reply ([c02d2ec](https://github.com/elelem-sh/openai/commit/c02d2ec889c6be7f0a5cd3953df3c84f9169cd0d))
|
|
14
|
+
* say when a reply hits the output limit ([d8005bd](https://github.com/elelem-sh/openai/commit/d8005bdba722a44ce6492fb227d3cd087a807dda))
|
|
15
|
+
|
|
16
|
+
## [0.3.1](https://github.com/elelem-sh/openai/compare/v0.3.0...v0.3.1) (2026-11-18)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* **deps:** accept the json that Ruby 4.0 ships ([3c856d4](https://github.com/elelem-sh/openai/commit/3c856d43e90bdcde09134d512bf60d4ba9db907e))
|
|
22
|
+
|
|
3
23
|
## [0.3.0](https://github.com/elelem-sh/openai/compare/v0.2.0...v0.3.0) (2026-11-16)
|
|
4
24
|
|
|
5
25
|
|
|
@@ -47,6 +47,7 @@ module Elelem
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def handle_event(event, tool_calls, &block)
|
|
50
|
+
stopped(event.dig("choices", 0, "finish_reason"))
|
|
50
51
|
delta = event.dig("choices", 0, "delta") || {}
|
|
51
52
|
|
|
52
53
|
block.call(type: "saying", text: delta["content"]) if delta["content"]
|
|
@@ -64,31 +65,27 @@ module Elelem
|
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
# Raises before a cut-off tool call is parsed.
|
|
69
|
+
def stopped(reason)
|
|
70
|
+
case reason
|
|
71
|
+
when "length" then raise "the reply hit the model's output limit before it ended"
|
|
72
|
+
when "content_filter" then raise "the reply was stopped by a content filter"
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
75
|
|
|
75
|
-
def
|
|
76
|
-
|
|
76
|
+
def stream(body)
|
|
77
|
+
http.post(@uri, body:, headers:) do |response|
|
|
78
|
+
Elelem::HTTP.events(response) { |data| yield JSON.parse(data) }
|
|
79
|
+
end
|
|
77
80
|
end
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
buffer << chunk
|
|
84
|
-
|
|
85
|
-
while (index = buffer.index("\n"))
|
|
86
|
-
line = buffer.slice!(0, index + 1).strip
|
|
87
|
-
next unless line.start_with?("data: ") && line != "data: [DONE]"
|
|
82
|
+
# A local server may need no key.
|
|
83
|
+
def headers
|
|
84
|
+
@api_key.to_s.empty? ? {} : { "authorization" => "Bearer #{@api_key}" }
|
|
85
|
+
end
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
end
|
|
87
|
+
def http
|
|
88
|
+
@http ||= Elelem::HTTP.new(read_timeout: @read_timeout, open_timeout: @open_timeout)
|
|
92
89
|
end
|
|
93
90
|
|
|
94
91
|
def finalize_tool_calls(tool_calls, &block)
|
|
@@ -100,29 +97,6 @@ module Elelem
|
|
|
100
97
|
}.tap { |result| block.call(result.merge(type: "doing")) }
|
|
101
98
|
end
|
|
102
99
|
end
|
|
103
|
-
|
|
104
|
-
class HttpAdapter
|
|
105
|
-
def initialize(read_timeout:, open_timeout:)
|
|
106
|
-
@read_timeout = read_timeout
|
|
107
|
-
@open_timeout = open_timeout
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def post(uri, api_key:, body:, &)
|
|
111
|
-
request = Net::HTTP::Post.new(uri)
|
|
112
|
-
request["content-type"] = "application/json"
|
|
113
|
-
request["authorization"] = "Bearer #{api_key}" unless api_key.to_s.empty?
|
|
114
|
-
request.body = JSON.generate(body)
|
|
115
|
-
|
|
116
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
117
|
-
http.use_ssl = uri.scheme == "https"
|
|
118
|
-
http.read_timeout = @read_timeout
|
|
119
|
-
http.open_timeout = @open_timeout
|
|
120
|
-
|
|
121
|
-
http.start do |conn|
|
|
122
|
-
conn.request(request, &)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
100
|
end
|
|
127
101
|
end
|
|
128
102
|
end
|
data/lib/elelem/openai.rb
CHANGED
|
@@ -19,14 +19,15 @@ RSpec.describe Elelem::OpenAI::Provider do
|
|
|
19
19
|
|
|
20
20
|
let(:http) do
|
|
21
21
|
Class.new do
|
|
22
|
-
attr_reader :body
|
|
22
|
+
attr_reader :body, :headers
|
|
23
23
|
|
|
24
24
|
def initialize(response)
|
|
25
25
|
@response = response
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def post(_uri, body:,
|
|
28
|
+
def post(_uri, body:, headers: {})
|
|
29
29
|
@body = body
|
|
30
|
+
@headers = headers
|
|
30
31
|
yield @response
|
|
31
32
|
end
|
|
32
33
|
end.new(response)
|
|
@@ -43,6 +44,53 @@ RSpec.describe Elelem::OpenAI::Provider do
|
|
|
43
44
|
expect(body).to eq(model: "gpt-4o", messages:, stream: true)
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
it "sends the key as a bearer token" do
|
|
48
|
+
provider.fetch(messages, [])
|
|
49
|
+
|
|
50
|
+
expect(http.headers).to eq("authorization" => "Bearer sk-test")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "without a key, as for a local server" do
|
|
54
|
+
let(:params) { { api_key: "" } }
|
|
55
|
+
|
|
56
|
+
it "sends no authorization header" do
|
|
57
|
+
provider.fetch(messages, [])
|
|
58
|
+
|
|
59
|
+
expect(http.headers).to eq({})
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "reads events split by CRLF" do
|
|
64
|
+
allow(response).to receive(:read_body)
|
|
65
|
+
.and_yield(%(data: {"choices":[{"delta":{"content":"hi"}}]}\r\n\r\ndata: [DONE]\r\n))
|
|
66
|
+
seen = []
|
|
67
|
+
|
|
68
|
+
provider.fetch(messages, []) { |event| seen << event }
|
|
69
|
+
|
|
70
|
+
expect(seen).to eq([{ type: "saying", text: "hi" }])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
context "with a tool call cut off at the output limit" do
|
|
74
|
+
let(:events) do
|
|
75
|
+
[{ "choices" => [{ "delta" => { "tool_calls" => [{ "index" => 0, "id" => "1",
|
|
76
|
+
"function" => { "name" => "write",
|
|
77
|
+
"arguments" => '{"path":"a' } }] } }] },
|
|
78
|
+
{ "choices" => [{ "delta" => {}, "finish_reason" => "length" }] }]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "says so instead of failing to parse half the arguments" do
|
|
82
|
+
expect { provider.fetch(messages, []) {} }.to raise_error(/output limit before it ended/)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "with a filtered reply" do
|
|
87
|
+
let(:events) { [{ "choices" => [{ "delta" => {}, "finish_reason" => "content_filter" }] }] }
|
|
88
|
+
|
|
89
|
+
it "raises" do
|
|
90
|
+
expect { provider.fetch(messages, []) {} }.to raise_error(/stopped by a content filter/)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
46
94
|
it "sends tools with tool_choice auto" do
|
|
47
95
|
tools = [{ type: "function", function: { name: "read" } }]
|
|
48
96
|
provider.fetch(messages, tools)
|
|
@@ -15,7 +15,9 @@ RSpec.describe "a tool call round trip through Elelem::Agent" do
|
|
|
15
15
|
@requests << body
|
|
16
16
|
problem = invalid(body[:messages])
|
|
17
17
|
events = @requests.size == 1 ? tool_call : reply
|
|
18
|
-
|
|
18
|
+
raise "HTTP 400: invalid tool call: #{problem}" if problem
|
|
19
|
+
|
|
20
|
+
yield ok(events)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
private
|
|
@@ -39,12 +41,6 @@ RSpec.describe "a tool call round trip through Elelem::Agent" do
|
|
|
39
41
|
res.define_singleton_method(:read_body) { |&block| block.call(data) }
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
|
-
|
|
43
|
-
def bad_request(problem)
|
|
44
|
-
Net::HTTPBadRequest.new("1.1", "400", "Bad Request").tap do |res|
|
|
45
|
-
res.define_singleton_method(:body) { "invalid tool call: #{problem}" }
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
44
|
end.new
|
|
49
45
|
end
|
|
50
46
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elelem-openai
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mo khan
|
|
@@ -15,7 +15,7 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0.
|
|
18
|
+
version: '0.16'
|
|
19
19
|
- - "<"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: '1'
|
|
@@ -25,7 +25,7 @@ dependencies:
|
|
|
25
25
|
requirements:
|
|
26
26
|
- - ">="
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: '0.
|
|
28
|
+
version: '0.16'
|
|
29
29
|
- - "<"
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
31
|
version: '1'
|
|
@@ -33,30 +33,16 @@ dependencies:
|
|
|
33
33
|
name: json
|
|
34
34
|
requirement: !ruby/object:Gem::Requirement
|
|
35
35
|
requirements:
|
|
36
|
-
- - "
|
|
37
|
-
- !ruby/object:Gem::Version
|
|
38
|
-
version: '3.0'
|
|
39
|
-
type: :runtime
|
|
40
|
-
prerelease: false
|
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
-
requirements:
|
|
43
|
-
- - "~>"
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: '3.0'
|
|
46
|
-
- !ruby/object:Gem::Dependency
|
|
47
|
-
name: net-http
|
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
requirements:
|
|
50
|
-
- - "~>"
|
|
36
|
+
- - ">="
|
|
51
37
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: '
|
|
38
|
+
version: '2.18'
|
|
53
39
|
type: :runtime
|
|
54
40
|
prerelease: false
|
|
55
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
56
42
|
requirements:
|
|
57
|
-
- - "
|
|
43
|
+
- - ">="
|
|
58
44
|
- !ruby/object:Gem::Version
|
|
59
|
-
version: '
|
|
45
|
+
version: '2.18'
|
|
60
46
|
- !ruby/object:Gem::Dependency
|
|
61
47
|
name: uri
|
|
62
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -79,6 +65,7 @@ executables:
|
|
|
79
65
|
extensions: []
|
|
80
66
|
extra_rdoc_files: []
|
|
81
67
|
files:
|
|
68
|
+
- ".agents/backlog/001-readme-and-gem-metadata.md"
|
|
82
69
|
- ".github/workflows/release.yml"
|
|
83
70
|
- ".release-please-manifest.json"
|
|
84
71
|
- ".rspec"
|
|
@@ -91,7 +78,6 @@ files:
|
|
|
91
78
|
- lib/elelem/openai/provider.rb
|
|
92
79
|
- lib/elelem/openai/version.rb
|
|
93
80
|
- release-please-config.json
|
|
94
|
-
- spec/elelem/openai/http_adapter_spec.rb
|
|
95
81
|
- spec/elelem/openai/provider_spec.rb
|
|
96
82
|
- spec/elelem/openai/registration_spec.rb
|
|
97
83
|
- spec/elelem/openai/round_trip_spec.rb
|
|
@@ -118,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
104
|
- !ruby/object:Gem::Version
|
|
119
105
|
version: '0'
|
|
120
106
|
requirements: []
|
|
121
|
-
rubygems_version: 4.0.
|
|
107
|
+
rubygems_version: 4.0.20
|
|
122
108
|
specification_version: 4
|
|
123
109
|
summary: An OpenAI provider plugin for elelem.
|
|
124
110
|
test_files: []
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe Elelem::OpenAI::Provider::HttpAdapter do
|
|
4
|
-
def sent_headers(api_key)
|
|
5
|
-
seen = nil
|
|
6
|
-
conn = double("conn").tap { |c| allow(c).to receive(:request) { |req| seen = req } }
|
|
7
|
-
http = double("http", "use_ssl=": nil, "read_timeout=": nil, "open_timeout=": nil).tap do |h|
|
|
8
|
-
allow(h).to receive(:start).and_yield(conn)
|
|
9
|
-
end
|
|
10
|
-
allow(Net::HTTP).to receive(:new).and_return(http)
|
|
11
|
-
adapter = described_class.new(read_timeout: 1, open_timeout: 1)
|
|
12
|
-
adapter.post(URI("http://h/v1/chat/completions"), api_key: api_key, body: {})
|
|
13
|
-
seen
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "sends the key as a bearer token" do
|
|
17
|
-
expect(sent_headers("sk-test")["authorization"]).to eq("Bearer sk-test")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "sends no authorization header without a key" do
|
|
21
|
-
expect(sent_headers("")["authorization"]).to be_nil
|
|
22
|
-
end
|
|
23
|
-
end
|