Skip to content

Commit ee62965

Browse files
authored
Merge pull request #1028 from code0-tech/#1013-query-available-models
query velorum models
2 parents 2e858ed + 66132b8 commit ee62965

20 files changed

Lines changed: 385 additions & 0 deletions

File tree

app/graphql/types/query_type.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QueryType < Types::BaseObject
4343
field :users, Types::UserType.connection_type, null: false, description: 'Find users'
4444

4545
field :global_runtimes, Types::RuntimeType.connection_type, null: false, description: 'Find runtimes'
46+
field :velorum, Types::VelorumType, null: true, description: 'Get Velorum information'
4647

4748
def application
4849
{}
@@ -86,6 +87,10 @@ def global_runtimes
8687
Runtime.where(namespace: nil)
8788
end
8889

90+
def velorum
91+
{}
92+
end
93+
8994
def current_authentication
9095
super.authentication
9196
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class VelorumModelType < Types::BaseObject
5+
description 'Represents a model available through Velorum'
6+
7+
field :identifier, String, null: false, description: 'Unique model identifier'
8+
field :name, String, null: false, description: 'Human-readable model name'
9+
field :token_cost, Float, null: false, description: 'Token cost for using this model'
10+
field :types, [Types::VelorumModelTypeEnum],
11+
null: false,
12+
description: 'Capabilities supported by this model',
13+
method: :type
14+
end
15+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class VelorumModelTypeEnum < Types::BaseEnum
5+
description 'Supported Velorum model capabilities'
6+
7+
value :UNKNOWN, 'Unknown model capability', value: :UNKNOWN
8+
value :EXPLAIN, 'Model can explain flows', value: :EXPLAIN
9+
value :GENERATE, 'Model can generate flows', value: :GENERATE
10+
end
11+
end

app/graphql/types/velorum_type.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class VelorumType < Types::BaseObject
5+
description 'Represents Velorum integration information'
6+
7+
authorize :read_velorum_config
8+
declarative_policy_subject { :global }
9+
10+
field :enabled, Boolean, null: false, description: 'Whether Velorum is enabled'
11+
field :models, [Types::VelorumModelType], null: false, description: 'Find models available through Velorum'
12+
13+
def enabled
14+
config[:enabled]
15+
end
16+
17+
def models
18+
::Velorum::ModelsService.new(config: config).execute
19+
end
20+
21+
private
22+
23+
def config
24+
Sagittarius::Configuration.config[:velorum]
25+
end
26+
end
27+
end

app/policies/global_policy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class GlobalPolicy < BasePolicy
1212
enable :read_flow_type
1313
enable :read_flow_type_setting
1414
enable :read_metadata
15+
enable :read_velorum_config
1516
end
1617

1718
rule { admin }.policy do
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Velorum
4+
class ModelsService
5+
def initialize(client: nil, config: Sagittarius::Configuration.config[:velorum])
6+
@client = client
7+
@config = config
8+
end
9+
10+
def execute
11+
return [] unless config[:enabled]
12+
13+
client.models.models
14+
end
15+
16+
private
17+
18+
attr_reader :config
19+
20+
def client
21+
@client ||= Sagittarius::Velorum::Client.new
22+
end
23+
end
24+
end

config/initializers/tucana.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
Rails.application.config.to_prepare do
44
Tucana.load_protocol(:sagittarius)
5+
Tucana.load_protocol(:velorum)
56
end

config/sagittarius.example.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ rails:
2626
key_derivation_salt: Z6zcLTgobXLYjXUslRsLMKxvXKq3j6DJ
2727
secret_key_base: MVMD6CtQwEWrQ28TdokQakbG2FG5abOn
2828

29+
velorum:
30+
enabled: false
31+
host: 'localhost:50052'
32+
jwt_secret:
33+
jwt_ttl_minutes: 8
34+
2935
application_setting_overrides: {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: VelorumModelType
3+
---
4+
5+
Supported Velorum model capabilities
6+
7+
| Value | Description |
8+
|-------|-------------|
9+
| `EXPLAIN` | Model can explain flows |
10+
| `GENERATE` | Model can generate flows |
11+
| `UNKNOWN` | Unknown model capability |

docs/graphql/object/query.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Root Query type
1414
| `globalRuntimes` | [`RuntimeConnection!`](../object/runtimeconnection.md) | Find runtimes |
1515
| `organizations` | [`OrganizationConnection!`](../object/organizationconnection.md) | Find organizations |
1616
| `users` | [`UserConnection!`](../object/userconnection.md) | Find users |
17+
| `velorum` | [`Velorum`](../object/velorum.md) | Get Velorum information |
1718

1819
## Fields with arguments
1920

0 commit comments

Comments
 (0)