lex-claude 0.1.1
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 +7 -0
- data/.github/workflows/ci.yml +16 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +50 -0
- data/CHANGELOG.md +11 -0
- data/CLAUDE.md +57 -0
- data/Dockerfile +6 -0
- data/Gemfile +12 -0
- data/LICENSE +21 -0
- data/README.md +96 -0
- data/lex-claude.gemspec +31 -0
- data/lib/legion/extensions/claude/client.rb +31 -0
- data/lib/legion/extensions/claude/helpers/client.rb +29 -0
- data/lib/legion/extensions/claude/runners/batches.rb +48 -0
- data/lib/legion/extensions/claude/runners/messages.rb +49 -0
- data/lib/legion/extensions/claude/runners/models.rb +32 -0
- data/lib/legion/extensions/claude/version.rb +9 -0
- data/lib/legion/extensions/claude.rb +15 -0
- metadata +92 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9e951db1ed95bb767cf7b1e4b8d5131bc0f99facb11671fd60a4076430931664
|
|
4
|
+
data.tar.gz: cd22fd58a0a78106e2db87e11cddad4c11c70eac0c09bcd8c529d09fb34c9f4e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f1f39899fea69d4d1bae1218ee1b1c56faf9d012ebf55c69fddf219c890bd5ce604dedc60e9f89098af5757b0d13941b803875b1bd8248219def76f149a2ea8a
|
|
7
|
+
data.tar.gz: 21744108eec4bbe05653f5d91b08e3a8cf9ecf9c206ef5056dfc5f7b9c3a4c7604e57165b0207728a90a1e6f6666bf2dcec82215a98a719649620e98876388f1
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 40
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*'
|
|
29
|
+
|
|
30
|
+
Metrics/AbcSize:
|
|
31
|
+
Max: 60
|
|
32
|
+
|
|
33
|
+
Metrics/CyclomaticComplexity:
|
|
34
|
+
Max: 15
|
|
35
|
+
|
|
36
|
+
Metrics/PerceivedComplexity:
|
|
37
|
+
Max: 17
|
|
38
|
+
|
|
39
|
+
Style/Documentation:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Style/SymbolArray:
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
45
|
+
Style/FrozenStringLiteralComment:
|
|
46
|
+
Enabled: true
|
|
47
|
+
EnforcedStyle: always
|
|
48
|
+
|
|
49
|
+
Naming/FileName:
|
|
50
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# lex-claude: Claude Anthropic Integration for LegionIO
|
|
2
|
+
|
|
3
|
+
**Repository Level 3 Documentation**
|
|
4
|
+
- **Parent**: `/Users/miverso2/rubymine/legion/extensions-ai/CLAUDE.md`
|
|
5
|
+
- **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Legion Extension that connects LegionIO to the Claude Anthropic API. Provides runners for message creation, token counting, model listing, and asynchronous batch processing.
|
|
10
|
+
|
|
11
|
+
**GitHub**: https://github.com/LegionIO/lex-claude
|
|
12
|
+
**License**: MIT
|
|
13
|
+
**Version**: 0.1.0
|
|
14
|
+
**Specs**: 18 examples
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Legion::Extensions::Claude
|
|
20
|
+
├── Runners/
|
|
21
|
+
│ ├── Messages # create(api_key:, model:, messages:, ...), count_tokens(api_key:, model:, messages:, ...)
|
|
22
|
+
│ ├── Models # list(api_key:, ...), retrieve(api_key:, model_id:, ...)
|
|
23
|
+
│ └── Batches # create_batch, list_batches, retrieve_batch, cancel_batch, batch_results
|
|
24
|
+
├── Helpers/
|
|
25
|
+
│ └── Client # Faraday-based Anthropic API client (module, factory method)
|
|
26
|
+
└── Client # Standalone client class (includes all runners, holds @config)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`Helpers::Client` is a **module** with a `client(api_key:, ...)` factory method. It sets `x-api-key` and `anthropic-version` headers. The `API_VERSION` constant is `'2023-06-01'` and `DEFAULT_HOST` is `'https://api.anthropic.com'`. All runner modules `extend` it.
|
|
30
|
+
|
|
31
|
+
`Client` (class) provides a standalone instantiable wrapper. It `include`s all runner modules and holds a persistent `@config` hash. Its private `client(**override_opts)` merges config with any per-call overrides and delegates to `Helpers::Client.client(...)`.
|
|
32
|
+
|
|
33
|
+
## Key Design Decisions
|
|
34
|
+
|
|
35
|
+
- Runners use `extend Helpers::Client` so `client(...)` is available as a module-function without instantiation.
|
|
36
|
+
- `Client` class uses `include` (not `extend`) so runner methods become instance methods on the client object.
|
|
37
|
+
- The Batches runner uses JSON-only payloads — no multipart dependency.
|
|
38
|
+
- `include Legion::Extensions::Helpers::Lex` is guarded: only included when `lex-lex` is loaded.
|
|
39
|
+
|
|
40
|
+
## Dependencies
|
|
41
|
+
|
|
42
|
+
| Gem | Purpose |
|
|
43
|
+
|-----|---------|
|
|
44
|
+
| `faraday` >= 2.0 | HTTP client for Anthropic API |
|
|
45
|
+
| `multi_json` | JSON parser abstraction |
|
|
46
|
+
|
|
47
|
+
## Testing
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bundle install
|
|
51
|
+
bundle exec rspec # 18 examples
|
|
52
|
+
bundle exec rubocop
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
**Maintained By**: Matthew Iverson (@Esity)
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Esity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# lex-claude
|
|
2
|
+
|
|
3
|
+
Claude Anthropic API integration for [LegionIO](https://github.com/LegionIO/LegionIO). Provides runners for creating messages, listing models, counting tokens, and managing message batches.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install lex-claude
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or add to your Gemfile:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem 'lex-claude'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Functions
|
|
18
|
+
|
|
19
|
+
### Messages
|
|
20
|
+
- `create` - Create a message (chat completion) with Claude
|
|
21
|
+
- `count_tokens` - Count input tokens for a message request
|
|
22
|
+
|
|
23
|
+
### Models
|
|
24
|
+
- `list` - List available Claude models
|
|
25
|
+
- `retrieve` - Get details for a specific model
|
|
26
|
+
|
|
27
|
+
### Batches
|
|
28
|
+
- `create_batch` - Create an asynchronous message batch
|
|
29
|
+
- `list_batches` - List message batches
|
|
30
|
+
- `retrieve_batch` - Get details for a specific batch
|
|
31
|
+
- `cancel_batch` - Cancel an in-progress batch
|
|
32
|
+
- `batch_results` - Retrieve results for a completed batch
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
Set your API key in your LegionIO settings:
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"claude": {
|
|
41
|
+
"api_key": "sk-ant-..."
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Standalone Usage
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
require 'legion/extensions/claude/client'
|
|
50
|
+
|
|
51
|
+
client = Legion::Extensions::Claude::Client.new(api_key: ENV['ANTHROPIC_API_KEY'])
|
|
52
|
+
|
|
53
|
+
# Create a message
|
|
54
|
+
result = client.create(
|
|
55
|
+
model: 'claude-opus-4-6',
|
|
56
|
+
messages: [{ role: 'user', content: 'Hello, Claude!' }],
|
|
57
|
+
max_tokens: 1024
|
|
58
|
+
)
|
|
59
|
+
puts result[:result]['content'].first['text']
|
|
60
|
+
|
|
61
|
+
# List models
|
|
62
|
+
models = client.list
|
|
63
|
+
puts models[:result]['data'].map { |m| m['id'] }
|
|
64
|
+
|
|
65
|
+
# Count tokens
|
|
66
|
+
tokens = client.count_tokens(
|
|
67
|
+
model: 'claude-opus-4-6',
|
|
68
|
+
messages: [{ role: 'user', content: 'How many tokens is this?' }]
|
|
69
|
+
)
|
|
70
|
+
puts tokens[:result]['input_tokens']
|
|
71
|
+
|
|
72
|
+
# Create an async batch
|
|
73
|
+
batch = client.create_batch(
|
|
74
|
+
requests: [
|
|
75
|
+
{ custom_id: 'req-1', params: { model: 'claude-opus-4-6',
|
|
76
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
77
|
+
max_tokens: 100 } }
|
|
78
|
+
]
|
|
79
|
+
)
|
|
80
|
+
puts batch[:result]['id']
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Dependencies
|
|
84
|
+
|
|
85
|
+
- `faraday` >= 2.0 - HTTP client
|
|
86
|
+
- `multi_json` - JSON parser abstraction
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
89
|
+
|
|
90
|
+
- Ruby >= 3.4
|
|
91
|
+
- [LegionIO](https://github.com/LegionIO/LegionIO) framework (optional for standalone client usage)
|
|
92
|
+
- Anthropic API key
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
data/lex-claude.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/claude/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-claude'
|
|
7
|
+
spec.version = Legion::Extensions::Claude::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX Claude'
|
|
12
|
+
spec.description = 'Connects LegionIO to the Claude Anthropic API'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-claude'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.4'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-claude'
|
|
19
|
+
spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-claude'
|
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-claude'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-claude/issues'
|
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
23
|
+
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
end
|
|
27
|
+
spec.require_paths = ['lib']
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
30
|
+
spec.add_dependency 'multi_json'
|
|
31
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/claude/helpers/client'
|
|
4
|
+
require 'legion/extensions/claude/runners/messages'
|
|
5
|
+
require 'legion/extensions/claude/runners/models'
|
|
6
|
+
require 'legion/extensions/claude/runners/batches'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Claude
|
|
11
|
+
class Client
|
|
12
|
+
include Legion::Extensions::Claude::Runners::Messages
|
|
13
|
+
include Legion::Extensions::Claude::Runners::Models
|
|
14
|
+
include Legion::Extensions::Claude::Runners::Batches
|
|
15
|
+
|
|
16
|
+
attr_reader :config
|
|
17
|
+
|
|
18
|
+
def initialize(api_key:, host: Helpers::Client::DEFAULT_HOST, **opts)
|
|
19
|
+
@config = { api_key: api_key, host: host, **opts }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def client(**override_opts)
|
|
25
|
+
merged = config.merge(override_opts)
|
|
26
|
+
Legion::Extensions::Claude::Helpers::Client.client(**merged)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'multi_json'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Claude
|
|
9
|
+
module Helpers
|
|
10
|
+
module Client
|
|
11
|
+
DEFAULT_HOST = 'https://api.anthropic.com'
|
|
12
|
+
API_VERSION = '2023-06-01'
|
|
13
|
+
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def client(api_key:, host: DEFAULT_HOST, **_opts)
|
|
17
|
+
Faraday.new(url: host) do |conn|
|
|
18
|
+
conn.request :json
|
|
19
|
+
conn.response :json, content_type: /\bjson$/
|
|
20
|
+
conn.headers['x-api-key'] = api_key
|
|
21
|
+
conn.headers['anthropic-version'] = API_VERSION
|
|
22
|
+
conn.headers['Content-Type'] = 'application/json'
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/claude/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Claude
|
|
8
|
+
module Runners
|
|
9
|
+
module Batches
|
|
10
|
+
extend Legion::Extensions::Claude::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create_batch(api_key:, requests:, **)
|
|
13
|
+
body = { requests: requests }
|
|
14
|
+
response = client(api_key: api_key, **).post('/v1/messages/batches', body)
|
|
15
|
+
{ result: response.body, status: response.status }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def list_batches(api_key:, limit: 20, before_id: nil, after_id: nil, **)
|
|
19
|
+
params = { limit: limit }
|
|
20
|
+
params[:before_id] = before_id if before_id
|
|
21
|
+
params[:after_id] = after_id if after_id
|
|
22
|
+
|
|
23
|
+
response = client(api_key: api_key, **).get('/v1/messages/batches', params)
|
|
24
|
+
{ result: response.body, status: response.status }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def retrieve_batch(api_key:, batch_id:, **)
|
|
28
|
+
response = client(api_key: api_key, **).get("/v1/messages/batches/#{batch_id}")
|
|
29
|
+
{ result: response.body, status: response.status }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def cancel_batch(api_key:, batch_id:, **)
|
|
33
|
+
response = client(api_key: api_key, **).post("/v1/messages/batches/#{batch_id}/cancel")
|
|
34
|
+
{ result: response.body, status: response.status }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def batch_results(api_key:, batch_id:, **)
|
|
38
|
+
response = client(api_key: api_key, **).get("/v1/messages/batches/#{batch_id}/results")
|
|
39
|
+
{ result: response.body, status: response.status }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
43
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/claude/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Claude
|
|
8
|
+
module Runners
|
|
9
|
+
module Messages
|
|
10
|
+
extend Legion::Extensions::Claude::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create(api_key:, model:, messages:, max_tokens: 1024, system: nil, temperature: nil, # rubocop:disable Metrics/ParameterLists
|
|
13
|
+
top_p: nil, top_k: nil, stop_sequences: nil, metadata: nil, tools: nil,
|
|
14
|
+
tool_choice: nil, stream: false, **)
|
|
15
|
+
body = {
|
|
16
|
+
model: model,
|
|
17
|
+
messages: messages,
|
|
18
|
+
max_tokens: max_tokens,
|
|
19
|
+
stream: stream
|
|
20
|
+
}
|
|
21
|
+
body[:system] = system if system
|
|
22
|
+
body[:temperature] = temperature if temperature
|
|
23
|
+
body[:top_p] = top_p if top_p
|
|
24
|
+
body[:top_k] = top_k if top_k
|
|
25
|
+
body[:stop_sequences] = stop_sequences if stop_sequences
|
|
26
|
+
body[:metadata] = metadata if metadata
|
|
27
|
+
body[:tools] = tools if tools
|
|
28
|
+
body[:tool_choice] = tool_choice if tool_choice
|
|
29
|
+
|
|
30
|
+
response = client(api_key: api_key, **).post('/v1/messages', body)
|
|
31
|
+
{ result: response.body, status: response.status }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def count_tokens(api_key:, model:, messages:, system: nil, tools: nil, **) # rubocop:disable Metrics/ParameterLists
|
|
35
|
+
body = { model: model, messages: messages }
|
|
36
|
+
body[:system] = system if system
|
|
37
|
+
body[:tools] = tools if tools
|
|
38
|
+
|
|
39
|
+
response = client(api_key: api_key, **).post('/v1/messages/count_tokens', body)
|
|
40
|
+
{ result: response.body, status: response.status }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
44
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/claude/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Claude
|
|
8
|
+
module Runners
|
|
9
|
+
module Models
|
|
10
|
+
extend Legion::Extensions::Claude::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list(api_key:, limit: 20, before_id: nil, after_id: nil, **)
|
|
13
|
+
params = { limit: limit }
|
|
14
|
+
params[:before_id] = before_id if before_id
|
|
15
|
+
params[:after_id] = after_id if after_id
|
|
16
|
+
|
|
17
|
+
response = client(api_key: api_key, **).get('/v1/models', params)
|
|
18
|
+
{ result: response.body, status: response.status }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def retrieve(api_key:, model_id:, **)
|
|
22
|
+
response = client(api_key: api_key, **).get("/v1/models/#{model_id}")
|
|
23
|
+
{ result: response.body, status: response.status }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
27
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/claude/version'
|
|
4
|
+
require 'legion/extensions/claude/helpers/client'
|
|
5
|
+
require 'legion/extensions/claude/runners/messages'
|
|
6
|
+
require 'legion/extensions/claude/runners/models'
|
|
7
|
+
require 'legion/extensions/claude/runners/batches'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Claude
|
|
12
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-claude
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: multi_json
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
description: Connects LegionIO to the Claude Anthropic API
|
|
41
|
+
email:
|
|
42
|
+
- matthewdiverson@gmail.com
|
|
43
|
+
executables: []
|
|
44
|
+
extensions: []
|
|
45
|
+
extra_rdoc_files: []
|
|
46
|
+
files:
|
|
47
|
+
- ".github/workflows/ci.yml"
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- ".rspec"
|
|
50
|
+
- ".rubocop.yml"
|
|
51
|
+
- CHANGELOG.md
|
|
52
|
+
- CLAUDE.md
|
|
53
|
+
- Dockerfile
|
|
54
|
+
- Gemfile
|
|
55
|
+
- LICENSE
|
|
56
|
+
- README.md
|
|
57
|
+
- lex-claude.gemspec
|
|
58
|
+
- lib/legion/extensions/claude.rb
|
|
59
|
+
- lib/legion/extensions/claude/client.rb
|
|
60
|
+
- lib/legion/extensions/claude/helpers/client.rb
|
|
61
|
+
- lib/legion/extensions/claude/runners/batches.rb
|
|
62
|
+
- lib/legion/extensions/claude/runners/messages.rb
|
|
63
|
+
- lib/legion/extensions/claude/runners/models.rb
|
|
64
|
+
- lib/legion/extensions/claude/version.rb
|
|
65
|
+
homepage: https://github.com/LegionIO/lex-claude
|
|
66
|
+
licenses:
|
|
67
|
+
- MIT
|
|
68
|
+
metadata:
|
|
69
|
+
homepage_uri: https://github.com/LegionIO/lex-claude
|
|
70
|
+
source_code_uri: https://github.com/LegionIO/lex-claude
|
|
71
|
+
documentation_uri: https://github.com/LegionIO/lex-claude
|
|
72
|
+
changelog_uri: https://github.com/LegionIO/lex-claude
|
|
73
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-claude/issues
|
|
74
|
+
rubygems_mfa_required: 'true'
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.4'
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
requirements: []
|
|
89
|
+
rubygems_version: 3.6.9
|
|
90
|
+
specification_version: 4
|
|
91
|
+
summary: LEX Claude
|
|
92
|
+
test_files: []
|