lex-azure-ai 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 +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +58 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +10 -0
- data/README.md +57 -0
- data/lex-azure-ai.gemspec +31 -0
- data/lib/legion/extensions/azure_ai/client.rb +31 -0
- data/lib/legion/extensions/azure_ai/helpers/client.rb +25 -0
- data/lib/legion/extensions/azure_ai/runners/chat.rb +29 -0
- data/lib/legion/extensions/azure_ai/runners/embeddings.rb +25 -0
- data/lib/legion/extensions/azure_ai/runners/models.rb +24 -0
- data/lib/legion/extensions/azure_ai/version.rb +9 -0
- data/lib/legion/extensions/azure_ai.rb +16 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dff494ee2f2c36cb2abb0c9b17f23d74967cb5ad0ca54874c33ef092035faacd
|
|
4
|
+
data.tar.gz: 5303a63624b2efc42aec65e8344b819d102d9b34ed334b8b744cf705df5d7ca4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f39c37df43f4aea508d1e2dc6a02bd85af0a4804189f4826c3f02fb11b5e70e88183b9e13e6698a7aae5958a05ddb5f5733d4f98e4e8f664f24a4b252b6d7de1
|
|
7
|
+
data.tar.gz: fee59becbb15d70f72389dd813af47a82426ff35a9fc47141d4c69f476b6b5e8340105cd64c855d0b03990da472748872390c745f280e0de2384caaddff0475f
|
|
@@ -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,58 @@
|
|
|
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
|
+
Metrics/ParameterLists:
|
|
51
|
+
Max: 12
|
|
52
|
+
|
|
53
|
+
Naming/FileName:
|
|
54
|
+
Enabled: false
|
|
55
|
+
|
|
56
|
+
Naming/MethodParameterName:
|
|
57
|
+
AllowedNames:
|
|
58
|
+
- n
|
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
|
+
- Chat completions runner via Azure OpenAI deployment
|
|
8
|
+
- Embeddings runner via Azure OpenAI deployment
|
|
9
|
+
- Models listing runner
|
|
10
|
+
- Standalone Client class
|
|
11
|
+
- Faraday-based HTTP client with api-key header authentication
|
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# lex-azure-ai
|
|
2
|
+
|
|
3
|
+
Legion Extension that connects LegionIO to Azure AI Services (Azure OpenAI).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'lex-azure-ai'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Standalone Client
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'legion/extensions/azure_ai'
|
|
19
|
+
|
|
20
|
+
client = Legion::Extensions::AzureAi::Client.new(
|
|
21
|
+
api_key: 'your-azure-api-key',
|
|
22
|
+
endpoint: 'my-resource',
|
|
23
|
+
api_version: '2024-10-21'
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
result = client.create(
|
|
27
|
+
deployment: 'gpt-4o',
|
|
28
|
+
messages: [{ role: 'user', content: 'Hello!' }]
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Runners Directly
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
Legion::Extensions::AzureAi::Runners::Chat.create(
|
|
36
|
+
deployment: 'gpt-4o',
|
|
37
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
38
|
+
api_key: 'your-key',
|
|
39
|
+
endpoint: 'my-resource'
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
Legion::Extensions::AzureAi::Runners::Embeddings.create(
|
|
43
|
+
deployment: 'text-embedding-ada-002',
|
|
44
|
+
input: 'Hello world',
|
|
45
|
+
api_key: 'your-key',
|
|
46
|
+
endpoint: 'my-resource'
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
Legion::Extensions::AzureAi::Runners::Models.list(
|
|
50
|
+
api_key: 'your-key',
|
|
51
|
+
endpoint: 'my-resource'
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/azure_ai/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-azure-ai'
|
|
7
|
+
spec.version = Legion::Extensions::AzureAi::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX Azure AI'
|
|
12
|
+
spec.description = 'Connects LegionIO to Azure AI Services (Azure OpenAI)'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-azure-ai'
|
|
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-azure-ai'
|
|
19
|
+
spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-azure-ai'
|
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-azure-ai'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-azure-ai/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/azure_ai/helpers/client'
|
|
4
|
+
require 'legion/extensions/azure_ai/runners/chat'
|
|
5
|
+
require 'legion/extensions/azure_ai/runners/embeddings'
|
|
6
|
+
require 'legion/extensions/azure_ai/runners/models'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module AzureAi
|
|
11
|
+
class Client
|
|
12
|
+
include Legion::Extensions::AzureAi::Runners::Chat
|
|
13
|
+
include Legion::Extensions::AzureAi::Runners::Embeddings
|
|
14
|
+
include Legion::Extensions::AzureAi::Runners::Models
|
|
15
|
+
|
|
16
|
+
attr_reader :config
|
|
17
|
+
|
|
18
|
+
def initialize(api_key:, endpoint:, api_version: '2024-10-21', **opts)
|
|
19
|
+
@config = { api_key: api_key, endpoint: endpoint, api_version: api_version, **opts }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def client(**override_opts)
|
|
25
|
+
merged = config.merge(override_opts)
|
|
26
|
+
Legion::Extensions::AzureAi::Helpers::Client.client(**merged)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'multi_json'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module AzureAi
|
|
9
|
+
module Helpers
|
|
10
|
+
module Client
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def client(api_key:, endpoint:, _api_version: '2024-10-21', **)
|
|
14
|
+
Faraday.new(url: "https://#{endpoint}.openai.azure.com") do |conn|
|
|
15
|
+
conn.request :json
|
|
16
|
+
conn.response :json, content_type: /\bjson$/
|
|
17
|
+
conn.headers['api-key'] = api_key
|
|
18
|
+
conn.headers['Content-Type'] = 'application/json'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/azure_ai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module AzureAi
|
|
8
|
+
module Runners
|
|
9
|
+
module Chat
|
|
10
|
+
extend Legion::Extensions::AzureAi::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create(deployment:, messages:, api_key:, endpoint:, api_version: '2024-10-21',
|
|
13
|
+
max_tokens: nil, temperature: nil, **)
|
|
14
|
+
body = { messages: messages }
|
|
15
|
+
body[:max_tokens] = max_tokens if max_tokens
|
|
16
|
+
body[:temperature] = temperature if temperature
|
|
17
|
+
|
|
18
|
+
path = "/openai/deployments/#{deployment}/chat/completions?api-version=#{api_version}"
|
|
19
|
+
response = client(api_key: api_key, endpoint: endpoint, api_version: api_version).post(path, body)
|
|
20
|
+
{ result: response.body }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
24
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/azure_ai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module AzureAi
|
|
8
|
+
module Runners
|
|
9
|
+
module Embeddings
|
|
10
|
+
extend Legion::Extensions::AzureAi::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def create(deployment:, input:, api_key:, endpoint:, api_version: '2024-10-21', **)
|
|
13
|
+
body = { input: input }
|
|
14
|
+
path = "/openai/deployments/#{deployment}/embeddings?api-version=#{api_version}"
|
|
15
|
+
response = client(api_key: api_key, endpoint: endpoint, api_version: api_version).post(path, 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,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/azure_ai/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module AzureAi
|
|
8
|
+
module Runners
|
|
9
|
+
module Models
|
|
10
|
+
extend Legion::Extensions::AzureAi::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list(api_key:, endpoint:, api_version: '2024-10-21', **)
|
|
13
|
+
path = "/openai/models?api-version=#{api_version}"
|
|
14
|
+
response = client(api_key: api_key, endpoint: endpoint, api_version: api_version).get(path)
|
|
15
|
+
{ models: response.body }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
19
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/azure_ai/version'
|
|
4
|
+
require 'legion/extensions/azure_ai/helpers/client'
|
|
5
|
+
require 'legion/extensions/azure_ai/runners/chat'
|
|
6
|
+
require 'legion/extensions/azure_ai/runners/embeddings'
|
|
7
|
+
require 'legion/extensions/azure_ai/runners/models'
|
|
8
|
+
require 'legion/extensions/azure_ai/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module AzureAi
|
|
13
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-azure-ai
|
|
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 Azure AI Services (Azure OpenAI)
|
|
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-azure-ai.gemspec
|
|
55
|
+
- lib/legion/extensions/azure_ai.rb
|
|
56
|
+
- lib/legion/extensions/azure_ai/client.rb
|
|
57
|
+
- lib/legion/extensions/azure_ai/helpers/client.rb
|
|
58
|
+
- lib/legion/extensions/azure_ai/runners/chat.rb
|
|
59
|
+
- lib/legion/extensions/azure_ai/runners/embeddings.rb
|
|
60
|
+
- lib/legion/extensions/azure_ai/runners/models.rb
|
|
61
|
+
- lib/legion/extensions/azure_ai/version.rb
|
|
62
|
+
homepage: https://github.com/LegionIO/lex-azure-ai
|
|
63
|
+
licenses:
|
|
64
|
+
- MIT
|
|
65
|
+
metadata:
|
|
66
|
+
homepage_uri: https://github.com/LegionIO/lex-azure-ai
|
|
67
|
+
source_code_uri: https://github.com/LegionIO/lex-azure-ai
|
|
68
|
+
documentation_uri: https://github.com/LegionIO/lex-azure-ai
|
|
69
|
+
changelog_uri: https://github.com/LegionIO/lex-azure-ai
|
|
70
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-azure-ai/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 Azure AI
|
|
89
|
+
test_files: []
|