Module: Ollama::BaseURL
- Included in:
- Ollama
- Defined in:
- lib/ollama/base_url.rb
Overview
A module that provides URL normalization for the Ollama base URL.
This module is extended into the Ollama namespace, making
Ollama.base_url the public entry point for resolving a
user-supplied host specification into a fully-qualified
URI suitable for HTTP(S) communication with an Ollama server.
Instance Method Summary collapse
-
#base_url(spec, fallback: true) ⇒ URI?
Normalizes a base URL specification into a URI object.
Instance Method Details
#base_url(spec, fallback: true) ⇒ URI?
Normalizes a base URL specification into a URI object.
Accepts either a URI instance or a String. If the String
does not contain an explicit http:// or https:// scheme,
one is prepended automatically.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ollama/base_url.rb', line 36 def base_url(spec, fallback: true) uri = nil begin uri = spec.is_a?(URI) ? spec : URI.parse(spec) rescue URI::InvalidURIError if fallback return base_url('http://%s' % spec, fallback: false) else return end end case when uri&.scheme =~ /\Ahttps?\z/ uri when fallback base_url('http://%s' % spec, fallback: false) end end |