lex-xai 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 +51 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +7 -0
- data/README.md +53 -0
- data/lex-xai.gemspec +31 -0
- data/lib/legion/extensions/xai/client.rb +31 -0
- data/lib/legion/extensions/xai/helpers/client.rb +27 -0
- data/lib/legion/extensions/xai/runners/chat.rb +28 -0
- data/lib/legion/extensions/xai/runners/embeddings.rb +25 -0
- data/lib/legion/extensions/xai/runners/models.rb +28 -0
- data/lib/legion/extensions/xai/version.rb +9 -0
- data/lib/legion/extensions/xai.rb +15 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6fca806edc2e12276707307434a20b580f0a491888e12f312f1c3c0fa989bccd
|
|
4
|
+
data.tar.gz: d28561f9012a49d21e71d45a7fd2a24ee9fc7e86a5050f5f082b6f8a23f222e9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 559921a947e5c04e5c986bb2a044d507962519efd0e1f0f6ebba0c876c5ef268cd5280cc16b274baf0a7cc27781411c5daecfa3e630fa30fd9c71a3fc36a8586
|
|
7
|
+
data.tar.gz: 8449fc7f371fc1dad7f8c7d0d43ce878a117a25591523c34f1347c41a1ce7e9d4d4f4c62b66d640c4075696ff4944d787612b910e5ba4761e765cb8222b38877
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [origin]
|
|
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/origin'
|
|
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,51 @@
|
|
|
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
|
+
- '*.gemspec'
|
|
30
|
+
|
|
31
|
+
Metrics/AbcSize:
|
|
32
|
+
Max: 60
|
|
33
|
+
|
|
34
|
+
Metrics/CyclomaticComplexity:
|
|
35
|
+
Max: 15
|
|
36
|
+
|
|
37
|
+
Metrics/PerceivedComplexity:
|
|
38
|
+
Max: 17
|
|
39
|
+
|
|
40
|
+
Style/Documentation:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Style/SymbolArray:
|
|
44
|
+
Enabled: true
|
|
45
|
+
|
|
46
|
+
Style/FrozenStringLiteralComment:
|
|
47
|
+
Enabled: true
|
|
48
|
+
EnforcedStyle: always
|
|
49
|
+
|
|
50
|
+
Naming/FileName:
|
|
51
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-03-21
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- `Runners::Chat` with `create` method for chat completions via xAI Grok API
|
|
8
|
+
- `Runners::Models` with `list` and `retrieve` methods
|
|
9
|
+
- `Runners::Embeddings` with `create` method
|
|
10
|
+
- `Helpers::Client` Faraday connection builder with Bearer token auth
|
|
11
|
+
- Standalone `Client` class including all runner modules
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# lex-xai
|
|
2
|
+
|
|
3
|
+
LegionIO extension for the [xAI Grok API](https://docs.x.ai).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'lex-xai'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Standalone Client
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'legion/extensions/xai/client'
|
|
19
|
+
|
|
20
|
+
client = Legion::Extensions::Xai::Client.new(api_key: 'your-xai-api-key')
|
|
21
|
+
|
|
22
|
+
# Chat completions
|
|
23
|
+
result = client.create(messages: [{ role: 'user', content: 'Hello!' }])
|
|
24
|
+
|
|
25
|
+
# List models
|
|
26
|
+
result = client.list
|
|
27
|
+
|
|
28
|
+
# Retrieve a model
|
|
29
|
+
result = client.retrieve(model: 'grok-3')
|
|
30
|
+
|
|
31
|
+
# Create embeddings
|
|
32
|
+
result = client.create(input: 'Hello world')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Runner Modules
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
include Legion::Extensions::Xai::Runners::Chat
|
|
39
|
+
|
|
40
|
+
result = create(api_key: 'your-key', messages: [{ role: 'user', content: 'Hello!' }])
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Coverage
|
|
44
|
+
|
|
45
|
+
| Runner | Methods |
|
|
46
|
+
|--------|---------|
|
|
47
|
+
| `Chat` | `create` |
|
|
48
|
+
| `Models` | `list`, `retrieve` |
|
|
49
|
+
| `Embeddings` | `create` |
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
data/lex-xai.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/xai/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-xai'
|
|
7
|
+
spec.version = Legion::Extensions::Xai::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX xAI'
|
|
12
|
+
spec.description = 'Connects LegionIO to the xAI Grok API'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-xai'
|
|
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-xai'
|
|
19
|
+
spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-xai'
|
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-xai'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-xai/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/xai/helpers/client'
|
|
4
|
+
require 'legion/extensions/xai/runners/chat'
|
|
5
|
+
require 'legion/extensions/xai/runners/models'
|
|
6
|
+
require 'legion/extensions/xai/runners/embeddings'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Xai
|
|
11
|
+
class Client
|
|
12
|
+
include Legion::Extensions::Xai::Runners::Chat
|
|
13
|
+
include Legion::Extensions::Xai::Runners::Models
|
|
14
|
+
include Legion::Extensions::Xai::Runners::Embeddings
|
|
15
|
+
|
|
16
|
+
attr_reader :config
|
|
17
|
+
|
|
18
|
+
def initialize(api_key:, base_url: Helpers::Client::DEFAULT_BASE_URL, **opts)
|
|
19
|
+
@config = { api_key: api_key, base_url: base_url, **opts }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def client(**override_opts)
|
|
25
|
+
merged = config.merge(override_opts)
|
|
26
|
+
Legion::Extensions::Xai::Helpers::Client.client(**merged)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'multi_json'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Xai
|
|
9
|
+
module Helpers
|
|
10
|
+
module Client
|
|
11
|
+
DEFAULT_BASE_URL = 'https://api.x.ai'
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
def client(api_key:, base_url: DEFAULT_BASE_URL, **)
|
|
16
|
+
Faraday.new(url: base_url) do |conn|
|
|
17
|
+
conn.request :json
|
|
18
|
+
conn.response :json, content_type: /\bjson$/
|
|
19
|
+
conn.headers['Authorization'] = "Bearer #{api_key}"
|
|
20
|
+
conn.headers['Content-Type'] = 'application/json'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/xai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Xai
|
|
8
|
+
module Runners
|
|
9
|
+
module Chat
|
|
10
|
+
extend Legion::Extensions::Xai::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create(api_key:, messages:, model: 'grok-3', max_tokens: nil, temperature: nil, # rubocop:disable Metrics/ParameterLists
|
|
13
|
+
stream: false, **)
|
|
14
|
+
body = { model: model, messages: messages, stream: stream }
|
|
15
|
+
body[:max_tokens] = max_tokens if max_tokens
|
|
16
|
+
body[:temperature] = temperature if temperature
|
|
17
|
+
|
|
18
|
+
response = client(api_key: api_key, **).post('/v1/chat/completions', body)
|
|
19
|
+
{ result: response.body }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
23
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/xai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Xai
|
|
8
|
+
module Runners
|
|
9
|
+
module Embeddings
|
|
10
|
+
extend Legion::Extensions::Xai::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create(api_key:, input:, model: 'embedding-beta', **)
|
|
13
|
+
body = { model: model, input: input }
|
|
14
|
+
|
|
15
|
+
response = client(api_key: api_key, **).post('/v1/embeddings', body)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
20
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/xai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Xai
|
|
8
|
+
module Runners
|
|
9
|
+
module Models
|
|
10
|
+
extend Legion::Extensions::Xai::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list(api_key:, **)
|
|
13
|
+
response = client(api_key: api_key, **).get('/v1/models')
|
|
14
|
+
{ models: response.body }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def retrieve(api_key:, model:, **)
|
|
18
|
+
response = client(api_key: api_key, **).get("/v1/models/#{model}")
|
|
19
|
+
{ model: response.body }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
23
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/xai/version'
|
|
4
|
+
require 'legion/extensions/xai/helpers/client'
|
|
5
|
+
require 'legion/extensions/xai/runners/chat'
|
|
6
|
+
require 'legion/extensions/xai/runners/models'
|
|
7
|
+
require 'legion/extensions/xai/runners/embeddings'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Xai
|
|
12
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-xai
|
|
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 xAI Grok 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
|
+
- Gemfile
|
|
53
|
+
- README.md
|
|
54
|
+
- lex-xai.gemspec
|
|
55
|
+
- lib/legion/extensions/xai.rb
|
|
56
|
+
- lib/legion/extensions/xai/client.rb
|
|
57
|
+
- lib/legion/extensions/xai/helpers/client.rb
|
|
58
|
+
- lib/legion/extensions/xai/runners/chat.rb
|
|
59
|
+
- lib/legion/extensions/xai/runners/embeddings.rb
|
|
60
|
+
- lib/legion/extensions/xai/runners/models.rb
|
|
61
|
+
- lib/legion/extensions/xai/version.rb
|
|
62
|
+
homepage: https://github.com/LegionIO/lex-xai
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata:
|
|
66
|
+
homepage_uri: https://github.com/LegionIO/lex-xai
|
|
67
|
+
source_code_uri: https://github.com/LegionIO/lex-xai
|
|
68
|
+
documentation_uri: https://github.com/LegionIO/lex-xai
|
|
69
|
+
changelog_uri: https://github.com/LegionIO/lex-xai
|
|
70
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-xai/issues
|
|
71
|
+
rubygems_mfa_required: 'true'
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '3.4'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubygems_version: 3.6.9
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: LEX xAI
|
|
89
|
+
test_files: []
|