Module: LightGptProxy
- Extended by:
- Forwardable
- Defined in:
- lib/light_gpt_proxy.rb,
lib/light_gpt_proxy/guard.rb,
lib/light_gpt_proxy/config.rb,
lib/light_gpt_proxy/logger.rb,
lib/light_gpt_proxy/version.rb,
lib/light_gpt_proxy/endpoint.rb,
lib/light_gpt_proxy/provider.rb,
lib/light_gpt_proxy/templates.rb,
lib/light_gpt_proxy/proxy_server.rb,
lib/light_gpt_proxy/schema_validator.rb,
lib/light_gpt_proxy/templates/template.rb,
lib/light_gpt_proxy/schema_defaults_applier.rb,
lib/light_gpt_proxy/templates/ollama_template.rb,
lib/light_gpt_proxy/templates/copilot_template.rb,
lib/light_gpt_proxy/templates/open_ai_template.rb,
lib/light_gpt_proxy/helpers/hash_deep_stringify_helper.rb
Defined Under Namespace
Modules: Helpers, Templates
Classes: Config, Endpoint, Guard, Logger, Provider, ProxyServer, SchemaDefaultsApplier, SchemaValidator, Template
Constant Summary
collapse
- CONFIG_FILE =
'.light_gpt_proxy.yml'
- ENCRYPTED_CONFIG_FILE =
'.light_gpt_proxy.yml.enc'
- DEFAULT_PORT =
3030
- DEFAULT_CONFIG =
{ 'default_port' => DEFAULT_PORT, 'verbose' => true, 'default_provider' => nil }.freeze
- Error =
Class.new(StandardError)
- VERSION =
'0.1.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.passwd ⇒ Object
Returns the value of attribute passwd.
27
28
29
|
# File 'lib/light_gpt_proxy.rb', line 27
def passwd
@passwd
end
|
.verb ⇒ Object
Returns the value of attribute verb.
27
28
29
|
# File 'lib/light_gpt_proxy.rb', line 27
def verb
@verb
end
|
Class Method Details
.config ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/light_gpt_proxy.rb', line 41
def config
@config ||= Config.new(
if config?
if encrypted_config?
raise Error, 'Please provide a password to decrypt the config' unless passwd
guard(passwd).decode(config_path)
else
YAML.load_file(config_path)
end
else
DEFAULT_CONFIG
end
)
end
|
.config? ⇒ Boolean
29
|
# File 'lib/light_gpt_proxy.rb', line 29
def config? = File.exist?(config_path)
|
.encrypted_config? ⇒ Boolean
30
|
# File 'lib/light_gpt_proxy.rb', line 30
def encrypted_config? = config_path&.end_with?('.enc')
|
.guard(pass = passwd) ⇒ Object
57
|
# File 'lib/light_gpt_proxy.rb', line 57
def guard(pass = passwd) = Guard.new(pass)
|
.logger ⇒ Object
59
|
# File 'lib/light_gpt_proxy.rb', line 59
def logger = @logger ||= Logger.new($stdout, verbose: verb)
|
.provider(name) ⇒ Object
58
|
# File 'lib/light_gpt_proxy.rb', line 58
def provider(name) = config.provider(name)
|
.start(port: nil, password: passwd, verbose: true) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/light_gpt_proxy.rb', line 62
def start(port: nil, password: passwd, verbose: true)
@passwd = password
@verb = verbose
verify_password! if encrypted_config?
port ||= config.default_port
logger.info("Starting LightGPT Proxy server on port #{port} with Puma")
@server_thread = Thread.new do
Rack::Handler::Puma.run(server, Port: port)
end
@server_thread.join rescue => e logger.error("Failed to start server: #{e.message}")
end
|
.stop ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/light_gpt_proxy.rb', line 80
def stop
logger.info('Stopping LightGPT Proxy server')
if @server_thread
Thread.kill(@server_thread)
logger.info('Server stopped successfully')
else
logger.warn('Server is not running')
end
end
|
.verify_password! ⇒ Object
76
77
78
|
# File 'lib/light_gpt_proxy.rb', line 76
def verify_password!
config
end
|